nvim_runtime_lua

vim.lsp.client

Methods25

function Client.get_language_id(bufnr: integer, filetype: string) -> string
function Client.create(config: vim.lsp.ClientConfig) -> vim.lsp.Client | nil

@nodoc

function Client.initialize() -> nil

@nodoc

function Client.request(method: vim.lsp.protocol.Method.ClientToServer.Request, params: nil | table, handler: lsp.Handler | nil, bufnr: nil | integer) -> (status boolean, request_id nil | integer)

Sends a request to the server.

This is a thin wrapper around {client.rpc.request} with some additional checks for capabilities and handler availability.

Parameters
paramsnil | table

LSP request params.

handlerlsp.Handler | nil

Response |lsp-handler| for this method.

bufnrnil | integer

(default: 0) Buffer handle, or 0 for current.

Returns
statusboolean

indicates whether the request was successful. If it is false, then it will always be false (the client has shutdown).

request_idnil | integer

Can be used with |Client:cancel_request()|. nil is request failed. to cancel the-request.

See:

|vim.lsp.bufrequestall()|

function Client.request_sync(method: vim.lsp.protocol.Method.ClientToServer.Request, params: table, timeout_ms: nil | integer, bufnr: nil | integer) -> ({ err: lsp.ResponseError?, result: any } | nil, err nil | string)

Sends a request to the server and synchronously waits for the response.

This is a wrapper around |Client:request()|

Parameters
paramstable

LSP request params.

timeout_msnil | integer

Maximum time in milliseconds to wait for a result. Defaults to 1000

bufnrnil | integer

(default: 0) Buffer handle, or 0 for current.

Returns
{ err: lsp.ResponseError?, result: any } | nil

result and err from the |lsp-handler|. nil is the request was unsuccessful

errnil | string

On timeout, cancel or error, where err is a string describing the failure reason.

See:

|vim.lsp.bufrequestsync()|

function Client.notify(method: vim.lsp.protocol.Method.ClientToServer.Notification, params: nil | table, bufnr: nil | integer) -> status boolean

Sends a notification to an LSP server.

Parameters
paramsnil | table

LSP request params.

bufnrnil | integer

Buffer associated with notification.

Returns
statusboolean

indicating if the notification was successful. If it is false, then the client has shutdown.

function Client.cancel_request(id: integer) -> status boolean

Cancels a request with a given request id.

Parameters
idinteger

id of request to cancel

Returns
statusboolean

indicating if the notification was successful.

See:

|Client:notify()|

function Client.stop(force: nil | boolean | integer) -> nil

Stops a client, optionally with force after a timeout.

By default this sends a "shutdown" request to the server, escalating to force-stop if the server has not exited after self.exit_timeout milliseconds (unless exit_timeout=false). Calling stop() on a client that was previously requested to shutdown, will escalate to force-stop immediately, regardless of force (or self.exit_timeout if force=nil).

Note: Forcing shutdown while a server is busy writing out project or index files can lead to file corruption.

Parameters
forcenil | boolean | integer

(default: self.exit_timeout) Decides whether to force-stop the server.

  • false: Do not force-stop after "shutdown" request.
  • nil: Defaults to exit_timeout from |vim.lsp.ClientConfig|.
  • true: Force-stop after "shutdown" request.
  • number: Wait up to force milliseconds before force-stop.
Returns
nil
function Client._restart(force: nil | boolean | integer) -> nil

Stops a client, then starts a new client with the same config and attached buffers.

Parameters
forcenil | boolean | integer

See [Client:stop()] for details. (default: self.exit_timeout)

Returns
nil
function Client._handle_restart() -> nil
function Client._supports_registration(method: vim.lsp.protocol.Method | vim.lsp.protocol.Method.Registration) -> any

Get options for a method that is registered dynamically.

function Client._registration_provider(method: vim.lsp.protocol.Method | vim.lsp.protocol.Method.Registration) -> "$/cancelRequest" | "$/logTrace" | "$/progress" | "$/setTrace" | "callHierarchyProvider" | "client/registerCapability" | "client/unregisterCapability" | "codeActionProvider" | "codeLensProvider" | "completionProvider" | "documentLinkProvider" | "exit" | "initialize" | "initialized" | "inlayHintProvider" | "notebookDocument/didChange" | "notebookDocument/didClose" | "notebookDocument/didOpen" | "notebookDocument/didSave" | "shutdown" | "telemetry/event" | "colorProvider" | "declarationProvider" | "definitionProvider" | "diagnosticProvider" | "textDocumentSync" | "documentHighlightProvider" | "documentSymbolProvider" | "foldingRangeProvider" | "documentFormattingProvider" | "hoverProvider" | "implementationProvider" | "inlineCompletionProvider" | "inlineValueProvider" | "linkedEditingRangeProvider" | "monikerProvider" | "documentOnTypeFormattingProvider" | "renameProvider" | "typeHierarchyProvider" | "textDocument/publishDiagnostics" | "documentRangeFormattingProvider" | "referencesProvider" | "selectionRangeProvider" | "semanticTokensProvider" | "signatureHelpProvider" | "typeDefinitionProvider" | "typeHierarchy/subtypes" | "typeHierarchy/supertypes" | "window/logMessage" | "window/showDocument" | "window/showMessage" | "window/showMessageRequest" | "window/workDoneProgress/cancel" | "window/workDoneProgress/create" | "workspace/applyEdit" | "workspace/codeLens/refresh" | "workspace/configuration" | "workspace/diagnostic/refresh" | "workspace/didChangeConfiguration" | "workspace/didChangeWatchedFiles" | "workspace.workspaceFolders.changeNotifications" | "workspace.fileOperations.didCreate" | "workspace.fileOperations.didDelete" | "workspace.fileOperations.didRename" | "executeCommandProvider" | "workspace/foldingRange/refresh" | "workspace/inlayHint/refresh" | "workspace/inlineValue/refresh" | "workspace/semanticTokens/refresh" | "workspaceSymbolProvider" | "workspace.textDocumentContent" | "workspace/textDocumentContent/refresh" | "workspace.fileOperations.willCreate" | "workspace.fileOperations.willDelete" | "workspace.fileOperations.willRename" | "workspace.workspaceFolders"

Get provider for a method to be registered dynamically.

function Client._register(registrations: lsp.Registration[]) -> nil
function Client._unregister(unregistrations: lsp.Unregistration[]) -> nil
function Client._get_registrations(provider: string, bufnr: nil | integer) -> lsp.Registration[] | nil
function Client.is_stopped() -> boolean

Checks whether a client is stopped.

Returns
boolean

true if client is stopped or in the process of being stopped; false otherwise

function Client.exec_cmd(cmd: lsp.Command, context: { bufnr: integer? } | nil, handler: lsp.Handler | nil) -> nil

Execute a lsp command, either via client command function (if available) or via workspace/executeCommand (if supported by the server)

Parameters
context{ bufnr: integer? } | nil
handlerlsp.Handler | nil

only called if a server command

Returns
nil
function Client._text_document_did_close_handler(bufnr: integer) -> nil

Default handler for the 'textDocument/didClose' LSP notification.

Parameters
bufnrinteger

Number of the buffer, or 0 for current

Returns
nil
function Client._text_document_did_open_handler(bufnr: integer) -> nil

Default handler for the 'textDocument/didOpen' LSP notification.

Parameters
bufnrinteger

Number of the buffer, or 0 for current

Returns
nil
function Client.on_attach(bufnr: integer) -> nil

Runs the on_attach function from the client's config if it was defined. Useful for buffer-local setup.

Parameters
bufnrinteger

Buffer number

Returns
nil
function Client.supports_method(method: vim.lsp.protocol.Method.ClientToServer | vim.lsp.protocol.Method.Registration, bufnr: nil | integer) -> boolean

Checks if a client supports a given method. Always returns true for unknown off-spec methods.

Note: Some language server capabilities can be file specific.

function Client._provider_foreach(method: vim.lsp.protocol.Method.ClientToServer | vim.lsp.protocol.Method.Registration, fn: fun(capability_value: lsp.LSPAny) -> nil) -> nil

Executes callback fn for all registrations for a given LSP method.

This handles both static capabilities (declared in server_capabilities during initialization) and dynamic registrations (registered at runtime via client/registerCapability).

Some methods may have multiple registrations (e.g., different documentSelectors or configurations). The callback is invoked once for each registration.

Example: Getting diagnostic identifiers from all registrations client:providerforeach('textDocument/diagnostic', function(cap) print(cap.identifier) -- "static-id", "dynamic-id-1", "dynamic-id-2" end)

Note: Some capabilities alias to different providers. For example, workspace/diagnostic uses the same diagnosticProvider as textDocument/diagnostic.

Parameters
fnfun(capability_value: lsp.LSPAny) -> nil

Callback invoked for each matching capability

Returns
nil
function Client._on_detach(bufnr: integer) -> nil
Parameters
bufnrinteger

resolved buffer

Returns
nil
function Client._add_workspace_folder(dir: nil | string) -> nil

Add a directory to the workspace folders.

function Client._remove_workspace_folder(dir: nil | string) -> nil

Remove a directory to the workspace folders.

Fields27

Client.attached_buffers : {integer, string}

Each buffer's last used languageId.

Client.capabilities : lsp.ClientCapabilities

Capabilities provided by the client (editor or tool), at startup.

Client.commands : {string, fun(command: lsp.Command, ctx: table) -> nil}

Client commands. See [vim.lsp.ClientConfig].

Client.config : vim.lsp.ClientConfig

Copy of the config passed to |vim.lsp.start()|.

Client.dynamic_capabilities : lsp.DynamicCapabilities

Capabilities provided at runtime (after startup).

Client.exit_timeout : boolean | integer

See [vim.lsp.ClientConfig]. (default: false)

Client.flags : vim.lsp.Client.Flags

Experimental client flags:

Client.handlers : {string, lsp.Handler}

See [vim.lsp.ClientConfig].

Client.id : integer

The id allocated to the client.

Client.initialized : true | nil
Client.name : string

See [vim.lsp.ClientConfig].

Client.offset_encoding : "utf-8" | "utf-16" | "utf-32"

See [vim.lsp.ClientConfig].

Client.progress : vim.lsp.Client.Progress

A ring buffer (|vim.ringbuf()|) containing progress messages sent by the server.

Client.requests : {integer, { bufnr: integer, method: string, type: string } | nil}

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. It will be "complete" ephemerally while executing |LspRequest| autocmds when replies are received from the server.

Client.root_dir : nil | string

See [vim.lsp.ClientConfig].

Client.rpc : vim.lsp.rpc.Client

RPC client object, for low level interaction with the client. See |vim.lsp.rpc.start()|.

Client.server_capabilities : lsp.ServerCapabilities | nil

Response from the server sent on initialize describing the server's capabilities.

Client.server_info : lsp.ServerInfo | nil

Response from the server sent on initialize describing server information (e.g. version).

Client.settings : lsp.LSPObject

See [vim.lsp.ClientConfig].

Client.workspace_folders : lsp.WorkspaceFolder[] | nil

See [vim.lsp.ClientConfig].

Client._enabled_capabilities : {vim.lsp.capability.Name, nil | boolean}
Client._otf_enabled : nil | boolean

Whether on-type formatting is enabled for this client.

Client._on_error_cb : fun(code: integer, err: string) -> nil | nil
Client.__index : vim.lsp.Client
Client._is_stopping: false
Client.messages: table
Deprecated
use client.progress instead
Client._all : {integer, vim.lsp.Client}

Export for internal use only.