aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/lsp.txt
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/doc/lsp.txt')
-rw-r--r--runtime/doc/lsp.txt509
1 files changed, 284 insertions, 225 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 139f4c6bc5..215515a2d9 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -33,7 +33,7 @@ Follow these steps to get LSP features:
2. Configure the LSP client per language server.
A minimal example:
->
+>lua
vim.lsp.start({
name = 'my-server-name',
cmd = {'name-of-language-server-executable'},
@@ -44,7 +44,7 @@ Follow these steps to get LSP features:
3. Configure keymaps and autocmds to utilize LSP features.
See |lsp-config|.
-<
+
*lsp-config*
Starting a LSP client will automatically report diagnostics via
@@ -66,7 +66,7 @@ language server supports the functionality.
To use other LSP features like hover, rename, etc. you can setup some
additional keymaps. It's recommended to setup them in a |LspAttach| autocmd to
ensure they're only active if there is a LSP client running. An example:
->
+>lua
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf })
@@ -86,7 +86,7 @@ The most used functions are:
Not all language servers provide the same capabilities. To ensure you only set
keymaps if the language server supports a feature, you can guard the keymap
calls behind capability checks:
->
+>lua
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
@@ -100,7 +100,7 @@ calls behind capability checks:
To learn what capabilities are available you can run the following command in
a buffer with a started LSP client:
->
+>vim
:lua =vim.lsp.get_active_clients()[1].server_capabilities
<
@@ -110,14 +110,14 @@ Full list of features provided by default can be found in |lsp-buf|.
FAQ *lsp-faq*
- Q: How to force-reload LSP?
- A: Stop all clients, then reload the buffer. >
+ A: Stop all clients, then reload the buffer. >vim
:lua vim.lsp.stop_client(vim.lsp.get_active_clients())
:edit
- Q: Why isn't completion working?
A: In the buffer where you want to use LSP, check that 'omnifunc' is set to
- "v:lua.vim.lsp.omnifunc": >
+ "v:lua.vim.lsp.omnifunc": >vim
:verbose set omnifunc?
@@ -129,7 +129,7 @@ FAQ *lsp-faq*
A: Check if the function has an `async` parameter and set the value to
false.
- E.g. code formatting: >
+ E.g. code formatting: >vim
" Auto-format *.rs (rust) files prior to saving them
" (async = false is the default for format)
@@ -162,7 +162,7 @@ to the given buffer. |lsp-buf|
LSP request/response handlers are implemented as Lua functions (see
|lsp-handler|). The |vim.lsp.handlers| table defines default handlers used
-when creating a new client. Keys are LSP method names: >
+when creating a new client. Keys are LSP method names: >vim
:lua print(vim.inspect(vim.tbl_keys(vim.lsp.handlers)))
<
@@ -291,7 +291,7 @@ To configure the behavior of a builtin |lsp-handler|, the convenient method
To configure the behavior of |vim.lsp.diagnostic.on_publish_diagnostics()|,
consider the following example, where a new |lsp-handler| is created using
- |vim.lsp.with()| that no longer generates signs for the diagnostics: >
+ |vim.lsp.with()| that no longer generates signs for the diagnostics: >lua
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
@@ -301,7 +301,7 @@ To configure the behavior of a builtin |lsp-handler|, the convenient method
)
<
To enable signs, use |vim.lsp.with()| again to create and assign a new
- |lsp-handler| to |vim.lsp.handlers| for the associated method: >
+ |lsp-handler| to |vim.lsp.handlers| for the associated method: >lua
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
@@ -311,7 +311,7 @@ To configure the behavior of a builtin |lsp-handler|, the convenient method
)
<
To configure a handler on a per-server basis, you can use the {handlers} key
- for |vim.lsp.start_client()| >
+ for |vim.lsp.start_client()| >lua
vim.lsp.start_client {
..., -- Other configuration omitted.
@@ -325,7 +325,8 @@ To configure the behavior of a builtin |lsp-handler|, the convenient method
},
}
<
- or if using 'nvim-lspconfig', you can use the {handlers} key of `setup()`: >
+ or if using "nvim-lspconfig", you can use the {handlers} key of `setup()`:
+ >lua
require('lspconfig').rust_analyzer.setup {
handlers = {
@@ -340,7 +341,7 @@ To configure the behavior of a builtin |lsp-handler|, the convenient method
<
Some handlers do not have an explicitly named handler function (such as
||vim.lsp.diagnostic.on_publish_diagnostics()|). To override these, first
- create a reference to the existing handler: >
+ create a reference to the existing handler: >lua
local on_references = vim.lsp.handlers["textDocument/references"]
vim.lsp.handlers["textDocument/references"] = vim.lsp.with(
@@ -357,14 +358,14 @@ Handlers can be set by:
vim.lsp.handlers is a global table that contains the default mapping of
|lsp-method| names to |lsp-handlers|.
- To override the handler for the `"textDocument/definition"` method: >
+ To override the handler for the `"textDocument/definition"` method: >lua
vim.lsp.handlers["textDocument/definition"] = my_custom_default_definition
<
- The {handlers} parameter for |vim.lsp.start_client()|.
This will set the |lsp-handler| as the default handler for this server.
- For example: >
+ For example: >lua
vim.lsp.start_client {
..., -- Other configuration omitted.
@@ -376,7 +377,7 @@ Handlers can be set by:
- The {handler} parameter for |vim.lsp.buf_request()|.
This will set the |lsp-handler| ONLY for the current request.
- For example: >
+ For example: >lua
vim.lsp.buf_request(
0,
@@ -403,7 +404,7 @@ and helper functions for creating protocol-related objects.
https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.md
For example `vim.lsp.protocol.ErrorCodes` allows reverse lookup by number or
-name: >
+name: >lua
vim.lsp.protocol.TextDocumentSyncKind.Full == 1
vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
@@ -426,7 +427,7 @@ For the format of the notification message, see:
- `context` table|nil. `ctx` from |lsp-handler|
This table can be used with vim.fn.setqflist or vim.fn.setloclist. E.g.:
->
+>lua
local function on_list(options)
vim.fn.setqflist({}, ' ', options)
vim.api.nvim_command('cfirst')
@@ -436,7 +437,7 @@ This table can be used with vim.fn.setqflist or vim.fn.setloclist. E.g.:
vim.lsp.buf.references(nil, {on_list=on_list})
<
If you prefer loclist do something like this:
->
+>lua
local function on_list(options)
vim.fn.setloclist(0, {}, ' ', options)
vim.api.nvim_command('lopen')
@@ -487,7 +488,7 @@ EVENTS *lsp-events*
*LspAttach*
After an LSP client attaches to a buffer. The |autocmd-pattern| is the
name of the buffer. When used from Lua, the client ID is passed to the
-callback in the "data" table. Example: >
+callback in the "data" table. Example: >lua
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
@@ -505,7 +506,7 @@ callback in the "data" table. Example: >
*LspDetach*
Just before an LSP client detaches from a buffer. The |autocmd-pattern| is the
name of the buffer. When used from Lua, the client ID is passed to the
-callback in the "data" table. Example: >
+callback in the "data" table. Example: >lua
vim.api.nvim_create_autocmd("LspDetach", {
callback = function(args)
@@ -525,7 +526,7 @@ LspRequest *LspRequest*
After a change to the active set of pending LSP requests. See {requests}
in |vim.lsp.client|.
-Example: >
+Example: >vim
autocmd User LspProgressUpdate redrawstatus
autocmd User LspRequest redrawstatus
<
@@ -563,9 +564,9 @@ buf_notify({bufnr}, {method}, {params}) *vim.lsp.buf_notify()*
Send a notification to a server
Parameters: ~
- • {bufnr} [number] (optional): The number of the buffer
- • {method} [string]: Name of the request method
- • {params} [string]: Arguments to send to the server
+ • {bufnr} (number|nil) The number of the buffer
+ • {method} (string) Name of the request method
+ • {params} (any) Arguments to send to the server
Return: ~
true if any client returns true; false otherwise
@@ -579,7 +580,7 @@ buf_request_all({bufnr}, {method}, {params}, {callback})
Parameters: ~
• {bufnr} (number) Buffer handle, or 0 for current.
• {method} (string) LSP method name
- • {params} (optional, table) Parameters to send to the server
+ • {params} (table|nil) Parameters to send to the server
• {callback} (function) The callback to call when all requests are
finished.
@@ -598,9 +599,9 @@ buf_request_sync({bufnr}, {method}, {params}, {timeout_ms})
Parameters: ~
• {bufnr} (number) Buffer handle, or 0 for current.
• {method} (string) LSP method name
- • {params} (optional, table) Parameters to send to the server
- • {timeout_ms} (optional, number, default=1000) Maximum time in
- milliseconds to wait for a result.
+ • {params} (table|nil) Parameters to send to the server
+ • {timeout_ms} (number|nil) Maximum time in milliseconds to wait for a
+ result. Defaults to 1000
Return: ~
Map of client_id:request_result. On timeout, cancel or error, returns
@@ -667,7 +668,7 @@ client_is_stopped({client_id}) *vim.lsp.client_is_stopped()*
Checks whether a client is stopped.
Parameters: ~
- • {client_id} (Number)
+ • {client_id} (number)
Return: ~
true if client is stopped, false otherwise.
@@ -680,7 +681,7 @@ for_each_buffer_client({bufnr}, {fn})
• {bufnr} (number) Buffer number
• {fn} (function) Function to run on each client attached to buffer
{bufnr}. The function takes the client, client ID, and buffer
- number as arguments. Example: >
+ number as arguments. Example: >lua
vim.lsp.for_each_buffer_client(0, function(client, client_id, bufnr)
print(vim.inspect(client))
@@ -746,8 +747,8 @@ omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
Implements 'omnifunc' compatible LSP completion.
Parameters: ~
- • {findstart} 0 or 1, decides behavior
- • {base} If findstart=0, text to match against
+ • {findstart} (number) 0 or 1, decides behavior
+ • {base} (number) findstart=0, text to match against
Return: ~
(number) Decided by {findstart}:
@@ -769,7 +770,7 @@ set_log_level({level}) *vim.lsp.set_log_level()*
Use `lsp.log_levels` for reverse lookup.
Parameters: ~
- • {level} [number|string] the case insensitive level name or number
+ • {level} (number|string) the case insensitive level name or number
See also: ~
|vim.lsp.log_levels|
@@ -779,35 +780,31 @@ start({config}, {opts}) *vim.lsp.start()*
running client if one is found matching `name` and `root_dir`. Attaches
the current buffer to the client.
- Example:
->
+ Example: >lua
- vim.lsp.start({
- name = 'my-server-name',
- cmd = {'name-of-language-server-executable'},
- root_dir = vim.fs.dirname(vim.fs.find({'pyproject.toml', 'setup.py'}, { upward = true })[1]),
- })
+ vim.lsp.start({
+ name = 'my-server-name',
+ cmd = {'name-of-language-server-executable'},
+ root_dir = vim.fs.dirname(vim.fs.find({'pyproject.toml', 'setup.py'}, { upward = true })[1]),
+ })
<
See |vim.lsp.start_client()| for all available options. The most important
are:
- `name` is an arbitrary name for the LSP client. It should be unique per
- language server.
-
- `cmd` the command as list - used to start the language server. The command must
- be present in the `$PATH` environment variable or an absolute path to the executable. Shell
- constructs like `~` are NOT expanded.
-
- `root_dir` path to the project root. By default this is used to decide if
- an existing client should be re-used. The example above uses
- |vim.fs.find()| and |vim.fs.dirname()| to detect the root by traversing
- the file system upwards starting from the current directory until either a
- `pyproject.toml` or `setup.py` file is found.
-
- `workspace_folders` a list of { uri:string, name: string } tables. The
- project root folders used by the language server. If `nil` the property is
- derived from the `root_dir` for convenience.
+ • `name` arbitrary name for the LSP client. Should be unique per language
+ server.
+ • `cmd` command (in list form) used to start the language server. Must be
+ absolute, or found on `$PATH`. Shell constructs like `~` are not
+ expanded.
+ • `root_dir` path to the project root. By default this is used to decide
+ if an existing client should be re-used. The example above uses
+ |vim.fs.find()| and |vim.fs.dirname()| to detect the root by traversing
+ the file system upwards starting from the current directory until either
+ a `pyproject.toml` or `setup.py` file is found.
+ • `workspace_folders` list of `{ uri:string, name: string }` tables
+ specifying the project root folders used by the language server. If
+ `nil` the property is derived from `root_dir` for convenience.
Language servers use this information to discover metadata like the
dependencies of your project and they tend to index the contents within
@@ -835,128 +832,118 @@ start({config}, {opts}) *vim.lsp.start()*
start_client({config}) *vim.lsp.start_client()*
Starts and initializes a client with the given configuration.
- Parameter `cmd` is required.
-
- The following parameters describe fields in the {config} table.
-
- Parameters: ~
- • {cmd} (table|string|fun(dispatchers: table):table)
- command string or list treated like |jobstart()|.
- The command must launch the language server
- process. `cmd` can also be a function that
- creates an RPC client. The function receives a
- dispatchers table and must return a table with
- the functions `request`, `notify`, `is_closing`
- and `terminate` See |vim.lsp.rpc.request()| and
- |vim.lsp.rpc.notify()| For TCP there is a
- built-in rpc client factory:
- |vim.lsp.rpc.connect()|
- • {cmd_cwd} (string, default=|getcwd()|) Directory to launch
- the `cmd` process. Not related to `root_dir`.
- • {cmd_env} (table) Environment flags to pass to the LSP on
- spawn. Can be specified using keys like a map or
- as a list with `k=v` pairs or both. Non-string values are coerced to
- string. Example: >
-
- { "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
+ Field `cmd` in {config} is required.
+
+ Parameters: ~
+ • {config} (table) Configuration for the server:
+ • cmd: (table|string|fun(dispatchers: table):table) command
+ string or list treated like |jobstart()|. The command must
+ launch the language server process. `cmd` can also be a
+ function that creates an RPC client. The function receives
+ a dispatchers table and must return a table with the
+ functions `request`, `notify`, `is_closing` and
+ `terminate` See |vim.lsp.rpc.request()| and
+ |vim.lsp.rpc.notify()| For TCP there is a built-in rpc
+ client factory: |vim.lsp.rpc.connect()|
+ • cmd_cwd: (string, default=|getcwd()|) Directory to launch
+ the `cmd` process. Not related to `root_dir`.
+ • cmd_env: (table) Environment flags to pass to the LSP on
+ spawn. Can be specified using keys like a map or as a list
+ with `k=v` pairs or both. Non-string values are coerced to string.
+ Example: >
+
+ { "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
<
- • {detached} (boolean, default true) Daemonize the server
- process so that it runs in a separate process
- group from Nvim. Nvim will shutdown the process
- on exit, but if Nvim fails to exit cleanly this
- could leave behind orphaned server processes.
- • {workspace_folders} (table) List of workspace folders passed to the
- language server. For backwards compatibility
- rootUri and rootPath will be derived from the
- first workspace folder in this list. See
- `workspaceFolders` in the LSP spec.
- • {capabilities} Map overriding the default capabilities defined
- by |vim.lsp.protocol.make_client_capabilities()|,
- passed to the language server on initialization.
- Hint: use make_client_capabilities() and modify
- its result.
- • Note: To send an empty dictionary use
- `{[vim.type_idx]=vim.types.dictionary}`, else
- it will be encoded as an array.
- • {handlers} Map of language server method names to
- |lsp-handler|
- • {settings} Map with language server specific settings. These
- are returned to the language server if requested
- via `workspace/configuration`. Keys are
- case-sensitive.
- • {commands} (table) Table that maps string of clientside
- commands to user-defined functions. Commands
- passed to start_client take precedence over the
- global command registry. Each key must be a
- unique command name, and the value is a function
- which is called if any LSP action (code action,
- code lenses, ...) triggers the command.
- • {init_options} Values to pass in the initialization request as
- `initializationOptions`. See `initialize` in the
- LSP spec.
- • {name} (string, default=client-id) Name in log messages.
- • {get_language_id} function(bufnr, filetype) -> language ID as
- string. Defaults to the filetype.
- • {offset_encoding} (default="utf-16") One of "utf-8", "utf-16", or
- "utf-32" which is the encoding that the LSP
- server expects. Client does not verify this is
- correct.
- • {on_error} Callback with parameters (code, ...), invoked
- when the client operation throws an error. `code`
- is a number describing the error. Other arguments
- may be passed depending on the error kind. See
- `vim.lsp.rpc.client_errors` for possible errors.
- Use `vim.lsp.rpc.client_errors[code]` to get
- human-friendly name.
- • {before_init} Callback with parameters (initialize_params,
- config) invoked before the LSP "initialize"
- phase, where `params` contains the parameters
- being sent to the server and `config` is the
- config that was passed to
- |vim.lsp.start_client()|. You can use this to
- modify parameters before they are sent.
- • {on_init} Callback (client, initialize_result) invoked
- after LSP "initialize", where `result` is a table
- of `capabilities` and anything else the server
- may send. For example, clangd sends
- `initialize_result.offsetEncoding` if
- `capabilities.offsetEncoding` was sent to it. You
- can only modify the `client.offset_encoding` here
- before any notifications are sent. Most language
- servers expect to be sent client specified
- settings after initialization. Neovim does not
- make this assumption. A
- `workspace/didChangeConfiguration` notification
- should be sent to the server during on_init.
- • {on_exit} Callback (code, signal, client_id) invoked on
- client exit.
- • code: exit code of the process
- • signal: number describing the signal used to
- terminate (if any)
- • client_id: client handle
- • {on_attach} Callback (client, bufnr) invoked when client
- attaches to a buffer.
- • {trace} "off" | "messages" | "verbose" | nil passed
- directly to the language server in the initialize
- request. Invalid/empty values will default to
- "off"
- • {flags} A table with flags for the client. The current
- (experimental) flags are:
- • allow_incremental_sync (bool, default true):
- Allow using incremental sync for buffer edits
- • debounce_text_changes (number, default 150):
- Debounce didChange notifications to the server
- by the given number in milliseconds. No
- debounce occurs if nil
- • exit_timeout (number|boolean, default false):
- Milliseconds to wait for server to exit cleanly
- after sending the "shutdown" request before
- sending kill -15. If set to false, nvim exits
- immediately after sending the "shutdown"
- request to the server.
- • {root_dir} (string) Directory where the LSP server will base
- its workspaceFolders, rootUri, and rootPath on
- initialization.
+ • detached: (boolean, default true) Daemonize the server
+ process so that it runs in a separate process group from
+ Nvim. Nvim will shutdown the process on exit, but if Nvim
+ fails to exit cleanly this could leave behind orphaned
+ server processes.
+ • workspace_folders: (table) List of workspace folders
+ passed to the language server. For backwards compatibility
+ rootUri and rootPath will be derived from the first
+ workspace folder in this list. See `workspaceFolders` in
+ the LSP spec.
+ • capabilities: Map overriding the default capabilities
+ defined by |vim.lsp.protocol.make_client_capabilities()|,
+ passed to the language server on initialization. Hint: use
+ make_client_capabilities() and modify its result.
+ • Note: To send an empty dictionary use
+ `{[vim.type_idx]=vim.types.dictionary}`, else it will be
+ encoded as an array.
+
+ • handlers: Map of language server method names to
+ |lsp-handler|
+ • settings: Map with language server specific settings.
+ These are returned to the language server if requested via
+ `workspace/configuration`. Keys are case-sensitive.
+ • commands: table Table that maps string of clientside
+ commands to user-defined functions. Commands passed to
+ start_client take precedence over the global command
+ registry. Each key must be a unique command name, and the
+ value is a function which is called if any LSP action
+ (code action, code lenses, ...) triggers the command.
+ • init_options Values to pass in the initialization request
+ as `initializationOptions`. See `initialize` in the LSP
+ spec.
+ • name: (string, default=client-id) Name in log messages.
+ • get_language_id: function(bufnr, filetype) -> language ID
+ as string. Defaults to the filetype.
+ • offset_encoding: (default="utf-16") One of "utf-8",
+ "utf-16", or "utf-32" which is the encoding that the LSP
+ server expects. Client does not verify this is correct.
+ • on_error: Callback with parameters (code, ...), invoked
+ when the client operation throws an error. `code` is a
+ number describing the error. Other arguments may be passed
+ depending on the error kind. See
+ `vim.lsp.rpc.client_errors` for possible errors. Use
+ `vim.lsp.rpc.client_errors[code]` to get human-friendly
+ name.
+ • before_init: Callback with parameters (initialize_params,
+ config) invoked before the LSP "initialize" phase, where
+ `params` contains the parameters being sent to the server
+ and `config` is the config that was passed to
+ |vim.lsp.start_client()|. You can use this to modify
+ parameters before they are sent.
+ • on_init: Callback (client, initialize_result) invoked
+ after LSP "initialize", where `result` is a table of
+ `capabilities` and anything else the server may send. For
+ example, clangd sends `initialize_result.offsetEncoding`
+ if `capabilities.offsetEncoding` was sent to it. You can
+ only modify the `client.offset_encoding` here before any
+ notifications are sent. Most language servers expect to be
+ sent client specified settings after initialization.
+ Neovim does not make this assumption. A
+ `workspace/didChangeConfiguration` notification should be
+ sent to the server during on_init.
+ • on_exit Callback (code, signal, client_id) invoked on
+ client exit.
+ • code: exit code of the process
+ • signal: number describing the signal used to terminate
+ (if any)
+ • client_id: client handle
+
+ • on_attach: Callback (client, bufnr) invoked when client
+ attaches to a buffer.
+ • trace: ("off" | "messages" | "verbose" | nil) passed
+ directly to the language server in the initialize request.
+ Invalid/empty values will default to "off"
+ • flags: A table with flags for the client. The current
+ (experimental) flags are:
+ • allow_incremental_sync (bool, default true): Allow using
+ incremental sync for buffer edits
+ • debounce_text_changes (number, default 150): Debounce
+ didChange notifications to the server by the given
+ number in milliseconds. No debounce occurs if nil
+ • exit_timeout (number|boolean, default false):
+ Milliseconds to wait for server to exit cleanly after
+ sending the "shutdown" request before sending kill -15.
+ If set to false, nvim exits immediately after sending
+ the "shutdown" request to the server.
+
+ • root_dir: (string) Directory where the LSP server will
+ base its workspaceFolders, rootUri, and rootPath on
+ initialization.
Return: ~
Client id. |vim.lsp.get_client_by_id()| Note: client may not be fully
@@ -966,19 +953,18 @@ start_client({config}) *vim.lsp.start_client()*
stop_client({client_id}, {force}) *vim.lsp.stop_client()*
Stops a client(s).
- You can also use the `stop()` function on a |vim.lsp.client| object. To
- stop all clients:
->
+ You can also use the `stop()` function on a |vim.lsp.client| object. To stop all clients: >lua
- vim.lsp.stop_client(vim.lsp.get_active_clients())
+ vim.lsp.stop_client(vim.lsp.get_active_clients())
<
By default asks the server to shutdown, unless stop was requested already
for this client, then force-shutdown is attempted.
Parameters: ~
- • {client_id} client id or |vim.lsp.client| object, or list thereof
- • {force} (boolean) (optional) shutdown forcefully
+ • {client_id} number|table id or |vim.lsp.client| object, or list
+ thereof
+ • {force} (boolean|nil) shutdown forcefully
tagfunc({...}) *vim.lsp.tagfunc()*
Provides an interface between the built-in client and 'tagfunc'.
@@ -989,8 +975,8 @@ tagfunc({...}) *vim.lsp.tagfunc()*
LSP servers, falls back to using built-in tags.
Parameters: ~
- • {pattern} Pattern used to find a workspace symbol
- • {flags} See |tag-function|
+ • {pattern} (string) Pattern used to find a workspace symbol
+ • {flags} (string) See |tag-function|
Return: ~
A list of matching tags
@@ -1026,6 +1012,8 @@ code_action({options}) *vim.lsp.buf.code_action()*
• only (table|nil): List of LSP `CodeActionKind`s used to
filter the code actions. Most language servers support
values like `refactor` or `quickfix`.
+ • triggerKind (number|nil): The reason why code actions
+ were requested.
• filter: (function|nil) Predicate taking an `CodeAction`
and returning a boolean.
@@ -1040,6 +1028,7 @@ code_action({options}) *vim.lsp.buf.code_action()*
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
+ vim.lsp.protocol.constants.CodeActionTriggerKind
completion({context}) *vim.lsp.buf.completion()*
Retrieves the completion items at the current cursor position. Can only be
@@ -1080,11 +1069,10 @@ definition({options}) *vim.lsp.buf.definition()*
document_highlight() *vim.lsp.buf.document_highlight()*
Send request to the server to resolve document highlights for the current
text document position. This request can be triggered by a key mapping or
- by events such as `CursorHold`, e.g.:
->
- 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()
+ by events such as `CursorHold` , e.g.: >vim
+ 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()
<
Note: Usage of |vim.lsp.buf.document_highlight()| requires the following
@@ -1128,12 +1116,12 @@ format({options}) *vim.lsp.buf.format()*
buffer (0).
• filter (function|nil): Predicate used to filter clients.
Receives a client as argument and must return a boolean.
- Clients matching the predicate are included. Example: • >
+ Clients matching the predicate are included. Example: • >lua
- -- Never request typescript-language-server for formatting
- vim.lsp.buf.format {
- filter = function(client) return client.name ~= "tsserver" end
- }
+ -- Never request typescript-language-server for formatting
+ vim.lsp.buf.format {
+ filter = function(client) return client.name ~= "tsserver" end
+ }
<
• async boolean|nil If true the method won't block.
Defaults to false. Editing the buffer while formatting
@@ -1179,7 +1167,7 @@ references({context}, {options}) *vim.lsp.buf.references()*
window.
Parameters: ~
- • {context} (table) Context for the request
+ • {context} (table|nil) Context for the request
• {options} (table|nil) additional options
• on_list: (function) handler for list results. See
|lsp-on-list-handler|
@@ -1255,7 +1243,7 @@ on_publish_diagnostics({_}, {result}, {ctx}, {config})
|lsp-handler| for the method "textDocument/publishDiagnostics"
See |vim.diagnostic.config()| for configuration options. Handler-specific
- configuration can be set using |vim.lsp.with()|: >
+ configuration can be set using |vim.lsp.with()|: >lua
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
@@ -1283,6 +1271,13 @@ on_publish_diagnostics({_}, {result}, {ctx}, {config})
==============================================================================
Lua module: vim.lsp.codelens *lsp-codelens*
+clear({client_id}, {bufnr}) *vim.lsp.codelens.clear()*
+ Clear the lenses
+
+ Parameters: ~
+ • {client_id} (number|nil) filter by client_id. All clients if nil
+ • {bufnr} (number|nil) filter by buffer. All buffers if nil
+
display({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.display()*
Display the lenses using virtual text
@@ -1308,8 +1303,9 @@ refresh() *vim.lsp.codelens.refresh()*
Refresh the codelens for the current buffer
It is recommended to trigger this using an autocmd or via keymap.
->
- autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()
+
+ Example: >vim
+ autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()
<
run() *vim.lsp.codelens.run()*
@@ -1325,17 +1321,79 @@ save({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.save()*
==============================================================================
+Lua module: vim.lsp.semantic_tokens *lsp-semantic_tokens*
+
+force_refresh({bufnr}) *vim.lsp.semantic_tokens.force_refresh()*
+ Force a refresh of all semantic tokens
+
+ Only has an effect if the buffer is currently active for semantic token
+ highlighting (|vim.lsp.semantic_tokens.start()| has been called for it)
+
+ Parameters: ~
+ • {bufnr} (nil|number) default: current buffer
+
+ *vim.lsp.semantic_tokens.get_at_pos()*
+get_at_pos({bufnr}, {row}, {col})
+ Return the semantic token(s) at the given position. If called without
+ arguments, returns the token under the cursor.
+
+ Parameters: ~
+ • {bufnr} (number|nil) Buffer number (0 for current buffer, default)
+ • {row} (number|nil) Position row (default cursor position)
+ • {col} (number|nil) Position column (default cursor position)
+
+ Return: ~
+ (table|nil) List of tokens at position
+
+start({bufnr}, {client_id}, {opts}) *vim.lsp.semantic_tokens.start()*
+ Start the semantic token highlighting engine for the given buffer with the
+ given client. The client must already be attached to the buffer.
+
+ NOTE: This is currently called automatically by
+ |vim.lsp.buf_attach_client()|. To opt-out of semantic highlighting with a
+ server that supports it, you can delete the semanticTokensProvider table
+ from the {server_capabilities} of your client in your |LspAttach| callback
+ or your configuration's `on_attach` callback: >lua
+
+ client.server_capabilities.semanticTokensProvider = nil
+<
+
+ Parameters: ~
+ • {bufnr} (number)
+ • {client_id} (number)
+ • {opts} (nil|table) Optional keyword arguments
+ • debounce (number, default: 200): Debounce token
+ requests to the server by the given number in
+ milliseconds
+
+stop({bufnr}, {client_id}) *vim.lsp.semantic_tokens.stop()*
+ Stop the semantic token highlighting engine for the given buffer with the
+ given client.
+
+ NOTE: This is automatically called by a |LspDetach| autocmd that is set up
+ as part of `start()`, so you should only need this function to manually
+ disengage the semantic token engine without fully detaching the LSP client
+ from the buffer.
+
+ Parameters: ~
+ • {bufnr} (number)
+ • {client_id} (number)
+
+
+==============================================================================
Lua module: vim.lsp.handlers *lsp-handlers*
hover({_}, {result}, {ctx}, {config}) *vim.lsp.handlers.hover()*
- |lsp-handler| for the method "textDocument/hover" >
-
- vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
- vim.lsp.handlers.hover, {
- -- Use a sharp border with `FloatBorder` highlights
- border = "single"
- }
- )
+ |lsp-handler| for the method "textDocument/hover" >lua
+
+ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
+ vim.lsp.handlers.hover, {
+ -- Use a sharp border with `FloatBorder` highlights
+ border = "single",
+ -- add the title in hover float window
+ title = "hover"
+ }
+ )
<
Parameters: ~
@@ -1347,14 +1405,14 @@ hover({_}, {result}, {ctx}, {config}) *vim.lsp.handlers.hover()*
*vim.lsp.handlers.signature_help()*
signature_help({_}, {result}, {ctx}, {config})
|lsp-handler| for the method "textDocument/signatureHelp". The active
- parameter is highlighted with |hl-LspSignatureActiveParameter|. >
-
- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
- vim.lsp.handlers.signature_help, {
- -- Use a sharp border with `FloatBorder` highlights
- border = "single"
- }
- )
+ parameter is highlighted with |hl-LspSignatureActiveParameter|. >lua
+
+ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
+ vim.lsp.handlers.signature_help, {
+ -- Use a sharp border with `FloatBorder` highlights
+ border = "single"
+ }
+ )
<
Parameters: ~
@@ -1417,7 +1475,7 @@ buf_highlight_references({bufnr}, {references}, {offset_encoding})
• {offset_encoding} (string) One of "utf-8", "utf-16", "utf-32".
See also: ~
- https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#documentHighlight
+ https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentContentChangeEvent
*vim.lsp.util.character_offset()*
character_offset({buf}, {row}, {col}, {offset_encoding})
@@ -1443,8 +1501,8 @@ convert_input_to_markdown_lines({input}, {contents})
Parameters: ~
• {input} (`MarkedString` | `MarkedString[]` | `MarkupContent`)
- • {contents} (table, optional, default `{}`) List of strings to extend
- with converted lines
+ • {contents} (table|nil) List of strings to extend with converted
+ lines. Defaults to {}.
Return: ~
{contents}, extended with lines of converted markdown.
@@ -1501,7 +1559,7 @@ jump_to_location({location}, {offset_encoding}, {reuse_win})
Parameters: ~
• {location} (table) (`Location`|`LocationLink`)
• {offset_encoding} "utf-8" | "utf-16" | "utf-32"
- • {reuse_win} (boolean) Jump to existing window if buffer is
+ • {reuse_win} (boolean|nil) Jump to existing window if buffer is
already open.
Return: ~
@@ -1547,6 +1605,7 @@ make_floating_popup_options({width}, {height}, {opts})
• border (string or table) override `border`
• focusable (string or table) override `focusable`
• zindex (string or table) override `zindex`, defaults to 50
+ • relative ("mouse"|"cursor") defaults to "cursor"
Return: ~
(table) Options
@@ -1592,7 +1651,7 @@ make_position_params({window}, {offset_encoding})
Parameters: ~
• {window} (number|nil) window handle or 0 for current,
defaults to current
- • {offset_encoding} (string) utf-8|utf-16|utf-32|nil defaults to
+ • {offset_encoding} (string|nil) utf-8|utf-16|utf-32|nil defaults to
`offset_encoding` of first client of buffer of
`window`
@@ -1723,7 +1782,7 @@ show_document({location}, {offset_encoding}, {opts})
Parameters: ~
• {location} (table) (`Location`|`LocationLink`)
• {offset_encoding} "utf-8" | "utf-16" | "utf-32"
- • {opts} (table) options
+ • {opts} (table|nil) options
• reuse_win (boolean) Jump to existing window if
buffer is already open.
• focus (boolean) Whether to focus/jump to location
@@ -1831,7 +1890,7 @@ set_level({level}) *vim.lsp.log.set_level()*
Sets the current log level.
Parameters: ~
- • {level} (string or number) One of `vim.lsp.log.levels`
+ • {level} (string|number) One of `vim.lsp.log.levels`
should_log({level}) *vim.lsp.log.should_log()*
Checks whether the level is sufficient for logging.
@@ -1953,7 +2012,7 @@ compute_diff({___MissingCloseParenHere___})
• {offset_encoding} (string) encoding requested by language server
Return: ~
- (table) TextDocumentContentChangeEvent see https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocumentContentChangeEvent
+ (table) TextDocumentContentChangeEvent see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentContentChangeEvent
==============================================================================