Plugins and users need to react to LSP lifecycle events—attach to buffers, respond to progress, handle document changes. Neovim needs a way to signal when these events occur so users can customize behavior.
LSP Events are Neovim autocmd events triggered during LSP client lifecycle: LspAttach (client initializes), LspDetach (client disconnects), LspProgress (server sends progress), LspRequest (request status changes), LspNotify (notification sent), LspTokenUpdate (semantic token changed).
- LspAttach: Fired after client initializes and attaches to buffer; provides
client_idin event data - LspDetach: Fired just before client detaches; clean up custom handlers here
- LspProgress: Triggered on progress notifications; use for statusline updates
- LspRequest: Fires on request send, completion, or cancellation; track pending work
- LspNotify: Fires after each successful notification to server
- LspTokenUpdate: Fires when semantic tokens change; for custom token highlighting
- Use
vim.api.nvim_create_autocmd()with event name - Event data passed to callback contains client_id, method, params, etc.
- LspProgress pattern can be filtered by work done kind (begin/report/end)
- Dynamic registration may add capabilities after LspAttach
- Built from: LSP Client — events relate to client lifecycle
- Builds into: vim.lsp — vim.lsp triggers these events
- Related: Semantic Tokens — LspTokenUpdate for token changes
- Dynamic registration can happen after LspAttach; handle registerCapability event
- LspDetach is the place to remove buffer-local autocmds (like format on save)
- LspRequest with type=complete deletes pending request after handler runs
- LspTokenUpdate is experimental beyond calling highlight_token()