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.
methodvim.lsp.protocol.Method.ClientToServer.RequestLSP method name.
paramsnil | tableLSP request params.
handlerlsp.Handler | nilResponse |lsp-handler| for this method.
bufnrnil | integer(default: 0) Buffer handle, or 0 for current.
statusbooleanindicates whether the request was successful. If it is
false, then it will always befalse(the client has shutdown).request_idnil | integerCan be used with |Client:cancel_request()|.
nilis request failed. to cancel the-request.
|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()|
methodvim.lsp.protocol.Method.ClientToServer.RequestLSP method name.
paramstableLSP request params.
timeout_msnil | integerMaximum time in milliseconds to wait for a result. Defaults to 1000
bufnrnil | integer(default: 0) Buffer handle, or 0 for current.
- { err: lsp.ResponseError?, result: any } | nil
resultanderrfrom the |lsp-handler|.nilis the request was unsuccessfulerrnil | stringOn timeout, cancel or error, where
erris a string describing the failure reason.
|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.
methodvim.lsp.protocol.Method.ClientToServer.NotificationLSP method name.
paramsnil | tableLSP request params.
bufnrnil | integerBuffer associated with notification.
statusbooleanindicating 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.
idintegerid of request to cancel
statusbooleanindicating if the notification was successful.
|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.
forcenil | boolean | integer(default:
self.exit_timeout) Decides whether to force-stop the server.false: Do not force-stop after "shutdown" request.nil: Defaults toexit_timeoutfrom |vim.lsp.ClientConfig|.true: Force-stop after "shutdown" request.- number: Wait up to
forcemilliseconds before force-stop.
- nil
function Client._restart(force: nil | boolean | integer) -> nil
Stops a client, then starts a new client with the same config and attached buffers.
forcenil | boolean | integerSee [Client:stop()] for details. (default:
self.exit_timeout)
- 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.
- 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)
cmdlsp.Commandcontext{ bufnr: integer? } | nilhandlerlsp.Handler | nilonly called if a server command
- nil
function Client._text_document_did_close_handler(bufnr: integer) -> nil
Default handler for the 'textDocument/didClose' LSP notification.
bufnrintegerNumber of the buffer, or 0 for current
- nil
function Client._text_document_did_open_handler(bufnr: integer) -> nil
Default handler for the 'textDocument/didOpen' LSP notification.
bufnrintegerNumber of the buffer, or 0 for current
- 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.
bufnrintegerBuffer number
- 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.
methodvim.lsp.protocol.Method.ClientToServer | vim.lsp.protocol.Method.RegistrationLSP method name
fnfun(capability_value: lsp.LSPAny) -> nilCallback invoked for each matching capability
- nil
function Client._on_detach(bufnr: integer) -> nil
bufnrintegerresolved buffer
- 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
Client._all : {integer, vim.lsp.Client}
Export for internal use only.