fix(diagnostic): remove buf from cache on BufWipeout (#20099)

Doing so on `BufDelete` has issues:
  - `BufDelete` is also fired for listed buffers that are made unlisted.
  - `BufDelete` is not fired for unlisted buffers that are deleted.

This means that diagnostics will be lost for a buffer that becomes unlisted.

It also means that if an entry exists for an unlisted buffer, deleting that
buffer later will not remove its entry from the cache (and you may see "Invalid
buffer id" errors when using diagnostic functions if it was wiped).

Instead, remove a buffer from the cache if it is wiped out.
This means simply `:bd`ing a buffer will not clear its diagnostics now.
This commit is contained in:
Sean Dewar
2022-09-07 03:55:03 +01:00
committed by GitHub
parent b17c5c3d9c
commit f32fd19f1e
2 changed files with 11 additions and 2 deletions

View File

@@ -47,11 +47,11 @@ local bufnr_and_namespace_cacher_mt = {
local diagnostic_cache
do
local group = vim.api.nvim_create_augroup('DiagnosticBufDelete', {})
local group = vim.api.nvim_create_augroup('DiagnosticBufWipeout', {})
diagnostic_cache = setmetatable({}, {
__index = function(t, bufnr)
assert(bufnr > 0, 'Invalid buffer number')
vim.api.nvim_create_autocmd('BufDelete', {
vim.api.nvim_create_autocmd('BufWipeout', {
group = group,
buffer = bufnr,
callback = function()