mirror of
https://github.com/neovim/neovim.git
synced 2025-10-19 00:01:54 +00:00
fix(lsp): clean the diagnostic cache when buffer delete (#19449)
Co-authored-by: Gregory Anders <greg@gpanders.com>
This commit is contained in:
@@ -45,18 +45,24 @@ local bufnr_and_namespace_cacher_mt = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local diagnostic_cache = setmetatable({}, {
|
local diagnostic_cache
|
||||||
__index = function(t, bufnr)
|
do
|
||||||
assert(bufnr > 0, 'Invalid buffer number')
|
local group = vim.api.nvim_create_augroup('DiagnosticBufDelete', {})
|
||||||
vim.api.nvim_buf_attach(bufnr, false, {
|
diagnostic_cache = setmetatable({}, {
|
||||||
on_detach = function()
|
__index = function(t, bufnr)
|
||||||
rawset(t, bufnr, nil) -- clear cache
|
assert(bufnr > 0, 'Invalid buffer number')
|
||||||
end,
|
vim.api.nvim_create_autocmd('BufDelete', {
|
||||||
})
|
group = group,
|
||||||
t[bufnr] = {}
|
buffer = bufnr,
|
||||||
return t[bufnr]
|
callback = function()
|
||||||
end,
|
rawset(t, bufnr, nil)
|
||||||
})
|
end,
|
||||||
|
})
|
||||||
|
t[bufnr] = {}
|
||||||
|
return t[bufnr]
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local diagnostic_cache_extmarks = setmetatable({}, bufnr_and_namespace_cacher_mt)
|
local diagnostic_cache_extmarks = setmetatable({}, bufnr_and_namespace_cacher_mt)
|
||||||
local diagnostic_attached_buffers = {}
|
local diagnostic_attached_buffers = {}
|
||||||
|
@@ -128,6 +128,28 @@ describe('vim.diagnostic', function()
|
|||||||
eq('Diagnostic #1', result[1].message)
|
eq('Diagnostic #1', result[1].message)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('removes diagnostics from the cache when a buffer is removed', function()
|
||||||
|
eq(2, exec_lua [[
|
||||||
|
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
|
||||||
|
local other_bufnr = vim.fn.bufadd('test | test')
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(diagnostic_bufnr, 0, -1, true)
|
||||||
|
vim.api.nvim_buf_set_lines(other_bufnr, 0, 1, false, lines)
|
||||||
|
vim.cmd('bunload! ' .. other_bufnr)
|
||||||
|
|
||||||
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
|
||||||
|
make_error('Diagnostic #1', 1, 1, 1, 1),
|
||||||
|
make_error('Diagnostic #2', 2, 1, 2, 1),
|
||||||
|
})
|
||||||
|
vim.diagnostic.set(diagnostic_ns, other_bufnr, {
|
||||||
|
make_error('Diagnostic #3', 3, 1, 3, 1),
|
||||||
|
})
|
||||||
|
vim.api.nvim_set_current_buf(other_bufnr)
|
||||||
|
vim.opt_local.buflisted = true
|
||||||
|
vim.cmd('bwipeout!')
|
||||||
|
return #vim.diagnostic.get()
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('resolves buffer number 0 to the current buffer', function()
|
it('resolves buffer number 0 to the current buffer', function()
|
||||||
eq(2, exec_lua [[
|
eq(2, exec_lua [[
|
||||||
vim.api.nvim_set_current_buf(diagnostic_bufnr)
|
vim.api.nvim_set_current_buf(diagnostic_bufnr)
|
||||||
|
Reference in New Issue
Block a user