Once an LSP server is started, the editor needs to manage its state—track attached buffers, send requests, handle responses, and monitor capabilities. This requires an abstraction representing the active LSP connection.
An LSP Client is a Neovim object representing an active connection to a language server. It holds the server’s capabilities, attached buffers, pending requests, and methods for interaction.
- Creation:
vim.lsp.start()orvim.lsp.enable()creates a client from a config - Retrieval:
vim.lsp.get_client_by_id(id),vim.lsp.get_clients({filter}) - Capabilities:
client.server_capabilitiesexposes what the server supports - Request tracking:
client.pending_requeststracks in-flight requests - Buffer association:
client.attached_buffersmaps to buffers using LSP - Methods:
client.request(),client.notify(),client.cancel_request()
- Unique
idfor referencing the client namefrom config or defaultserver_capabilitiespopulated after initializationroot_dirderived from config or root_markers- Can attach to multiple buffers simultaneously
- Built from: LSP Configuration — config creates client
- Builds into: vim.lsp — clients are managed by vim.lsp
- Related: LSP Events — events fired based on client activity
- Client may not be fully initialized when first returned
- Dynamic registration can add capabilities after LspAttach
- Stopped clients return nil from get_client_by_id
- Request cancellation triggers LspRequest event with type=cancel