mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
refactor(lsp): define Capability.on_attach
This commit is contained in:
@@ -69,6 +69,16 @@ function M:destroy()
|
||||
self.active[self.bufnr] = nil
|
||||
end
|
||||
|
||||
--- Callback invoked when an LSP client attaches.
|
||||
--- Use it to initialize per-client state (empty table, new namespaces, etc.),
|
||||
--- or issue requests as needed.
|
||||
---@param client_id integer
|
||||
function M:on_attach(client_id)
|
||||
self.client_state[client_id] = {}
|
||||
end
|
||||
|
||||
--- Callback invoked when an LSP client detaches.
|
||||
--- Use it to clear per-client state (cached data, extmarks, etc.).
|
||||
---@param client_id integer
|
||||
function M:on_detach(client_id)
|
||||
self.client_state[client_id] = nil
|
||||
|
@@ -265,6 +265,11 @@ function State:destroy()
|
||||
State.active[self.bufnr] = nil
|
||||
end
|
||||
|
||||
---@param client_id integer
|
||||
function State:on_attach(client_id)
|
||||
self:refresh(vim.lsp.get_client_by_id(client_id))
|
||||
end
|
||||
|
||||
---@params client_id integer
|
||||
function State:on_detach(client_id)
|
||||
self.client_state[client_id] = nil
|
||||
@@ -273,14 +278,13 @@ function State:on_detach(client_id)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param client_id? integer
|
||||
---@param client_id integer
|
||||
function M._setup(bufnr, client_id)
|
||||
local state = State.active[bufnr]
|
||||
if not state then
|
||||
state = State:new(bufnr)
|
||||
end
|
||||
|
||||
state:refresh(client_id and vim.lsp.get_client_by_id(client_id))
|
||||
state:on_attach(client_id)
|
||||
end
|
||||
|
||||
---@param kind lsp.FoldingRangeKind
|
||||
|
@@ -201,6 +201,9 @@ function STHighlighter:on_attach(client_id)
|
||||
}
|
||||
self.client_state[client_id] = state
|
||||
end
|
||||
if M.is_enabled({ bufnr = self.bufnr }) then
|
||||
self:send_request()
|
||||
end
|
||||
end
|
||||
|
||||
---@package
|
||||
@@ -581,9 +584,6 @@ function M._start(bufnr, client_id, debounce)
|
||||
end
|
||||
|
||||
highlighter:on_attach(client_id)
|
||||
if M.is_enabled({ bufnr = bufnr }) then
|
||||
highlighter:send_request()
|
||||
end
|
||||
end
|
||||
|
||||
--- Start the semantic token highlighting engine for the given buffer with the
|
||||
|
Reference in New Issue
Block a user