mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 21:25:04 -07:00
fix(diagnostics): if buffer not loaded, skip handlers that set extmark (#25628)
Problem: When enabling diagnostics, there can be diagnostics for unloaded buffer, but some handlers nevertheless attempt to set extmarks in such buffers. Solution: * Exit underline/virtual_text handler if buffer is not loaded. * Don't require is_loaded as precondition for show(), because handlers don't necessarily depend on it.
This commit is contained in:
parent
a63c67005b
commit
35f475d0a5
@ -652,20 +652,18 @@ function M.config(opts, namespace)
|
|||||||
|
|
||||||
if namespace then
|
if namespace then
|
||||||
for bufnr, v in pairs(diagnostic_cache) do
|
for bufnr, v in pairs(diagnostic_cache) do
|
||||||
if api.nvim_buf_is_loaded(bufnr) and v[namespace] then
|
if v[namespace] then
|
||||||
M.show(namespace, bufnr)
|
M.show(namespace, bufnr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for bufnr, v in pairs(diagnostic_cache) do
|
for bufnr, v in pairs(diagnostic_cache) do
|
||||||
if api.nvim_buf_is_loaded(bufnr) then
|
|
||||||
for ns in pairs(v) do
|
for ns in pairs(v) do
|
||||||
M.show(ns, bufnr)
|
M.show(ns, bufnr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--- Set diagnostics for the given namespace and buffer.
|
--- Set diagnostics for the given namespace and buffer.
|
||||||
---
|
---
|
||||||
@ -693,9 +691,7 @@ function M.set(namespace, bufnr, diagnostics, opts)
|
|||||||
set_diagnostic_cache(namespace, bufnr, diagnostics)
|
set_diagnostic_cache(namespace, bufnr, diagnostics)
|
||||||
end
|
end
|
||||||
|
|
||||||
if api.nvim_buf_is_loaded(bufnr) then
|
|
||||||
M.show(namespace, bufnr, nil, opts)
|
M.show(namespace, bufnr, nil, opts)
|
||||||
end
|
|
||||||
|
|
||||||
api.nvim_exec_autocmds('DiagnosticChanged', {
|
api.nvim_exec_autocmds('DiagnosticChanged', {
|
||||||
modeline = false,
|
modeline = false,
|
||||||
@ -928,6 +924,10 @@ M.handlers.underline = {
|
|||||||
bufnr = get_bufnr(bufnr)
|
bufnr = get_bufnr(bufnr)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
|
if not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if opts.underline and opts.underline.severity then
|
if opts.underline and opts.underline.severity then
|
||||||
diagnostics = filter_by_severity(opts.underline.severity, diagnostics)
|
diagnostics = filter_by_severity(opts.underline.severity, diagnostics)
|
||||||
end
|
end
|
||||||
@ -994,6 +994,10 @@ M.handlers.virtual_text = {
|
|||||||
bufnr = get_bufnr(bufnr)
|
bufnr = get_bufnr(bufnr)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
|
if not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local severity
|
local severity
|
||||||
if opts.virtual_text then
|
if opts.virtual_text then
|
||||||
if opts.virtual_text.format then
|
if opts.virtual_text.format then
|
||||||
|
Loading…
Reference in New Issue
Block a user