fix(diagnostic): remove invalid buffers from cache (#16397)

Errors were being caused by invalid buffers being kept around in
diagnostic_cache, so add a metatable to diagnostic_cache which attaches
to new buffers in the cache, removing them after they are invalidated.

Closes #16391.

Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com>
This commit is contained in:
smolck
2021-11-21 19:40:06 -06:00
committed by GitHub
parent 0d967f0298
commit 04bfd20bb8
2 changed files with 40 additions and 23 deletions

View File

@@ -343,6 +343,16 @@ describe('vim.diagnostic', function()
eq(0, result[5])
eq(3, result[6])
end)
it("doesn't error after bwipeout on buffer", function()
exec_lua [[
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { lnum = 0, end_lnum = 0, col = 0, end_col = 0 })
vim.cmd("bwipeout! " .. diagnostic_bufnr)
vim.diagnostic.show(diagnostic_ns)
vim.diagnostic.hide(diagnostic_ns)
]]
end)
end)
describe('enable() and disable()', function()
@@ -629,6 +639,15 @@ describe('vim.diagnostic', function()
]])
end)
it("doesn't error after bwipeout called on buffer", function()
exec_lua [[
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { lnum = 0, end_lnum = 0, col = 0, end_col = 0 })
vim.cmd("bwipeout! " .. diagnostic_bufnr)
vim.diagnostic.reset(diagnostic_ns)
]]
end)
end)
describe('get_next_pos()', function()