mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(diagnostic): ensure autocmd always is always sent diagnostics
This commit is contained in:

committed by
Lewis Russell

parent
b6b35cb557
commit
2b21c9c23f
@@ -418,7 +418,7 @@ local bufnr_and_namespace_cacher_mt = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- bufnr -> ns -> Diagnostic[]
|
-- bufnr -> ns -> Diagnostic[]
|
||||||
local diagnostic_cache = {} --- @type table<integer,table<integer,vim.Diagnostic[]>>
|
local diagnostic_cache = {} --- @type table<integer,table<integer,vim.Diagnostic[]?>>
|
||||||
do
|
do
|
||||||
local group = api.nvim_create_augroup('nvim.diagnostic.buf_wipeout', {})
|
local group = api.nvim_create_augroup('nvim.diagnostic.buf_wipeout', {})
|
||||||
setmetatable(diagnostic_cache, {
|
setmetatable(diagnostic_cache, {
|
||||||
@@ -710,16 +710,6 @@ local function norm_diag(bufnr, namespace, d)
|
|||||||
d1.bufnr = bufnr
|
d1.bufnr = bufnr
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param namespace integer
|
|
||||||
--- @param bufnr integer
|
|
||||||
--- @param diagnostics vim.Diagnostic.Set[]
|
|
||||||
local function set_diagnostic_cache(namespace, bufnr, diagnostics)
|
|
||||||
for _, diagnostic in ipairs(diagnostics) do
|
|
||||||
norm_diag(bufnr, namespace, diagnostic)
|
|
||||||
end
|
|
||||||
diagnostic_cache[bufnr][namespace] = diagnostics
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @param bufnr integer
|
--- @param bufnr integer
|
||||||
--- @param last integer
|
--- @param last integer
|
||||||
local function restore_extmarks(bufnr, last)
|
local function restore_extmarks(bufnr, last)
|
||||||
@@ -1260,10 +1250,16 @@ function M.set(namespace, bufnr, diagnostics, opts)
|
|||||||
|
|
||||||
bufnr = vim._resolve_bufnr(bufnr)
|
bufnr = vim._resolve_bufnr(bufnr)
|
||||||
|
|
||||||
|
for _, diagnostic in ipairs(diagnostics) do
|
||||||
|
norm_diag(bufnr, namespace, diagnostic)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @cast diagnostics vim.Diagnostic[]
|
||||||
|
|
||||||
if vim.tbl_isempty(diagnostics) then
|
if vim.tbl_isempty(diagnostics) then
|
||||||
diagnostic_cache[bufnr][namespace] = nil
|
diagnostic_cache[bufnr][namespace] = nil
|
||||||
else
|
else
|
||||||
set_diagnostic_cache(namespace, bufnr, diagnostics)
|
diagnostic_cache[bufnr][namespace] = diagnostics
|
||||||
end
|
end
|
||||||
|
|
||||||
M.show(namespace, bufnr, nil, opts)
|
M.show(namespace, bufnr, nil, opts)
|
||||||
@@ -1272,7 +1268,7 @@ function M.set(namespace, bufnr, diagnostics, opts)
|
|||||||
modeline = false,
|
modeline = false,
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
-- TODO(lewis6991): should this be deepcopy()'d like they are in vim.diagnostic.get()
|
-- TODO(lewis6991): should this be deepcopy()'d like they are in vim.diagnostic.get()
|
||||||
data = { diagnostics = diagnostic_cache[bufnr][namespace] },
|
data = { diagnostics = diagnostics },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -2714,6 +2714,23 @@ describe('vim.diagnostic', function()
|
|||||||
eq({}, result)
|
eq({}, result)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('always passes a table to DiagnosticChanged autocommand', function()
|
||||||
|
local result = exec_lua(function()
|
||||||
|
local changed_diags --- @type vim.Diagnostic[]?
|
||||||
|
vim.api.nvim_create_autocmd('DiagnosticChanged', {
|
||||||
|
buffer = _G.diagnostic_bufnr,
|
||||||
|
callback = function(args)
|
||||||
|
--- @type vim.Diagnostic[]
|
||||||
|
changed_diags = args.data.diagnostics
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {})
|
||||||
|
return changed_diags
|
||||||
|
end)
|
||||||
|
eq('table', type(result))
|
||||||
|
eq(0, #result)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('open_float()', function()
|
describe('open_float()', function()
|
||||||
|
Reference in New Issue
Block a user