aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2022-12-18 03:19:15 +0100
committerGitHub <noreply@github.com>2022-12-17 19:19:15 -0700
commit1743359235206cbd9da2e0589f1caba37cce3b8c (patch)
tree8c72770e496f916941af352ffb73d026191d5306 /runtime/lua/vim/diagnostic.lua
parent1c4794944deb734b24b4a424c50b766a96e050dd (diff)
downloadrneovim-1743359235206cbd9da2e0589f1caba37cce3b8c.tar.gz
rneovim-1743359235206cbd9da2e0589f1caba37cce3b8c.tar.bz2
rneovim-1743359235206cbd9da2e0589f1caba37cce3b8c.zip
fix(diagnostic): clear stale cache on reset (#21454)
The BufWipeout autocmd is not 100% reliable and may leave stale entries in the cache. This is sort of a hack/workaround to ensure `vim.diagnostic.reset` calls don't fail if there are stale cache entries but instead clears them Fixes errors like Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/diagnostic.lua:1458: Invalid buffer id: 22 stack traceback: [C]: in function 'nvim_exec_autocmds' /usr/share/nvim/runtime/lua/vim/diagnostic.lua:1458: in function 'reset'
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r--runtime/lua/vim/diagnostic.lua24
1 files changed, 16 insertions, 8 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index 7557bc79a2..8ca324d666 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -922,7 +922,7 @@ M.handlers.signs = {
end,
hide = function(namespace, bufnr)
local ns = M.get_namespace(namespace)
- if ns.user_data.sign_group then
+ if ns.user_data.sign_group and api.nvim_buf_is_valid(bufnr) then
vim.fn.sign_unplace(ns.user_data.sign_group, { buffer = bufnr })
end
end,
@@ -977,7 +977,9 @@ M.handlers.underline = {
local ns = M.get_namespace(namespace)
if ns.user_data.underline_ns then
diagnostic_cache_extmarks[bufnr][ns.user_data.underline_ns] = {}
- api.nvim_buf_clear_namespace(bufnr, ns.user_data.underline_ns, 0, -1)
+ if api.nvim_buf_is_valid(bufnr) then
+ api.nvim_buf_clear_namespace(bufnr, ns.user_data.underline_ns, 0, -1)
+ end
end
end,
}
@@ -1040,7 +1042,9 @@ M.handlers.virtual_text = {
local ns = M.get_namespace(namespace)
if ns.user_data.virt_text_ns then
diagnostic_cache_extmarks[bufnr][ns.user_data.virt_text_ns] = {}
- api.nvim_buf_clear_namespace(bufnr, ns.user_data.virt_text_ns, 0, -1)
+ if api.nvim_buf_is_valid(bufnr) then
+ api.nvim_buf_clear_namespace(bufnr, ns.user_data.virt_text_ns, 0, -1)
+ end
end
end,
}
@@ -1470,11 +1474,15 @@ function M.reset(namespace, bufnr)
M.hide(iter_namespace, iter_bufnr)
end
- api.nvim_exec_autocmds('DiagnosticChanged', {
- modeline = false,
- buffer = iter_bufnr,
- data = { diagnostics = {} },
- })
+ if api.nvim_buf_is_valid(iter_bufnr) then
+ api.nvim_exec_autocmds('DiagnosticChanged', {
+ modeline = false,
+ buffer = iter_bufnr,
+ data = { diagnostics = {} },
+ })
+ else
+ diagnostic_cache[iter_bufnr] = nil
+ end
end
end