mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
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:
@@ -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.
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user