neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 1d8e9b5d070ca43f9a12c865c598f7d7712078c6
parent ea2d226df6f344451306274f3f99911d459fb9dd
Author: Riley Bruins <ribru17@hotmail.com>
Date:   Tue,  8 Jul 2025 18:03:52 -0700

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`.

Diffstat:
Mruntime/lua/vim/lsp/diagnostic.lua | 10+++++++---
Mtest/functional/plugin/lsp/diagnostic_spec.lua | 27+++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua @@ -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. diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -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)