refactor(lsp): no longer rely on LspDetach for detaching capabilities

This commit is contained in:
Yi Ming
2025-07-21 17:57:01 +08:00
parent b3fbc8d6fa
commit 2ace4089f8
2 changed files with 18 additions and 11 deletions

View File

@@ -60,17 +60,6 @@ function M:new(bufnr)
})
self.client_state = {}
api.nvim_create_autocmd('LspDetach', {
group = self.augroup,
buffer = bufnr,
callback = function(args)
self:on_detach(args.data.client_id)
if next(self.client_state) == nil then
self:destroy()
end
end,
})
Class.active[bufnr] = self
return self
end

View File

@@ -1209,6 +1209,24 @@ function Client:_on_detach(bufnr)
})
end
for _, Capability in pairs(vim.lsp._capability.all) do
if
self:supports_method(Capability.method)
and vim.lsp._capability.is_enabled(Capability.name, {
bufnr = bufnr,
client_id = self.id,
})
then
local capability = Capability.active[bufnr]
if capability then
capability:on_detach(self.id)
if next(capability.client_state) == nil then
capability:destroy()
end
end
end
end
changetracking.reset_buf(self, bufnr)
if self:supports_method(ms.textDocument_didClose) then