Nvim の :help ページは、ソース を 生成 し、tree-sitter-vimdoc パーサーを使用しています。
vim.lsp を含むことを意味します。-- Create an event handler for the FileType autocommand
vim.api.nvim_create_autocmd('FileType', {
-- This handler will fire when the buffer's 'filetype' is "python"
pattern = 'python',
callback = function(args)
vim.lsp.start({
name = 'my-server-name',
cmd = {'name-of-language-server-executable', '--option', 'arg1', 'arg2'},
-- Set the "root directory" to the parent directory of the file in the
-- current buffer (`args.buf`) that contains either a "setup.py" or a
-- "pyproject.toml" file. Files that share a root directory will reuse
-- the connection to the same LSP server.
root_dir = vim.fs.root(args.buf, {'setup.py', 'pyproject.toml'}),
})
end,
})
:checkhealth lsp4. (オプション)LSP 機能を使用するためにキーマップと自動コマンドを設定します。 lsp-configCTRL-S は挿入モードで vim.lsp.buf.signature_help() にマップされます。vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
-- Unset 'formatexpr'
vim.bo[args.buf].formatexpr = nil
-- Unset 'omnifunc'
vim.bo[args.buf].omnifunc = nil
-- Unmap K
vim.keymap.del('n', 'K', { buffer = args.buf })
end,
})
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.supports_method('textDocument/implementation') then
-- Create a keymap for vim.lsp.buf.implementation
end
if client.supports_method('textDocument/completion') then
-- Enable auto-completion
vim.lsp.completion.enable(true, client.id, args.buf, {autotrigger = true})
end
if client.supports_method('textDocument/formatting') then
-- Format the current buffer on save
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = args.buf,
callback = function()
vim.lsp.buf.format({bufnr = args.buf, id = client.id})
end,
})
end
end,
})
:lua =vim.lsp.get_clients()[1].server_capabilitiesデフォルトで提供される機能の完全なリストは、lsp-buf で確認できます。:lua vim.lsp.stop_client(vim.lsp.get_clients())
:edit:verbose set omnifunc?async パラメーターがあるかどうかを確認し、値を false に設定します。例: コードのフォーマット" Auto-format *.rs (rust) files prior to saving them
" (async = false is the default for format)
autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false })
vim.lsp.buf_… 関数は、指定されたバッファにアタッチされているすべての LSP クライアントに対して操作を実行します。 lsp-buf:lua vim.print(vim.tbl_keys(vim.lsp.handlers))
'callHierarchy/incomingCalls'
'callHierarchy/outgoingCalls'
'textDocument/codeAction'
'textDocument/completion'
'textDocument/declaration'
'textDocument/definition'
'textDocument/diagnostic'
'textDocument/documentHighlight'
'textDocument/documentSymbol'
'textDocument/formatting'
'textDocument/hover'
'textDocument/implementation'
'textDocument/inlayHint'
'textDocument/prepareTypeHierarchy'
'textDocument/publishDiagnostics'
'textDocument/rangeFormatting'
'textDocument/rangesFormatting'
'textDocument/references'
'textDocument/rename'
'textDocument/semanticTokens/full'
'textDocument/semanticTokens/full/delta'
'textDocument/signatureHelp'
'textDocument/typeDefinition*'
'typeHierarchy/subtypes'
'typeHierarchy/supertypes'
'window/logMessage'
'window/showMessage'
'window/showDocument'
'window/showMessageRequest'
'workspace/applyEdit'
'workspace/configuration'
'workspace/executeCommand'
'workspace/inlayHint/refresh'
'workspace/symbol'
'workspace/workspaceFolders'
function(err, result, ctx)
{err} (table|nil) エラー情報辞書、またはリクエストが完了した場合は nil。{ctx} (table) ハンドラーに関連付けられた呼び出し状態のテーブル。次のキーがあります。{bufnr} (Buffer) バッファハンドル。{params} (table|nil) リクエストパラメーターのテーブル。{version} (number) リクエスト時のドキュメントバージョン。ハンドラーは、これを現在のドキュメントバージョンと比較して、応答が「古い」かどうかを確認できます。b:changedtick も参照してください。result, err の 2 つの値。err は RPC エラーのような形式です。{ code, message, data? }
vim.lsp.handlers は、lsp-method 名を lsp-handlers にデフォルトでマッピングするグローバルテーブルです。vim.lsp.handlers['textDocument/publishDiagnostics'] = my_custom_diagnostics_handler
vim.lsp.start {
..., -- Other configuration omitted.
handlers = {
['textDocument/publishDiagnostics'] = my_custom_server_definition
},
}
vim.lsp.buf_request_all(
0,
'textDocument/publishDiagnostics',
my_request_params,
my_handler
)
vim.lsp.protocol は、LSP 仕様によって規定された定数と、プロトコル関連オブジェクトを作成するためのヘルパー関数を定義します。 https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.mdvim.lsp.protocol.ErrorCodes では、番号または名前による逆引きが可能です。vim.lsp.protocol.TextDocumentSyncKind.Full == 1
vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
typeと、「readonly」や「deprecated」などの0個以上のmodifierがあります。標準の型と修飾子は、こちらで説明されています:https://microsoft.github.io/language-server-protocol/specification/#textDocument_semanticTokens LSPサーバーは、仕様外の型と修飾子を使用する場合もあります。@lsp.type.<type>.<ft>@lsp.mod.<mod>.<ft>@lsp.typemod.<type>.<mod>.<ft> 特定のトークンのハイライトを表示するには、:Inspectを使用します。セマンティックハイライトの外観を変更するには、:hi または nvim_set_hl() を使用します。hi @lsp.type.function guifg=Yellow " function names are yellow
hi @lsp.type.variable.lua guifg=Green " variables in lua are green
hi @lsp.mod.deprecated gui=strikethrough " deprecated is crossed out
hi @lsp.typemod.function.async guifg=Blue " async functions are blue
.semantic_tokens は、@lsp.type.* ハイライトの優先度です。@lsp.mod.* と @lsp.typemod.* ハイライトは、それぞれ1つと2つ高い優先度を持っています。-- Hide semantic highlights for functions
vim.api.nvim_set_hl(0, '@lsp.type.function', {})
-- Hide all semantic highlights
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
vim.api.nvim_set_hl(0, group, {})
end
vim.api.nvim_create_autocmd('LspDetach', {
callback = function(args)
-- Get the detaching client
local client = vim.lsp.get_client_by_id(args.data.client_id)
-- Remove the autocommand to format the buffer on save, if it exists
if client.supports_method('textDocument/formatting') then
vim.api.nvim_clear_autocmds({
event = 'BufWritePre',
buffer = args.buf,
})
end
end,
})
vim.api.nvim_create_autocmd('LspNotify', {
callback = function(args)
local bufnr = args.buf
local client_id = args.data.client_id
local method = args.data.method
local params = args.data.params
-- do something with the notification
if method == 'textDocument/...' then
update_buffer(bufnr)
end
end,
})
progressリングバッファーからポーリングするか、vim.lsp.status()を使用して集約メッセージを取得できます。patternはkind(begin、report、またはendのいずれか)に設定されます。client_idとparamsプロパティを持つdataテーブルが含まれます。paramsには、サーバーによって送信されたリクエストパラメーターが含まれます(lsp.ProgressParamsを参照)。autocmd LspProgress * redrawstatus
pending、complete、またはcancelのいずれかであり、コールバック関数に渡される "data" テーブルの{type}として送信されます。{type} == pending)と、LSPサーバーが応答したとき({type} == complete)にトリガーされます。 client.cancel_request(request_id)を使用してキャンセルが要求された場合、このイベントは{type} == cancelでトリガーされます。{requests} の詳細については、vim.lsp.Client を参照してください。リクエストタイプがcompleteの場合、イベントのコールバックを呼び出した直後に、リクエストはクライアントの保留中のリクエストテーブルから削除されます。例vim.api.nvim_create_autocmd('LspRequest', {
callback = function(args)
local bufnr = args.buf
local client_id = args.data.client_id
local request_id = args.data.request_id
local request = args.data.request
if request.type == 'pending' then
-- do something with pending requests
track_pending(client_id, bufnr, request_id, request)
elseif request.type == 'cancel' then
-- do something with pending cancel requests
track_canceling(client_id, bufnr, request_id, request)
elseif request.type == 'complete' then
-- do something with finished requests. this pending
-- request entry is about to be removed since it is complete
track_finish(client_id, bufnr, request_id, request)
end
end,
})
vim.api.nvim_create_autocmd('LspTokenUpdate', {
callback = function(args)
local token = args.data.token
if token.type == 'variable' and not token.modifiers.readonly then
vim.lsp.semantic_tokens.highlight_token(
token, args.buf, args.data.client_id, 'MyMutableVariableHighlight'
)
end
end,
})
{bufnr}, {client_id}) vim.lsp.buf_attach_client()textDocument/did… 通知を実装します。{bufnr} (integer) バッファーハンドル、または現在の場合は 0{client_id} (integer) クライアントIDboolean) 成功。クライアントが正常にアタッチされた場合は true、それ以外の場合は false{bufnr}, {client_id}) vim.lsp.buf_detach_client(){bufnr} (integer) バッファーハンドル、または現在の場合は 0{client_id} (integer) クライアントID{bufnr} (integer) バッファーハンドル、または現在の場合は 0{client_id} (integer) クライアントID{bufnr} (integer?) バッファー番号{method} (string) リクエストメソッドの名前{params} (any) サーバーに送信する引数boolean) 成功。クライアントが true を返した場合は true、それ以外の場合は false{bufnr}, {method}, {params}, {handler}) バッファーにアタッチされているすべてのアクティブなクライアントに非同期リクエストを送信し、結合された結果でhandlerコールバックを実行します。{bufnr} (integer) バッファーハンドル、または現在の場合は 0。{method} (string) LSPメソッド名{params} (table|(fun(client: vim.lsp.Client, bufnr: integer): table?)?) サーバーに送信するパラメーター。パラメーターがクライアントに固有の場合にパラメーターテーブルを返す関数としても渡すことができます。{handler} (function) すべてのリクエストが完了した後に呼び出されるハンドラー。サーバーの結果は、client_id:result マップとして渡されます。function) キャンセル。すべてのリクエストをキャンセルする関数。{bufnr}, {method}, {params}, {timeout_ms}) すべてのサーバーにリクエストを送信し、すべての応答を待ちます。{timeout_ms} を待ちます。{bufnr} (integer) バッファーハンドル、または現在の場合は 0。{method} (string) LSPメソッド名{params} (table?) サーバーに送信するパラメーター{timeout_ms} (integer?, デフォルト: 1000) 結果を待つ最大時間(ミリ秒単位)。table<integer, {error: lsp.ResponseError?, result: any}>?) クライアントIDとリクエスト結果のマップ。 (string?) err タイムアウト、キャンセル、またはエラーの場合、err は失敗理由を説明する文字列で、result は nil になります。{client_id} (integer)boolean) stopped クライアントが停止している場合は true、そうでない場合は false。workspace/executeCommand を使用してLSPサーバー経由で実行されます。Command です: コマンドのタイトル: String コマンド: String 引数?: any[]ctx です。setlocal formatexpr=v:lua.vim.lsp.formatexpr() または(より一般的には)on_attach で vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})' を使用して設定できます。{opts} (table?) 次のフィールドを持つテーブル{timeout_ms} (integer, デフォルト: 500ms) フォーマットリクエストのタイムアウト期間。{client_id}) client_id にアタッチされたバッファのリストを返します。{client_id} (integer) クライアントIDinteger[]) buffers バッファIDのリスト{client_id}) vim.lsp.get_client_by_id(){client_id} (integer) クライアントIDvim.lsp.Client?) クライアントRPCオブジェクト{filter} (table?) 返されるクライアントをフィルタリングするために使用されるキーと値のペア。{id} (integer) 指定されたIDを持つクライアントのみを返します{bufnr} (integer) このバッファにアタッチされたクライアントのみを返します{name} (string) 指定された名前を持つクライアントのみを返します{method} (string) 指定されたメソッドをサポートするクライアントのみを返しますstring) ログファイルへのパス{findstart} (integer) 0または1、動作を決定します{base} (integer) findstart=0、照合するテキストinteger|table) {findstart} によって決定されますlsp.log_levels を使用します。{level} (integer|string) 大文字と小文字を区別しないレベル名または番号{config}, {opts}) vim.lsp.start()name と root_dir に一致するものが既に見つかっている場合は、既に実行中のクライアントを再利用します。現在のバッファをクライアントにアタッチします。vim.lsp.start({
name = 'my-server-name',
cmd = {'name-of-language-server-executable'},
root_dir = vim.fs.root(0, {'pyproject.toml', 'setup.py'}),
})
name LSPクライアントの任意の名前。言語サーバーごとに一意である必要があります。cmd コマンド文字列[] または関数、vim.lsp.start_client() で説明されています。root_dir プロジェクトルートへのパス。デフォルトでは、これは既存のクライアントを再利用するかどうかを決定するために使用されます。上記の例では、vim.fs.root() を使用して、現在のディレクトリから上に向かってファイルシステムを走査し、pyproject.toml または setup.py ファイルが見つかるまでルートを検出します。workspace_folders 言語サーバーで使用されるプロジェクトルートフォルダを指定する { uri:string, name: string } テーブルのリスト。nil の場合、便宜上、プロパティは root_dir から派生します。ftplugin/<filetype_name>.lua に配置します ( ftplugin-name を参照)。{opts} (table?) オプションのキーワード引数{reuse_client} (fun(client: vim.lsp.Client, config: vim.lsp.ClientConfig): boolean) クライアントを再利用するかどうかを決定するために使用される述語。実行中のすべてのクライアントで使用されます。デフォルトの実装では、名前と root_dir が一致する場合にクライアントを再利用します。{bufnr} (integer) クライアントの起動または再利用時にアタッチするバッファハンドル (現在のバッファの場合は0)。{silent} (boolean) LSPサーバーの起動に失敗した場合のエラー報告を抑制します (デフォルトは false)。integer?) client_idinteger?) client_id vim.lsp.get_client_by_id() 注: クライアントは完全に初期化されていない可能性があります。クライアントが初期化されたらアクションを実行するには、on_init を使用してください。(string?) エラーメッセージ(ある場合)string)stop() 関数を使用することもできます。すべてのクライアントを停止するにはvim.lsp.stop_client(vim.lsp.get_clients())
{force} (boolean?) 強制的にシャットダウンtable[]) tags 一致するタグのリスト{id} (integer) クライアントに割り当てられたID。{name} (string) 作成時に名前が指定されている場合は、それが使用されます。それ以外の場合は、クライアントIDのみです。これはログとメッセージに使用されます。{offset_encoding} (string) サーバーとの通信に使用されるエンコーディング。テキストがサーバーに送信される前に、config の on_init メソッドでこれを変更できます。{requests} (table<integer,{ type: string, bufnr: integer, method: string}>) サーバーに送信中の現在の保留中のリクエスト。エントリは、キーがリクエストIDであり、値が type、bufnr、および method キーと値のペアを持つテーブルであるキーと値のペアです。type は、アクティブなリクエストの場合は "pending"、キャンセルリクエストの場合は "cancel" になります。サーバーから応答を受信すると、LspRequest autocmd を実行中に一時的に "complete" になります。{config} (vim.lsp.ClientConfig) ユーザーが vim.lsp.start_client() に渡したテーブルのコピー。vim.lsp.ClientConfig を参照してください。{server_capabilities} (lsp.ServerCapabilities?) サーバーの機能について説明する、initialize で送信されたサーバーからの応答。{progress} (vim.lsp.Client.Progress) サーバーから送信された進捗メッセージを含むリングバッファ (vim.ringbuf()) 。vim.lsp.Client.Progress を参照してください。{initialized} (true?){workspace_folders} (lsp.WorkspaceFolder[]?) サーバーの起動時にクライアントで構成されたワークスペースフォルダ。このプロパティは、クライアントがワークスペースフォルダをサポートしている場合にのみ使用できます。クライアントがワークスペースフォルダをサポートしているが構成されていない場合は、null になる可能性があります。{root_dir} (string?){attached_buffers} (table<integer,true>){commands} (table<string,fun(command: lsp.Command, ctx: table)>) LSPアクション(コードアクション、コードレンズなど)がコマンドをトリガーした場合に呼び出される関数へのコマンド名のテーブル。クライアントコマンドは、グローバルコマンドレジストリよりも優先されます。{settings} (table) 言語サーバー固有の設定を含むマップ。これらは、workspace/configuration を介してリクエストされた場合、言語サーバーに返されます。キーは大文字と小文字を区別します。{flags} (table) クライアントのフラグを含むテーブル。現在の(実験的な)フラグは次のとおりです。{allow_incremental_sync} (boolean, デフォルト: true) バッファ編集にインクリメンタル同期を使用することを許可します{debounce_text_changes} (integer, デフォルト: 150) didChange 通知をサーバーへ送信する際の遅延時間(ミリ秒単位)。nil の場合は遅延は発生しません。{exit_timeout} (integer|false, デフォルト: false) "shutdown" リクエストを送信後、サーバーがクリーンに終了するのを待つ時間(ミリ秒単位)。この時間が経過すると kill -15 を送信します。false が設定された場合、nvim はサーバーに "shutdown" リクエストを送信後、直ちに終了します。{get_language_id} (fun(bufnr: integer, filetype: string): string){capabilities} (lsp.ClientCapabilities) クライアント(エディターまたはツール)が提供する capabilities。{dynamic_capabilities} (lsp.DynamicCapabilities){request} (fun(method: string, params: table?, handler: lsp.Handler?, bufnr: integer?): boolean, integer?) サーバーにリクエストを送信します。これは、{client.rpc.request} を薄くラップしたもので、追加のチェックが含まれています。{handler} が指定されておらず、対応するグローバルハンドラーもない場合、エラーが発生します。返り値: {status}, {client_id}。{status} は、通知が成功したかどうかを示す boolean 値です。false の場合は常に false になります (クライアントがシャットダウンしたことを意味します)。{status} が true の場合、関数は 2 つ目の結果として {request_id} を返します。この request_id を client.cancel_request(request_id) で使用してリクエストをキャンセルできます。{request_sync} (fun(method: string, params: table?, timeout_ms: integer?, bufnr: integer): {err: lsp.ResponseError?, result:any}?, string?) err # dict{notify} (fun(method: string, params: table?): boolean) LSP サーバーに通知を送信します。返り値: 通知が成功したかどうかを示す boolean 値。false の場合は常に false になります (クライアントがシャットダウンしたことを意味します)。{cancel_request} (fun(id: integer): boolean) 指定されたリクエスト ID のリクエストをキャンセルします。返り値: notify() と同じ。{stop} (fun(force?: boolean)) クライアントを停止します。オプションで強制停止できます。デフォルトでは、サーバーに強制停止せずにシャットダウンを要求します。以前にシャットダウンが要求されたクライアントの停止を要求すると、自動的にエスカレートして強制シャットダウンします。{on_attach} (fun(bufnr: integer)) クライアントの設定で定義されている場合、クライアントの on_attach 関数を実行します。バッファローカルな設定に役立ちます。{supports_method} (fun(method: string, opts?: {bufnr: integer?}): boolean) クライアントが指定されたメソッドをサポートしているかどうかを確認します。仕様外の未知のメソッドに対しては常に true を返します。{opts} はオプションの {bufnr?: integer} テーブルです。一部の言語サーバーの機能は、ファイル固有である場合があります。{is_stopped} (fun(): boolean) クライアントが停止しているかどうかを確認します。返り値: クライアントが完全に停止している場合は true。{exec_cmd} (fun(self: vim.lsp.Client, command: lsp.Command, context: {bufnr?: integer}?, handler: lsp.Handler?)) LSP コマンドを実行します。クライアントコマンド関数(利用可能な場合)経由、または workspace/executeCommand(サーバーでサポートされている場合)経由。{pending} (table<lsp.ProgressToken,lsp.LSPAny>){cmd} (string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient) 言語サーバーを起動するコマンド文字列の配列 ( jobstart() と同様に扱われます。絶対パスであるか、$PATH 上にある必要があります。 "~" のようなシェル構文は展開されません)、または RPC クライアントを作成する関数。関数は dispatchers テーブルを受け取り、メンバー関数 request, notify, is_closing, terminate を持つテーブルを返します。 vim.lsp.rpc.request(), vim.lsp.rpc.notify() を参照してください。TCP の場合、組み込みの RPC クライアントファクトリーがあります: vim.lsp.rpc.connect(){cmd_cwd} (string, デフォルト: cwd) cmd プロセスを起動するディレクトリ。root_dir とは関係ありません。{cmd_env} (table) スポーン時に LSP に渡す環境フラグ。テーブルを使用して指定する必要があります。文字列以外の値は文字列に変換されます。例:{ PORT = 8080; HOST = "0.0.0.0"; }
{detached} (boolean, デフォルト: true) Nvim とは別のプロセスグループで実行するようにサーバープロセスをデーモン化します。Nvim は終了時にプロセスをシャットダウンしますが、Nvim が正常に終了しない場合、孤立したサーバープロセスが残る可能性があります。{workspace_folders} (lsp.WorkspaceFolder[]) 言語サーバーに渡されるワークスペースフォルダーのリスト。下位互換性のため、rootUri および rootPath は、このリストの最初のワークスペースフォルダーから派生します。LSP 仕様の workspaceFolders を参照してください。{capabilities} (lsp.ClientCapabilities) vim.lsp.protocol.make_client_capabilities() で定義されたデフォルトの capabilities をオーバーライドするマップ。初期化時に言語サーバーに渡されます。ヒント: make_client_capabilities() を使用し、その結果を変更します。{commands} (table<string,fun(command: lsp.Command, ctx: table)>) クライアント側のコマンド文字列をユーザー定義関数にマップするテーブル。start_client に渡されるコマンドは、グローバルコマンドレジストリよりも優先されます。各キーは一意のコマンド名である必要があり、値は、LSP アクション (コードアクション、コードレンズなど) がコマンドをトリガーした場合に呼び出される関数です。{init_options} (table) 初期化リクエストで initializationOptions として渡す値。LSP 仕様の initialize を参照してください。{name} (string, デフォルト: client-id) ログメッセージでの名前。{get_language_id} (fun(bufnr: integer, filetype: string): string) 文字列としての言語 ID。デフォルトはファイルタイプです。{offset_encoding} ('utf-8'|'utf-16'|'utf-32') LSP サーバーが予期するエンコーディング。クライアントはこれが正しいかどうかを検証しません。{on_error} (fun(code: integer, err: string)) クライアント操作がエラーをスローしたときに呼び出されるコールバック。code はエラーを説明する数値です。エラーの種類に応じて、他の引数が渡される場合があります。可能なエラーについては、vim.lsp.rpc.client_errors を参照してください。人間が理解しやすい名前を取得するには、vim.lsp.rpc.client_errors[code] を使用してください。{before_init} (fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)) LSP の "initialize" フェーズの前に呼び出されるコールバック。ここで、params にはサーバーに送信されるパラメーターが含まれ、config は vim.lsp.start_client() に渡された構成です。これをを使用して、パラメーターを送信前に変更できます。{on_init} (elem_or_list<fun(client: vim.lsp.Client, initialize_result: lsp.InitializeResult)>) LSP の "initialize" の後に呼び出されるコールバック。result は capabilities およびサーバーが送信する可能性のあるその他のもののテーブルです。たとえば、clangd は、capabilities.offsetEncoding が送信された場合、initialize_result.offsetEncoding を送信します。通知が送信される前に、ここで client.offset_encoding のみを変更できます。{on_exit} (elem_or_list<fun(code: integer, signal: integer, client_id: integer)>) クライアントの終了時に呼び出されるコールバック。{on_attach} (elem_or_list<fun(client: vim.lsp.Client, bufnr: integer)>) クライアントがバッファにアタッチされたときに呼び出されるコールバック。{trace} ('off'|'messages'|'verbose', デフォルト: "off") 初期化リクエストで言語サーバーに直接渡されます。無効/空の値は{flags} (table) クライアントのフラグを含むテーブル。現在の(実験的な)フラグは次のとおりです。{allow_incremental_sync} (boolean, デフォルト: true) バッファ編集にインクリメンタル同期を使用することを許可します{debounce_text_changes} (integer, デフォルト: 150) didChange 通知をサーバーへ送信する際の遅延時間(ミリ秒単位)。nil の場合は遅延は発生しません。{exit_timeout} (integer|false, デフォルト: false) "shutdown" リクエストを送信後、サーバーがクリーンに終了するのを待つ時間(ミリ秒単位)。この時間が経過すると kill -15 を送信します。false が設定された場合、nvim はサーバーに "shutdown" リクエストを送信後、直ちに終了します。{root_dir} (string) LSP サーバーが初期化時に workspaceFolders、rootUri、および rootPath のベースとするディレクトリ。{command}, {context}, {handler}) Client:exec_cmd(){command} (lsp.Command){context} ({bufnr?: integer}?){handler} (lsp.Handler?) サーバーコマンドの場合のみ呼び出されます{on_list} (fun(t: vim.lsp.LocationOpts.OnList)) デフォルトのハンドラーを置き換えるリストハンドラー。空でない結果に対して呼び出されます。このテーブルは setqflist() または setloclist() と共に使用できます。例:local function on_list(options)
vim.fn.setqflist({}, ' ', options)
vim.cmd.cfirst()
end
vim.lsp.buf.definition({ on_list = on_list })
vim.lsp.buf.references(nil, { on_list = on_list })
vim.lsp.buf.definition({ loclist = true })
vim.lsp.buf.references(nil, { loclist = true })
{loclist} (boolean){reuse_win} (boolean) バッファがすでに開いている場合は、既存のウィンドウにジャンプします。{title} (string) リストのタイトル。{silent} (boolean){silent} (boolean){workspace_folder}) 指定されたパスにあるフォルダをワークスペースフォルダに追加します。{path} が指定されていない場合は、input() を使用してパスをユーザーに求めるプロンプトが表示されます。{workspace_folder} (string?){opts} (table?) 次のフィールドを持つテーブル{context} (lsp.CodeActionContext) LSP 仕様の CodeActionContext に対応します{diagnostics} (table) LSP Diagnostic[]。指定されていない場合は、現在の位置から推測されます。{only} (table) コードアクションをフィルター処理するために使用される LSP CodeActionKind のリスト。ほとんどの言語サーバーは、refactor や quickfix などの値をサポートしています。{triggerKind} (integer) コードアクションが要求された理由。{filter} (fun(x: lsp.CodeAction|lsp.Command):boolean) CodeAction を受け取り boolean を返す述語。{apply} (boolean) true に設定され、(フィルタリング後) 残りのアクションが 1 つしかない場合、ユーザーに問い合わせることなくアクションが適用されます。{range} ({start: integer[], end: integer[]}) コードアクションをリクエストする範囲。ビジュアルモードの場合、これはアクティブな選択範囲がデフォルトになります。テーブルには、マークのようなインデックス付けを使用する {row,col} タプルを持つ start キーと end キーが含まれている必要があります。api-indexing を参照してくださいCursorHold などのイベントによってトリガーできます。例えば、以下のようにします。autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
{opts} (table?) 次のフィールドを持つテーブル{formatting_options} (table) FormattingOptionsを指定するために使用できます。指定されていないオプションのいくつかは、現在のNvimオプションから自動的に導出されます。https://microsoft.github.io/language-server-protocol/specification/#formattingOptions を参照してください。{timeout_ms} (integer, デフォルト: 1000) フォーマットリクエストをブロックする時間(ミリ秒単位)。async=trueの場合は効果がありません。{bufnr} (integer, デフォルト: 現在のバッファ) 指定されたバッファにアタッチされたクライアントにフォーマットを制限します。{filter} (fun(client: vim.lsp.Client): boolean?) クライアントをフィルタリングするために使用される述語。クライアントを引数として受け取り、ブール値を返す必要があります。述語に一致するクライアントが含まれます。例:-- Never request typescript-language-server for formatting
vim.lsp.buf.format {
filter = function(client) return client.name ~= "tsserver" end
}
{async} (boolean, デフォルト: false) trueの場合、メソッドはブロックしません。非同期でフォーマット中にバッファを編集すると、予期しない変更が発生する可能性があります。{id} (integer) このフィールドに一致するID (client.id)を持つクライアントにフォーマットを制限します。{name} (string) このフィールドに一致する名前 (client.name)を持つクライアントにフォーマットを制限します。{range} ({start:[integer,integer],end:[integer, integer]}|{start:[integer,integer],end:[integer,integer]}[], デフォルト: ビジュアルモードでの現在の選択範囲、他のモードでは nil、バッファ全体をフォーマット) フォーマットする範囲。テーブルには、(1,0)インデックスを使用した {row,col} タプルを持つ start と end キーが含まれている必要があります。また、上記のように start キーと end キーを含むテーブルのリストであることもできます。その場合は textDocument/rangesFormatting のサポートが必要です。{config}) vim.lsp.buf.hover(){workspace_folder}) パスにあるフォルダをワークスペースフォルダから削除します。 {path} が指定されていない場合、ユーザーは input() を使用してパスの入力を求められます。{workspace_folder} (string?){opts} (table?) 追加のオプション{filter} (fun(client: vim.lsp.Client): boolean?) クライアントをフィルタリングするために使用される述語。クライアントを引数として受け取り、ブール値を返す必要があります。述語に一致するクライアントが含まれます。{name} (string) 名前変更に使用するクライアントを、client.nameがこのフィールドに一致するものに制限します。{bufnr} (integer) (デフォルト: 現在のバッファ){kind}) vim.lsp.buf.typehierarchy(){kind} ("subtypes"|"supertypes"){query}, {opts}) vim.lsp.buf.workspace_symbol(){query} に対してフィルタリングされます。引数が呼び出しから省略された場合、ユーザーはコマンドラインで文字列を入力するように求められます。空の文字列は、フィルタリングが行われないことを意味します。{diagnostics} (vim.Diagnostic[])lsp.Diagnostic[]){client_id}, {is_pull}) LSPクライアントに関連付けられた診断の名前空間 vim.diagnostic を取得します。{client_id} (integer) LSPクライアントのID{is_pull} (boolean?) 名前空間がプルクライアント用かプッシュクライアント用か。デフォルトはプッシュです{_}, {result}, {ctx}) メソッド "textDocument/diagnostic" のための lsp-handler。{result} (lsp.DocumentDiagnosticReport){ctx} (lsp.HandlerContext){_}, {result}, {ctx}) メソッド "textDocument/publishDiagnostics" のための lsp-handler。{result} (lsp.PublishDiagnosticsParams){ctx} (lsp.HandlerContext){client_id} (integer?) client_idでフィルタリングします。nilの場合はすべてのクライアント{bufnr} (integer?) バッファでフィルタリングします。nilの場合はすべてのバッファ、0の場合は現在のバッファ{lenses} (lsp.CodeLens[]?) 表示するレンズ{bufnr} (integer){client_id} (integer){bufnr} (integer) バッファ番号。現在のバッファには0を使用できます。lsp.CodeLens[]){err}, {result}, {ctx}) vim.lsp.codelens.on_codelens()textDocument/codeLens のための lsp-handler。{err} (lsp.ResponseError?){result} (lsp.CodeLens[]){ctx} (lsp.HandlerContext)autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh({ bufnr = 0 })
{opts} (table?) オプションフィールド{bufnr} (integer?) バッファでフィルタリングします。nilの場合はすべてのバッファ、0の場合は現在のバッファ{lenses} (lsp.CodeLens[]?) 保存するレンズ{bufnr} (integer){client_id} (integer){autotrigger} (boolean) デフォルト: false。 trueの場合、サーバーのtriggerCharactersに基づいて補完が自動的にトリガーされます。{enable}, {client_id}, {bufnr}, {opts}) 指定されたバッファ内の指定された言語クライアントからの補完を有効または無効にします。{enable} (boolean) 有効にする場合はtrue、無効にする場合はfalse{client_id} (integer) クライアントID{bufnr} (integer) バッファハンドル。現在のバッファの場合は0is_enabled()の逆を渡しますvim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
{enable} (boolean?) 有効にする場合はtrue/nil、無効にする場合はfalse{bufnr} (integer?) バッファ番号。現在のバッファの場合は0、またはすべての場合はnil。local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer
local client = vim.lsp.get_client_by_id(hint.client_id)
local resp = client.request_sync('inlayHint/resolve', hint.inlay_hint, 100, 0)
local resolved_hint = assert(resp and resp.result, resp.err)
vim.lsp.util.apply_text_edits(resolved_hint.textEdits, 0, client.encoding)
location = resolved_hint.label[1].location
client.request('textDocument/hover', {
textDocument = { uri = location.uri },
position = location.range.start,
})
table[]) 次のフィールドを持つオブジェクトのリスト{bufnr} (integer){client_id} (integer){inlay_hint} (lsp.InlayHint){bufnr} (integer?) バッファ番号。現在のバッファの場合は0、またはすべての場合はnil。boolean){bufnr} (integer?) バッファでフィルタリングします。nilの場合はすべてのバッファ、0の場合は現在のバッファ。{bufnr}, {row}, {col}) 指定された位置にあるセマンティックトークンを返します。引数なしで呼び出された場合、カーソルの下にあるトークンを返します。{bufnr} (integer?) バッファ番号(現在のバッファの場合は0、デフォルト){row} (integer?) 行の位置 (デフォルトはカーソル位置){col} (integer?) 列の位置 (デフォルトはカーソル位置)table?) 位置にあるトークンのリスト。各トークンには次のフィールドがあります{token}, {bufnr}, {client_id}, {hl_group}, {opts}) セマンティックトークンを強調表示します。{bufnr} (integer) 強調表示するバッファ。現在のバッファの場合は0{hl_group} (string) 強調表示グループ名{opts} (table?) オプションパラメータ{priority} (integer, デフォルト: vim.hl.priorities.semantic_tokens + 3) 適用される拡張マークの優先度。{bufnr}, {client_id}, {opts}) vim.lsp.semantic_tokens.start()on_attachコールバックで、クライアントの{server_capabilities}からsemanticTokensProviderテーブルを削除できます。client.server_capabilities.semanticTokensProvider = nil
{bufnr} (integer) バッファ番号。現在のバッファの場合は0{opts} (table?) オプションのキーワード引数{bufnr}, {client_id}) vim.lsp.semantic_tokens.stop()start()の一部として設定されるLspDetach自動コマンドによって自動的に呼び出されるため、LSPクライアントをバッファから完全に切り離さずにセマンティックトークンエンジンを手動で解除する場合にのみ、この関数が必要になります。{height} (integer) フローティングウィンドウの高さ{width} (integer) フローティングウィンドウの幅{wrap} (boolean, デフォルト: true) 長い行を折り返す{wrap_at} (integer) 折り返しが有効になっている場合に高さを計算するために折り返す文字{max_width} (integer) フローティングウィンドウの最大幅{max_height} (integer) フローティングウィンドウの最大高さ{focus_id} (string) このIDでポップアップが開かれた場合は、フォーカスを当てます{close_events} (table) フローティングウィンドウを閉じるイベントのリスト{focusable} (boolean, デフォルト: true) フローティングウィンドウをフォーカス可能にします。{focus} (boolean, デフォルト: true) trueの場合、および{focusable}もtrueの場合、同じ{focus_id}で既存のフローティングウィンドウにフォーカスします{offset_x} (integer) colに追加するオフセット{offset_y} (integer) rowに追加するオフセット{border} (string|(string|[string,string])[]) borderをオーバーライドします{zindex} (integer) zindexをオーバーライドします。デフォルトは50です{title} (string){title_pos} ('left'|'center'|'right'){relative} ('mouse'|'cursor') (デフォルト: 'cursor'){anchor_bias} ('auto'|'above'|'below', デフォルト: 'auto') - "auto": カーソルのどちら側に多くの行があるかに基づいてウィンドウを配置します{text_document_edit}, {index}, {offset_encoding}) 1つのドキュメントへの変更のリストであるTextDocumentEditを適用します。{text_document_edit} (lsp.TextDocumentEdit){index} (integer?) 編集のオプションのインデックス。編集のリストからの場合は (リストからのものではない場合はnil){offset_encoding} ('utf-8'|'utf-16'|'utf-32'?){text_edits}, {bufnr}, {offset_encoding}) テキスト編集のリストをバッファに適用します。{text_edits} (lsp.TextEdit[]){bufnr} (integer) バッファID{offset_encoding} ('utf-8'|'utf-16'|'utf-32'){workspace_edit}, {offset_encoding}) WorkspaceEditを適用します。{workspace_edit} (lsp.WorkspaceEdit){offset_encoding} ('utf-8'|'utf-16'|'utf-32') (必須){bufnr} (integer?) バッファID{bufnr}, {references}, {offset_encoding}) 特定のバッファのドキュメント強調表示のリストを表示します。{bufnr} (integer) バッファID{references} (lsp.DocumentHighlight[]) 強調表示するオブジェクト{offset_encoding} ('utf-8'|'utf-16'|'utf-32'){buf}, {row}, {col}, {offset_encoding}) 特定のバッファ内の位置のUTF-32およびUTF-16オフセットを返します。{buf} (integer) バッファ番号 (現在の場合は0){row} (integer) 0から始まる行{col} (integer) 行内の0から始まるバイトオフセット{offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) デフォルトは、bufの最初のクライアントのoffset_encodinginteger) バッファ{buf}の行{row}の列{col}にある文字のoffset_encodingインデックス{input}, {contents}) MarkedString | MarkedString[] | MarkupContent のいずれかを有効なマークダウンを含む行のリストに変換します。textDocument/hoverのホバーウィンドウの入力、textDocument/signatureHelpの結果の解析などに役立ちます。MarkupContent型で、その種類がplaintextの場合、対応する値はそれ以上変更を加えずに返されることに注意してください。{input} (lsp.MarkedString|lsp.MarkedString[]|lsp.MarkupContent){contents} (string[]?) 変換された行で拡張する文字列のリスト。デフォルトは{}。string[]) 変換されたマークダウンの行で拡張されたもの。{signature_help}, {ft}, {triggers}) textDocument/signatureHelp のレスポンスをマークダウンの行に変換します。{signature_help} (lsp.SignatureHelp) textDocument/SignatureHelp のレスポンス{ft} (string?) ラベルのマークダウンコードブロックの `lang` として使用されるファイルタイプ{triggers} (string[]?) LSPサーバーからのトリガー文字のリスト。パラメーターのオフセットをより正確に決定するために使用されます。string[]?) 変換されたマークダウンの行。(Range4?) アクティブなパラメーターのハイライト範囲{bufnr} (integer?) バッファーハンドル。デフォルトは現在。integer) インデントサイズ{locations}, {offset_encoding}) クイックフィックスとロケーションリストに表示するために、バイト位置が正しく計算され、ソートされた順序でアイテムを返します。user_data フィールドには、計算元の元の Location または LocationLink が含まれます。{locations} (lsp.Location[]|lsp.LocationLink[]){offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) デフォルトはバッファーの最初のクライアント{width}, {height}, {opts}) フローティングウィンドウの適切なデフォルトオプションを持つテーブルを作成します。テーブルは nvim_open_win() に渡すことができます。{width} (integer) ウィンドウ幅(文字セル単位){height} (integer) ウィンドウ高さ(文字セル単位){opts} (vim.lsp.util.open_floating_preview.Opts?) vim.lsp.util.open_floating_preview.Opts を参照してください。table) オプション{options}) 現在のバッファーとカーソル位置の DocumentFormattingParams オブジェクトを作成します。{options} (lsp.FormattingOptions?) 有効な FormattingOptions エントリーlsp.DocumentFormattingParams) オブジェクト{start_pos}, {end_pos}, {bufnr}, {offset_encoding}) 現在のバッファーの指定された範囲を使用して、vim.lsp.util.make_range_params() と同様のオブジェクトを作成します。{start_pos} ([integer,integer]?) {row,col} マークインデックス位置。デフォルトは最後のビジュアル選択の開始位置。{end_pos} ([integer,integer]?) {row,col} マークインデックス位置。デフォルトは最後のビジュアル選択の終了位置。{bufnr} (integer?) バッファーハンドル。現在のバッファーは 0。デフォルトは現在。{offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) デフォルトは bufnr の最初のクライアントの offset_encodingtable) { textDocument = { uri = current_file_uri }, range = { start = start_position, end = end_position } }{window}, {offset_encoding}) 現在のバッファーとカーソル位置の TextDocumentPositionParams オブジェクトを作成します。{window} (integer?) ウィンドウハンドル。現在のウィンドウは 0。デフォルトは現在。{offset_encoding} ('utf-8'|'utf-16'|'utf-32'?) デフォルトは window のバッファーの最初のクライアントの offset_encodinglsp.TextDocumentPositionParams){window}, {offset_encoding}) 現在のバッファーの現在の位置を使用して、textDocument/codeAction、textDocument/colorPresentation、textDocument/rangeFormatting など、いくつかのLSPリクエストの構成要素として使用できるオブジェクトを作成します。{window} (integer?) ウィンドウハンドル。現在のウィンドウは 0。デフォルトは現在。{offset_encoding} ("utf-8"|"utf-16"|"utf-32"?) デフォルトは window のバッファーの最初のクライアントの offset_encodingtable) { textDocument = { uri = current_file_uri }, range = { start = current_position, end = current_position } }{bufnr}) 現在のバッファーの TextDocumentIdentifier オブジェクトを作成します。{bufnr} (integer?) バッファーハンドル。デフォルトは現在。lsp.TextDocumentIdentifier){added} (lsp.WorkspaceFolder[]){removed} (lsp.WorkspaceFolder[])lsp.WorkspaceFoldersChangeEvent){contents}, {syntax}, {opts}) フローティングウィンドウにコンテンツを表示します。{contents} (table) ウィンドウに表示する行{syntax} (string) 開いたバッファーに設定するシンタックス{opts} (vim.lsp.util.open_floating_preview.Opts?) オプションのフィールド付き(追加のキーは vim.lsp.util.make_floating_popup_options() でフィルタリングされてから nvim_open_win() に渡されます)。vim.lsp.util.open_floating_preview.Opts を参照してください。integer) 新しく作成されたフローティングウィンドウの bufnr (integer) 新しく作成されたフローティングウィンドウプレビューウィンドウの winid{location} (lsp.Location|lsp.LocationLink){opts} (vim.lsp.util.open_floating_preview.Opts?) vim.lsp.util.open_floating_preview.Opts を参照してください。integer?) フローティングウィンドウのバッファーID (integer?) フローティングウィンドウのウィンドウIDopts が上書きを要求する場合。または{old_fname} (string){new_fname} (string){opts} (table?) オプション{overwrite} (boolean){ignoreIfExists} (boolean){location}, {offset_encoding}, {opts}) ドキュメントを表示し、オプションでその場所にジャンプします。{location} (lsp.Location|lsp.LocationLink){offset_encoding} ('utf-8'|'utf-16'|'utf-32'?){opts} (table?) 次のフィールドを持つテーブル{reuse_win} (boolean) バッファがすでに開いている場合は、既存のウィンドウにジャンプします。{focus} (boolean) 可能であれば、場所にフォーカス/ジャンプするかどうか。(デフォルト: true)boolean) 成功した場合は true{bufnr}, {contents}, {opts}) マークダウンを、コードブロックを削除して強調表示されたコードに変換することにより、シンタックスを強調表示した領域に変換します。デフォルトでは、可読性を向上させるために、これらのコードブロック領域の後に空白行区切り記号が挿入されます。open_floating_preview を使用してください。{bufnr} (integer){contents} (string[]) ウィンドウに表示する行{opts} (table?) オプションのフィールド付きtable) ストリップされたコンテンツ{symbols} (lsp.DocumentSymbol[]|lsp.SymbolInformation[]){bufnr} (integer?)string) ログファイル名integer) 現在のログレベル{handle} (function) ロギング引数に適用する関数。複数行のフォーマットには vim.inspect を渡します{level} (string|integer) vim.lsp.log.levels のいずれか{level} (integer) ログレベルbool) ログを記録する場合は true、そうでない場合は false{request} (fun(method: string, params: table?, callback: fun(err: lsp.ResponseError?, result: any), notify_reply_callback: fun(message_id: integer)?):boolean,integer?) vim.lsp.rpc.request() を参照してください{is_closing} (fun(): boolean){terminate} (fun()){host_or_path}, {port}) vim.lsp.rpc.connect(){host_or_path} (string) 接続先のホストまたはパイプ/ドメインソケットへのパス{port} (integer?) 接続先の TCP ポート。指定しない場合、最初の引数はパイプである必要がありますfun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient){err} (table) エラーオブジェクトstring) error_message フォーマットされたエラーメッセージ{method} (string) 呼び出されるLSPメソッド{params} (table?) 呼び出されるLSPメソッドのパラメータboolean) 通知を送信できた場合はtrue、できなかった場合はfalse{method}, {params}, {callback}, {notify_reply_callback}) LSPサーバーにリクエストを送信し、レスポンス時に{callback}を実行します。{method} (string) 呼び出されるLSPメソッド{params} (table?) 呼び出されるLSPメソッドのパラメータ{callback} (fun(err: lsp.ResponseError?, result: any)) 呼び出すコールバック関数{notify_reply_callback} (fun(message_id: integer)?) リクエストが保留中でなくなったときにすぐに呼び出すコールバック関数boolean) success リクエストを送信できた場合はtrue、できなかった場合はfalse (integer?) リクエストを送信できた場合はmessage_id、できなかった場合はnil{code}, {message}, {data}) LSPレスポンスに送信するRPCレスポンステーブルのerrorを作成します。{code} (integer) 定義済みのRPCエラーコード。vim.lsp.protocol.ErrorCodesを参照してください。{message} (string?) サーバーに送信する任意のエラーメッセージ{data} (any?) サーバーに送信する任意のデータlsp.ResponseError)vim.lsp.protocol.ErrorCodesを参照してください。{cmd}, {dispatchers}, {extra_spawn_params}) vim.lsp.rpc.start() LSPサーバープロセスを開始し、それとやり取りするためのLSP RPCクライアントオブジェクトを作成します。spawnされたプロセスとの通信は標準入出力(stdio)を介して行われます。TCP経由で通信する場合は、プロセスを手動でspawnし、vim.lsp.rpc.connect()を使用してください。{cmd} (string[]) LSPサーバーを起動するためのコマンド。{dispatchers} (table?) LSPメッセージタイプのディスパッチャ。{notification} (fun(method: string, params: table)){server_request} (fun(method: string, params: table): any?, lsp.ResponseError?){on_exit} (fun(code: integer, signal: integer)){on_error} (fun(code: integer, err: any)){extra_spawn_params} (table?) LSPサーバープロセスの追加コンテキスト。{cwd} (string) LSPサーバープロセスの作業ディレクトリ{detached} (boolean) 現在のプロセスからLSPサーバープロセスをデタッチします。vim.lsp.rpc.PublicClient) 次のメソッドを持つクライアントRPCオブジェクトnotify() vim.lsp.rpc.notify()request() vim.lsp.rpc.request()is_closing() RPCがクローズ中かどうかを示すブール値を返します。terminate() RPCクライアントを終了します。vim.lsp.rpc.PublicClientを参照してください。lsp.ClientCapabilities){server_capabilities}) LSPサーバーの機能を記述する正規化されたオブジェクトを作成します。{server_capabilities} (table) サーバーがサポートする機能のテーブルlsp.ServerCapabilities?) 正規化された機能のテーブル