aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/lsp.txt
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2022-08-19 12:26:08 -0600
committerJosh Rahm <rahm@google.com>2022-08-19 13:06:41 -0600
commita7237662f96933efe29eed8212464571e3778cd0 (patch)
tree27930202726b4251437c8cfa53069f65b4db90dc /runtime/doc/lsp.txt
parent02292344929069ea63c0bb872cc22d552d86b67f (diff)
parentb2f979b30beac67906b2dd717fcb6a34f46f5e54 (diff)
downloadrneovim-tmp.tar.gz
rneovim-tmp.tar.bz2
rneovim-tmp.zip
Merge branch 'master' of https://github.com/neovim/neovim into rahmtmp
Diffstat (limited to 'runtime/doc/lsp.txt')
-rw-r--r--runtime/doc/lsp.txt2558
1 files changed, 1191 insertions, 1367 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 11f96db8c9..7fc0daa0ca 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -10,7 +10,7 @@ Nvim supports the Language Server Protocol (LSP), which means it acts as
a client to LSP servers and includes a Lua framework `vim.lsp` for building
enhanced LSP tools.
- https://microsoft.github.io/language-server-protocol/
+ https://microsoft.github.io/language-server-protocol/
LSP facilitates features like go-to-definition, find-references, hover,
completion, rename, format, refactor, etc., using semantic whole-project
@@ -34,11 +34,11 @@ Follow these steps to get LSP features:
2. Configure the LSP client per language server.
A minimal example:
>
- vim.lsp.start({
- name = 'my-server-name',
- cmd = {'name-of-language-server-executable'},
- root_dir = vim.fs.dirname(vim.fs.find({'setup.py', 'pyproject.toml'}, { upward = true })[1]),
- })
+ vim.lsp.start({
+ name = 'my-server-name',
+ cmd = {'name-of-language-server-executable'},
+ root_dir = vim.fs.dirname(vim.fs.find({'setup.py', 'pyproject.toml'}, { upward = true })[1]),
+ })
<
See |vim.lsp.start| for details.
@@ -59,6 +59,9 @@ language server supports the functionality.
- |tagfunc| is set to |vim.lsp.tagfunc|. This enables features like
go-to-definition, |:tjump|, and keymaps like |CTRL-]|, |CTRL-W_]|,
|CTRL-W_}| to utilize the language server.
+- |formatexpr| is set to |vim.lsp.formatexpr| if both |formatprg| and
+ |formatexpr| are empty. This allows to format lines via |gq| if the language
+ server supports it.
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
@@ -98,7 +101,7 @@ To learn what capabilities are available you can run the following command in
a buffer with a started LSP client:
>
- :lua =vim.lsp.get_active_clients()[1].server_capabilities
+ :lua =vim.lsp.get_active_clients()[1].server_capabilities
<
Full list of features provided by default can be found in |lsp-buf|.
@@ -160,7 +163,7 @@ 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: >
- :lua print(vim.inspect(vim.tbl_keys(vim.lsp.handlers)))
+ :lua print(vim.inspect(vim.tbl_keys(vim.lsp.handlers)))
<
*lsp-method*
@@ -201,84 +204,83 @@ For |lsp-request|, each |lsp-handler| has this signature: >
function(err, result, ctx, config)
<
- Parameters: ~
- {err} (table|nil)
- When the language server is unable to complete a
- request, a table with information about the error
- is sent. Otherwise, it is `nil`. See |lsp-response|.
- {result} (Result | Params | nil)
- When the language server is able to successfully
- complete a request, this contains the `result` key
- of the response. See |lsp-response|.
- {ctx} (table)
- Context describes additional calling state
- associated with the handler. It consists of the
- following key, value pairs:
-
- {method} (string)
- The |lsp-method| name.
- {client_id} (number)
- The ID of the |vim.lsp.client|.
- {bufnr} (Buffer)
- Buffer handle, or 0 for current.
-
- {params} (table|nil)
- The parameters used in the original request
- which resulted in this handler
- call.
- {config} (table)
- Configuration for the handler.
-
- Each handler can define its own configuration
- table that allows users to customize the behavior
- of a particular handler.
-
- To configure a particular |lsp-handler|, see:
- |lsp-handler-configuration|
-
-
- Returns: ~
- The |lsp-handler| can respond by returning two values: `result, err`
- Where `err` must be shaped like an RPC error:
- `{ code, message, data? }`
-
- You can use |vim.lsp.rpc_response_error()| to create this object.
+ Parameters: ~
+ {err} (table|nil)
+ When the language server is unable to complete a
+ request, a table with information about the error is
+ sent. Otherwise, it is `nil`. See |lsp-response|.
+ {result} (Result | Params | nil)
+ When the language server is able to successfully
+ complete a request, this contains the `result` key of
+ the response. See |lsp-response|.
+ {ctx} (table)
+ Context describes additional calling state associated
+ with the handler. It consists of the following key,
+ value pairs:
+
+ {method} (string)
+ The |lsp-method| name.
+ {client_id} (number)
+ The ID of the |vim.lsp.client|.
+ {bufnr} (Buffer)
+ Buffer handle, or 0 for current.
+ {params} (table|nil)
+ The parameters used in the original
+ request which resulted in this handler
+ call.
+ {config} (table)
+ Configuration for the handler.
+
+ Each handler can define its own configuration table
+ that allows users to customize the behavior of a
+ particular handler.
+
+ To configure a particular |lsp-handler|, see:
+ |lsp-handler-configuration|
+
+
+ Returns: ~
+ The |lsp-handler| can respond by returning two values: `result, err`
+ Where `err` must be shaped like an RPC error:
+ `{ code, message, data? }`
+
+ You can use |vim.lsp.rpc_response_error()| to create this object.
For |lsp-notification|, each |lsp-handler| has this signature: >
function(err, result, ctx, config)
<
- Parameters: ~
- {err} (nil)
- This is always `nil`.
- See |lsp-notification|
- {result} (Result)
- This contains the `params` key of the notification.
- See |lsp-notification|
- {ctx} (table)
- Context describes additional calling state
- associated with the handler. It consists of the
- following key, value pairs:
-
- {method} (string)
- The |lsp-method| name.
- {client_id} (number)
- The ID of the |vim.lsp.client|.
- {config} (table)
- Configuration for the handler.
-
- Each handler can define its own configuration
- table that allows users to customize the behavior
- of a particular handler.
-
- For an example, see:
- |vim.lsp.diagnostic.on_publish_diagnostics()|
-
- To configure a particular |lsp-handler|, see:
- |lsp-handler-configuration|
-
- Returns: ~
- The |lsp-handler|'s return value will be ignored.
+ Parameters: ~
+ {err} (nil)
+ This is always `nil`.
+ See |lsp-notification|
+ {result} (Result)
+ This contains the `params` key of the notification.
+ See |lsp-notification|
+ {ctx} (table)
+ Context describes additional calling state associated
+ with the handler. It consists of the following key,
+ value pairs:
+
+ {method} (string)
+ The |lsp-method| name.
+ {client_id} (number)
+ The ID of the |vim.lsp.client|.
+ {config} (table)
+ Configuration for the handler.
+
+ Each handler can define its own configuration table
+ that allows users to customize the behavior of a
+ particular handler.
+
+ For an example, see:
+ |vim.lsp.diagnostic.on_publish_diagnostics()|
+
+ To configure a particular |lsp-handler|, see:
+ |lsp-handler-configuration|
+
+ Returns: ~
+ The |lsp-handler|'s return value will be ignored.
*lsp-handler-configuration*
@@ -289,49 +291,50 @@ To configure the behavior of a builtin |lsp-handler|, the convenient method
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.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Disable signs
- signs = false,
- }
- )
+ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
+ vim.lsp.diagnostic.on_publish_diagnostics, {
+ -- Disable signs
+ signs = false,
+ }
+ )
<
To enable signs, use |vim.lsp.with()| again to create and assign a new
|lsp-handler| to |vim.lsp.handlers| for the associated method: >
- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Enable signs
- signs = true,
- }
- )
+ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
+ vim.lsp.diagnostic.on_publish_diagnostics, {
+ -- Enable signs
+ signs = true,
+ }
+ )
<
To configure a handler on a per-server basis, you can use the {handlers} key
for |vim.lsp.start_client()| >
- vim.lsp.start_client {
- ..., -- Other configuration omitted.
- handlers = {
- ["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Disable virtual_text
- virtual_text = false,
- }
- },
- }
+ vim.lsp.start_client {
+ ..., -- Other configuration omitted.
+ handlers = {
+ ["textDocument/publishDiagnostics"] = vim.lsp.with(
+ vim.lsp.diagnostic.on_publish_diagnostics, {
+ -- Disable virtual_text
+ virtual_text = false,
+ }
+ ),
+ },
+ }
<
or if using 'nvim-lspconfig', you can use the {handlers} key of `setup()`: >
- require('lspconfig').rust_analyzer.setup {
- handlers = {
- ["textDocument/publishDiagnostics"] = vim.lsp.with(
- vim.lsp.diagnostic.on_publish_diagnostics, {
- -- Disable virtual_text
- virtual_text = false
- }
- ),
- }
- }
+ require('lspconfig').rust_analyzer.setup {
+ handlers = {
+ ["textDocument/publishDiagnostics"] = vim.lsp.with(
+ vim.lsp.diagnostic.on_publish_diagnostics, {
+ -- Disable virtual_text
+ virtual_text = false
+ }
+ ),
+ }
+ }
<
Some handlers do not have an explicitly named handler function (such as
|on_publish_diagnostics()|). To override these, first create a reference
@@ -354,31 +357,31 @@ Handlers can be set by:
To override the handler for the `"textDocument/definition"` method: >
- vim.lsp.handlers["textDocument/definition"] = my_custom_default_definition
+ 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: >
- vim.lsp.start_client {
- ..., -- Other configuration omitted.
- handlers = {
+ vim.lsp.start_client {
+ ..., -- Other configuration omitted.
+ handlers = {
["textDocument/definition"] = my_custom_server_definition
- },
- }
+ },
+ }
- The {handler} parameter for |vim.lsp.buf_request()|.
This will set the |lsp-handler| ONLY for the current request.
For example: >
- vim.lsp.buf_request(
- 0,
- "textDocument/definition",
- definition_params,
- my_request_custom_definition
- )
+ vim.lsp.buf_request(
+ 0,
+ "textDocument/definition",
+ definition_params,
+ my_request_custom_definition
+ )
<
In summary, the |lsp-handler| will be chosen based on the current |lsp-method|
in the following order:
@@ -400,8 +403,8 @@ https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specificatio
For example `vim.lsp.protocol.ErrorCodes` allows reverse lookup by number or
name: >
- vim.lsp.protocol.TextDocumentSyncKind.Full == 1
- vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
+ vim.lsp.protocol.TextDocumentSyncKind.Full == 1
+ vim.lsp.protocol.TextDocumentSyncKind[1] == "Full"
<
*lsp-response*
@@ -412,7 +415,7 @@ For the format of the response message, see:
For the format of the notification message, see:
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#notificationMessage
- *on-list-handler*
+ *lsp-on-list-handler*
`on_list` receives a table with:
@@ -421,22 +424,22 @@ 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.:
+>
+ local function on_list(options)
+ vim.fn.setqflist({}, ' ', options)
+ vim.api.nvim_command('cfirst')
+ end
- local function on_list(options)
- vim.fn.setqflist({}, ' ', options)
- vim.api.nvim_command('cfirst')
- end
-
- vim.lsp.buf.definition{on_list=on_list}
- vim.lsp.buf.references(nil, {on_list=on_list})
-
+ vim.lsp.buf.definition{on_list=on_list}
+ vim.lsp.buf.references(nil, {on_list=on_list})
+<
If you prefer loclist do something like this:
-
- local function on_list(options)
- vim.fn.setloclist(0, {}, ' ', options)
- vim.api.nvim_command('lopen')
- end
-
+>
+ local function on_list(options)
+ vim.fn.setloclist(0, {}, ' ', options)
+ vim.api.nvim_command('lopen')
+ end
+<
================================================================================
LSP HIGHLIGHT *lsp-highlight*
@@ -461,11 +464,11 @@ Highlight groups related to |lsp-codelens| functionality.
*hl-LspCodeLens*
LspCodeLens
- Used to color the virtual text of the codelens. See
- |nvim_buf_set_extmark()|.
+ Used to color the virtual text of the codelens. See
+ |nvim_buf_set_extmark()|.
LspCodeLensSeparator *hl-LspCodeLensSeparator*
- Used to color the separator between two or more code lens.
+ Used to color the separator between two or more code lens.
*lsp-highlight-signature*
@@ -473,8 +476,8 @@ Highlight groups related to |vim.lsp.handlers.signature_help()|.
*hl-LspSignatureActiveParameter*
LspSignatureActiveParameter
- Used to highlight the active parameter in the signature help. See
- |vim.lsp.handlers.signature_help()|.
+ Used to highlight the active parameter in the signature help. See
+ |vim.lsp.handlers.signature_help()|.
==============================================================================
EVENTS *lsp-events*
@@ -513,317 +516,268 @@ callback in the "data" table. Example: >
In addition, the following |User| |autocommands| are provided:
LspProgressUpdate *LspProgressUpdate*
- Upon receipt of a progress notification from the server. See
- |vim.lsp.util.get_progress_messages()|.
+ Upon receipt of a progress notification from the server. See
+ |vim.lsp.util.get_progress_messages()|.
LspRequest *LspRequest*
- After a change to the active set of pending LSP requests. See {requests}
- in |vim.lsp.client|.
+ After a change to the active set of pending LSP requests. See {requests}
+ in |vim.lsp.client|.
Example: >
- autocmd User LspProgressUpdate redrawstatus
- autocmd User LspRequest redrawstatus
+ autocmd User LspProgressUpdate redrawstatus
+ autocmd User LspRequest redrawstatus
<
==============================================================================
Lua module: vim.lsp *lsp-core*
buf_attach_client({bufnr}, {client_id}) *vim.lsp.buf_attach_client()*
- Implements the `textDocument/did…` notifications required to
- track a buffer for any language server.
+ Implements the `textDocument/did…` notifications required to track a
+ buffer for any language server.
- Without calling this, the server won't be notified of changes
- to a buffer.
+ Without calling this, the server won't be notified of changes to a buffer.
- Parameters: ~
- {bufnr} (number) Buffer handle, or 0 for current
- {client_id} (number) Client id
+ Parameters: ~
+ {bufnr} (number) Buffer handle, or 0 for current
+ {client_id} (number) Client id
buf_detach_client({bufnr}, {client_id}) *vim.lsp.buf_detach_client()*
- Detaches client from the specified buffer. Note: While the
- server is notified that the text document (buffer) was closed,
- it is still able to send notifications should it ignore this
- notification.
+ Detaches client from the specified buffer. Note: While the server is
+ notified that the text document (buffer) was closed, it is still able to
+ send notifications should it ignore this notification.
- Parameters: ~
- {bufnr} (number) Buffer handle, or 0 for current
- {client_id} (number) Client id
+ Parameters: ~
+ {bufnr} (number) Buffer handle, or 0 for current
+ {client_id} (number) Client id
buf_is_attached({bufnr}, {client_id}) *vim.lsp.buf_is_attached()*
- Checks if a buffer is attached for a particular client.
+ Checks if a buffer is attached for a particular client.
- Parameters: ~
- {bufnr} (number) Buffer handle, or 0 for current
- {client_id} (number) the client id
+ Parameters: ~
+ {bufnr} (number) Buffer handle, or 0 for current
+ {client_id} (number) the client id
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
-
- Return: ~
- true if any client returns true; false otherwise
+ Send a notification to a server
- *vim.lsp.buf_request()*
-buf_request({bufnr}, {method}, {params}, {handler})
- Sends an async request for all active clients attached to the
- buffer.
+ Parameters: ~
+ {bufnr} [number] (optional): The number of the buffer
+ {method} [string]: Name of the request method
+ {params} [string]: Arguments to send to the server
- Parameters: ~
- {bufnr} (number) Buffer handle, or 0 for current.
- {method} (string) LSP method name
- {params} (optional, table) Parameters to send to the
- server
- {handler} (optional, function) See |lsp-handler| If nil,
- follows resolution strategy defined in
- |lsp-handler-configuration|
-
- Return: ~
- 2-tuple:
- • Map of client-id:request-id pairs for all successful
- requests.
- • Function which can be used to cancel all the requests.
- You could instead iterate all clients and call their
- `cancel_request()` methods.
+ Return: ~
+ true if any client returns true; false otherwise
*vim.lsp.buf_request_all()*
buf_request_all({bufnr}, {method}, {params}, {callback})
- Sends an async request for all active clients attached to the
- buffer. Executes the callback on the combined result.
- Parameters are the same as |vim.lsp.buf_request()| but the
- return result and callback are different.
-
- Parameters: ~
- {bufnr} (number) Buffer handle, or 0 for current.
- {method} (string) LSP method name
- {params} (optional, table) Parameters to send to the
- server
- {callback} (function) The callback to call when all
- requests are finished.
-
- Return: ~
- (function) A function that will cancel all requests which
- is the same as the one returned from `buf_request`.
+ Sends an async request for all active clients attached to the buffer.
+ Executes the callback on the combined result. Parameters are the same as
+ |vim.lsp.buf_request()| but the return result and callback are different.
+
+ Parameters: ~
+ {bufnr} (number) Buffer handle, or 0 for current.
+ {method} (string) LSP method name
+ {params} (optional, table) Parameters to send to the server
+ {callback} (function) The callback to call when all requests are
+ finished.
+
+ Return: ~
+ (function) A function that will cancel all requests which is the same
+ as the one returned from `buf_request`.
*vim.lsp.buf_request_sync()*
buf_request_sync({bufnr}, {method}, {params}, {timeout_ms})
- Sends a request to all server and waits for the response of
- all of them.
-
- Calls |vim.lsp.buf_request_all()| but blocks Nvim while
- awaiting the result. Parameters are the same as
- |vim.lsp.buf_request()| but the return result is different.
- Wait maximum of {timeout_ms} (default 1000) 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.
-
- Return: ~
- Map of client_id:request_result. On timeout, cancel or
- error, returns `(nil, err)` where `err` is a string
- describing the failure reason.
+ Sends a request to all server and waits for the response of all of them.
+
+ Calls |vim.lsp.buf_request_all()| but blocks Nvim while awaiting the
+ result. Parameters are the same as |vim.lsp.buf_request()| but the return
+ result is different. Wait maximum of {timeout_ms} (default 1000) 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.
+
+ Return: ~
+ Map of client_id:request_result. On timeout, cancel or error, returns
+ `(nil, err)` where `err` is a string describing the failure reason.
client() *vim.lsp.client*
- LSP client object. You can get an active client object via
- |vim.lsp.get_client_by_id()| or
- |vim.lsp.get_active_clients()|.
-
- • Methods:
- • request(method, params, [handler], bufnr) Sends a request
- to the server. This is a thin wrapper around
- {client.rpc.request} with some additional checking. If
- {handler} is not specified, If one is not found there,
- then an error will occur. Returns: {status},
- {[client_id]}. {status} is a boolean indicating if the
- notification was successful. If it is `false`, then it
- will always be `false` (the client has shutdown). If
- {status} is `true`, the function returns {request_id} as
- the second result. You can use this with
- `client.cancel_request(request_id)` to cancel the request.
- • request_sync(method, params, timeout_ms, bufnr) Sends a
- request to the server and synchronously waits for the
- response. This is a wrapper around {client.request}
- Returns: { err=err, result=result }, a dictionary, where
- `err` and `result` come from the |lsp-handler|. On
- timeout, cancel or error, returns `(nil, err)` where `err`
- is a string describing the failure reason. If the request
- was unsuccessful returns `nil`.
- • notify(method, params) Sends a notification to an LSP
- server. Returns: a boolean to indicate if the notification
- was successful. If it is false, then it will always be
- false (the client has shutdown).
- • cancel_request(id) Cancels a request with a given request
- id. Returns: same as `notify()`.
- • stop([force]) Stops a client, optionally with force. By
- default, it will just ask the server to shutdown without
- force. If you request to stop a client which has
- previously been requested to shutdown, it will
- automatically escalate and force shutdown.
- • is_stopped() Checks whether a client is stopped. Returns:
- true if the client is fully stopped.
- • on_attach(client, bufnr) Runs the on_attach function from
- the client's config if it was defined. Useful for
- buffer-local setup.
-
- • Members
- • {id} (number): The id allocated to the client.
- • {name} (string): If a name is specified on creation, that
- will be used. Otherwise it is just the client id. This is
- used for logs and messages.
- • {rpc} (table): RPC client object, for low level
- interaction with the client. See |vim.lsp.rpc.start()|.
- • {offset_encoding} (string): The encoding used for
- communicating with the server. You can modify this in the
- `config`'s `on_init` method before text is sent to the
- server.
- • {handlers} (table): The handlers used by the client as
- described in |lsp-handler|.
- • {requests} (table): The current pending requests in flight
- to the server. Entries are key-value pairs with the key
- being the request ID while the value is a table with
- `type`, `bufnr`, and `method` key-value pairs. `type` is
- either "pending" for an active request, or "cancel" for a
- cancel request.
- • {config} (table): copy of the table that was passed by the
- user to |vim.lsp.start_client()|.
- • {server_capabilities} (table): Response from the server
- sent on `initialize` describing the server's capabilities.
+ LSP client object. You can get an active client object via
+ |vim.lsp.get_client_by_id()| or |vim.lsp.get_active_clients()|.
+
+ • Methods:
+ • request(method, params, [handler], bufnr) Sends a request to the
+ server. This is a thin wrapper around {client.rpc.request} with some
+ additional checking. If {handler} is not specified, If one is not
+ found there, then an error will occur. Returns: {status},
+ {[client_id]}. {status} is a boolean indicating if the notification
+ was successful. If it is `false`, then it will always be `false` (the
+ client has shutdown). If {status} is `true`, the function returns
+ {request_id} as the second result. You can use this with
+ `client.cancel_request(request_id)` to cancel the request.
+ • request_sync(method, params, timeout_ms, bufnr) Sends a request to the
+ server and synchronously waits for the response. This is a wrapper
+ around {client.request} Returns: { err=err, result=result }, a
+ dictionary, where `err` and `result` come from the |lsp-handler|. On
+ timeout, cancel or error, returns `(nil, err)` where `err` is a string
+ describing the failure reason. If the request was unsuccessful returns
+ `nil`.
+ • notify(method, params) Sends a notification to an LSP server. Returns:
+ a boolean to indicate if the notification was successful. If it is
+ false, then it will always be false (the client has shutdown).
+ • cancel_request(id) Cancels a request with a given request id. Returns:
+ same as `notify()`.
+ • stop([force]) Stops a client, optionally with force. By default, it
+ will just ask the server to shutdown without force. If you request to
+ stop a client which has previously been requested to shutdown, it will
+ automatically escalate and force shutdown.
+ • is_stopped() Checks whether a client is stopped. Returns: true if the
+ client is fully stopped.
+ • on_attach(client, bufnr) Runs the on_attach function from the client's
+ config if it was defined. Useful for buffer-local setup.
+
+ • Members
+ • {id} (number): The id allocated to the client.
+ • {name} (string): If a name is specified on creation, that will be
+ used. Otherwise it is just the client id. This is used for logs and
+ messages.
+ • {rpc} (table): RPC client object, for low level interaction with the
+ client. See |vim.lsp.rpc.start()|.
+ • {offset_encoding} (string): The encoding used for communicating with
+ the server. You can modify this in the `config`'s `on_init` method
+ before text is sent to the server.
+ • {handlers} (table): The handlers used by the client as described in
+ |lsp-handler|.
+ • {requests} (table): The current pending requests in flight to the
+ server. Entries are key-value pairs with the key being the request ID
+ while the value is a table with `type`, `bufnr`, and `method`
+ key-value pairs. `type` is either "pending" for an active request, or
+ "cancel" for a cancel request.
+ • {config} (table): copy of the table that was passed by the user to
+ |vim.lsp.start_client()|.
+ • {server_capabilities} (table): Response from the server sent on
+ `initialize` describing the server's capabilities.
client_is_stopped({client_id}) *vim.lsp.client_is_stopped()*
- Checks whether a client is stopped.
+ Checks whether a client is stopped.
- Parameters: ~
- {client_id} (Number)
+ Parameters: ~
+ {client_id} (Number)
- Return: ~
- true if client is stopped, false otherwise.
+ Return: ~
+ true if client is stopped, false otherwise.
*vim.lsp.for_each_buffer_client()*
for_each_buffer_client({bufnr}, {fn})
- Invokes a function for each LSP client attached to a buffer.
-
- Parameters: ~
- {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: >
-
- vim.lsp.for_each_buffer_client(0, function(client, client_id, bufnr)
- print(vim.inspect(client))
- end)
+ Invokes a function for each LSP client attached to a buffer.
+
+ Parameters: ~
+ {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: >
+
+ vim.lsp.for_each_buffer_client(0, function(client, client_id, bufnr)
+ print(vim.inspect(client))
+ end)
<
formatexpr({opts}) *vim.lsp.formatexpr()*
- Provides an interface between the built-in client and a
- `formatexpr` function.
-
- Currently only supports a single client. This can be set via
- `setlocal formatexpr=v:lua.vim.lsp.formatexpr()` but will
- typically or in `on_attach` via
- `vim.api.nvim_buf_set_option(bufnr, 'formatexpr',
- 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})')`.
-
- Parameters: ~
- {opts} (table) options for customizing the formatting
- expression which takes the following optional
- keys:
- • timeout_ms (default 500ms). The timeout period
- for the formatting request.
+ Provides an interface between the built-in client and a `formatexpr`
+ function.
+
+ Currently only supports a single client. This can be set via `setlocal
+ formatexpr=v:lua.vim.lsp.formatexpr()` but will typically or in
+ `on_attach` via `vim.api.nvim_buf_set_option(bufnr, 'formatexpr',
+ 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})')`.
+
+ Parameters: ~
+ {opts} (table) options for customizing the formatting expression
+ which takes the following optional keys:
+ • timeout_ms (default 500ms). The timeout period for the
+ formatting request.
get_active_clients({filter}) *vim.lsp.get_active_clients()*
- Get active clients.
-
- Parameters: ~
- {filter} (table|nil) A table with key-value pairs used to
- filter the returned clients. The available keys
- are:
- • id (number): Only return clients with the
- given id
- • bufnr (number): Only return clients attached
- to this buffer
- • name (string): Only return clients with the
- given name
-
- Return: ~
- (table) List of |vim.lsp.client| objects
+ Get active clients.
+
+ Parameters: ~
+ {filter} (table|nil) A table with key-value pairs used to filter the
+ returned clients. The available keys are:
+ • id (number): Only return clients with the given id
+ • bufnr (number): Only return clients attached to this
+ buffer
+ • name (string): Only return clients with the given name
+
+ Return: ~
+ (table) List of |vim.lsp.client| objects
*vim.lsp.get_buffers_by_client_id()*
get_buffers_by_client_id({client_id})
- Returns list of buffers attached to client_id.
+ Returns list of buffers attached to client_id.
- Parameters: ~
- {client_id} (number) client id
+ Parameters: ~
+ {client_id} (number) client id
- Return: ~
- list of buffer ids
+ Return: ~
+ list of buffer ids
get_client_by_id({client_id}) *vim.lsp.get_client_by_id()*
- Gets a client by id, or nil if the id is invalid. The returned
- client may not yet be fully initialized.
+ Gets a client by id, or nil if the id is invalid. The returned client ma