mirror of
https://github.com/neovim/neovim.git
synced 2026-07-23 09:23:09 +00:00
fix(lsp): capability cleanup #40763
This commit is contained in:
@@ -18,7 +18,7 @@ local all_capabilities = {}
|
||||
|
||||
--- Track each capability instance created per buffer
|
||||
---@type table<integer, vim.lsp.Capability[]> buffer -> list of active capability instances
|
||||
local buf_capabilities = vim.defaulttable()
|
||||
local buf_capabilities = {}
|
||||
|
||||
-- Abstract base class (not instantiable directly).
|
||||
-- For each buffer that has at least one supported client attached,
|
||||
@@ -73,7 +73,12 @@ function M:new(bufnr)
|
||||
})
|
||||
self.client_state = {}
|
||||
|
||||
if not buf_capabilities[bufnr] then
|
||||
buf_capabilities[bufnr] = {}
|
||||
end
|
||||
|
||||
table.insert(buf_capabilities[bufnr], self)
|
||||
|
||||
Class.active[bufnr] = self
|
||||
return self
|
||||
end
|
||||
@@ -111,24 +116,27 @@ function M:on_detach(client_id)
|
||||
self.client_state[client_id] = nil
|
||||
end
|
||||
|
||||
---@param name vim.lsp.capability.Name
|
||||
local function make_enable_var(name)
|
||||
return ('_lsp_enabled_%s'):format(name)
|
||||
end
|
||||
|
||||
--- Callback invoked when textDocument/didClose is sent for a client.
|
||||
---@param client_id integer
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function M:on_close(client_id) end
|
||||
|
||||
--- Callback invoked when textDocument/didChange or textDocument/didOpen is sent for a client.
|
||||
---@param client_id integer
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function M:on_change(client_id) end
|
||||
|
||||
--- Callback invoked on every redraw.
|
||||
---@param topline integer
|
||||
---@param botline integer
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
function M:on_win(topline, botline) end
|
||||
|
||||
---@param name vim.lsp.capability.Name
|
||||
local function make_enable_var(name)
|
||||
return ('_lsp_enabled_%s'):format(name)
|
||||
end
|
||||
|
||||
--- Optional filters |kwargs|,
|
||||
---@class vim.lsp.capability.enable.Filter
|
||||
---@inlinedoc
|
||||
@@ -250,6 +258,10 @@ nvim_on('LspNotify', augroup, function(ev)
|
||||
local client_id = ev.data.client_id ---@type integer
|
||||
local bufnr = ev.buf
|
||||
|
||||
if not buf_capabilities[bufnr] then
|
||||
return
|
||||
end
|
||||
|
||||
for _, provider in ipairs(buf_capabilities[bufnr]) do
|
||||
if provider.client_state[client_id] then
|
||||
if ev.data.method == 'textDocument/didClose' then
|
||||
@@ -266,8 +278,12 @@ end)
|
||||
local namespace = api.nvim_create_namespace('nvim.lsp.capability')
|
||||
api.nvim_set_decoration_provider(namespace, {
|
||||
on_win = function(_, _, bufnr, topline, botline)
|
||||
for _, capability in ipairs(buf_capabilities[bufnr]) do
|
||||
capability:on_win(topline, botline)
|
||||
if not buf_capabilities[bufnr] then
|
||||
return
|
||||
end
|
||||
|
||||
for _, provider in ipairs(buf_capabilities[bufnr]) do
|
||||
provider:on_win(topline, botline)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user