fix(lsp): store result id for unchanged diagnostic reports

**Problem:** For unchanged document diagnostic reports, the `resultId`
is ignored completely, even though it should still be saved for the
request (in fact, the spec marks it as mandatory for unchanged reports,
so it should be extra important).

**Solution:** Always store the `resultId`.
This commit is contained in:
Riley Bruins
2025-07-08 18:03:52 -07:00
parent ea2d226df6
commit 1d8e9b5d07
2 changed files with 34 additions and 3 deletions

View File

@@ -269,16 +269,20 @@ function M.on_diagnostic(error, result, ctx)
return
end
if result == nil or result.kind == 'unchanged' then
if result == nil then
return
end
local client_id = ctx.client_id
handle_diagnostics(ctx.params.textDocument.uri, client_id, result.items, true)
local bufnr = assert(ctx.bufnr)
local bufstate = bufstates[bufnr]
bufstate.client_result_id[client_id] = result.resultId
if result.kind == 'unchanged' then
return
end
handle_diagnostics(ctx.params.textDocument.uri, client_id, result.items, true)
end
--- Clear push diagnostics and diagnostic cache.

View File

@@ -470,6 +470,7 @@ describe('vim.lsp.diagnostic', function()
end)
it('requests with the `previousResultId`', function()
-- Full reports
eq(
'dummy_server',
exec_lua(function()
@@ -497,6 +498,32 @@ describe('vim.lsp.diagnostic', function()
return _G.params.previousResultId
end)
)
-- Unchanged reports
eq(
'squidward',
exec_lua(function()
vim.lsp.diagnostic.on_diagnostic(nil, {
kind = 'unchanged',
resultId = 'squidward',
}, {
method = vim.lsp.protocol.Methods.textDocument_diagnostic,
params = {
textDocument = { uri = fake_uri },
},
client_id = client_id,
bufnr = diagnostic_bufnr,
})
vim.api.nvim_exec_autocmds('LspNotify', {
buffer = diagnostic_bufnr,
data = {
method = vim.lsp.protocol.Methods.textDocument_didChange,
client_id = client_id,
},
})
return _G.params.previousResultId
end)
)
end)
end)
end)