mirror of
https://github.com/neovim/neovim.git
synced 2026-04-27 09:44:07 +00:00
perf(lsp): include previousResultId in DocumentDiagnosticParams #32887
Problem:
Users of the Roslyn (C#) LSP have encountered significant delays when
retrieving pull diagnostics in large documents while using Neovim. For
instance, diagnostics in a 2000-line .cs file can take over 20 seconds
to display after edits in Neovim, whereas in VS Code, diagnostics for
the same file are displayed almost instantly.
As [mparq noted](https://github.com/seblj/roslyn.nvim/issues/93#issuecomment-2508940330)
in https://github.com/seblj/roslyn.nvim/issues/93, VS Code leverages
additional parameters specified in the [LSP documentation for
textDocument/diagnostic](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentDiagnosticParams),
specifically:
- previousResultId
- identifier
Solution:
When requesting diagnostics, Neovim should include the
`previousResultId` and `identifier` parameters as part of the request.
These parameters enable the server to utilize caching and return
incremental results.
Support for maintaining state is already present in the
[textDocument/semanticTokens implementation](8f84167c30/runtime/lua/vim/lsp/semantic_tokens.lua (L289)).
A similar mechanism can be implemented in `textDocument/diagnostic` handler.
This commit is contained in:
@@ -215,7 +215,8 @@ describe('vim.lsp.diagnostic', function()
|
||||
diagnosticProvider = {},
|
||||
},
|
||||
handlers = {
|
||||
[vim.lsp.protocol.Methods.textDocument_diagnostic] = function()
|
||||
[vim.lsp.protocol.Methods.textDocument_diagnostic] = function(_, params)
|
||||
_G.params = params
|
||||
_G.requests = _G.requests + 1
|
||||
end,
|
||||
},
|
||||
@@ -275,6 +276,7 @@ describe('vim.lsp.diagnostic', function()
|
||||
},
|
||||
uri = fake_uri,
|
||||
client_id = client_id,
|
||||
bufnr = diagnostic_bufnr,
|
||||
}, {})
|
||||
|
||||
return vim.diagnostic.get(diagnostic_bufnr)
|
||||
@@ -300,6 +302,7 @@ describe('vim.lsp.diagnostic', function()
|
||||
},
|
||||
uri = fake_uri,
|
||||
client_id = client_id,
|
||||
bufnr = diagnostic_bufnr,
|
||||
}, {})
|
||||
return vim.diagnostic.get(diagnostic_bufnr)
|
||||
end)
|
||||
@@ -320,6 +323,7 @@ describe('vim.lsp.diagnostic', function()
|
||||
},
|
||||
uri = fake_uri,
|
||||
client_id = client_id,
|
||||
bufnr = diagnostic_bufnr,
|
||||
}, {})
|
||||
end)
|
||||
|
||||
@@ -358,6 +362,7 @@ describe('vim.lsp.diagnostic', function()
|
||||
},
|
||||
uri = fake_uri,
|
||||
client_id = client_id,
|
||||
bufnr = diagnostic_bufnr,
|
||||
}, {})
|
||||
end)
|
||||
|
||||
@@ -392,6 +397,7 @@ describe('vim.lsp.diagnostic', function()
|
||||
}, {}, {
|
||||
method = vim.lsp.protocol.Methods.textDocument_diagnostic,
|
||||
client_id = client_id,
|
||||
bufnr = diagnostic_bufnr,
|
||||
})
|
||||
|
||||
return _G.requests
|
||||
@@ -408,6 +414,7 @@ describe('vim.lsp.diagnostic', function()
|
||||
}, {}, {
|
||||
method = vim.lsp.protocol.Methods.textDocument_diagnostic,
|
||||
client_id = client_id,
|
||||
bufnr = diagnostic_bufnr,
|
||||
})
|
||||
|
||||
return _G.requests
|
||||
@@ -424,11 +431,42 @@ describe('vim.lsp.diagnostic', function()
|
||||
}, {}, {
|
||||
method = vim.lsp.protocol.Methods.textDocument_diagnostic,
|
||||
client_id = client_id,
|
||||
bufnr = diagnostic_bufnr,
|
||||
})
|
||||
|
||||
return _G.requests
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('requests with the `previousResultId`', function()
|
||||
eq(
|
||||
'dummy_server',
|
||||
exec_lua(function()
|
||||
vim.lsp.diagnostic.on_diagnostic(nil, {
|
||||
kind = 'full',
|
||||
resultId = 'dummy_server',
|
||||
items = {
|
||||
_G.make_error('Pull Diagnostic', 4, 4, 4, 4),
|
||||
},
|
||||
}, {
|
||||
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