fix(lsp): improve diagnostics handling and comments

- Add TODO comments for aggregating diagnostics from all pull namespaces
  and for clearing diagnostics when an empty array is received, referencing
  the LSP specification.
- Update diagnostics refresh logic to safely access previousResultId,
  preventing potential nil errors.
This commit is contained in:
tris203
2026-03-19 17:50:40 +00:00
parent 0cda018345
commit 1f558f8d09
2 changed files with 6 additions and 1 deletions

View File

@@ -1365,6 +1365,7 @@ function M.code_action(opts)
params.context = context
else
local ns_push = lsp.diagnostic.get_namespace(client.id, false)
-- TODO(tris203): should we aggregate diagnostics from all the possible pull namespaces?
local ns_pull = lsp.diagnostic.get_namespace(client.id, true)
local diagnostics = {}
local lnum = api.nvim_win_get_cursor(0)[1] - 1

View File

@@ -261,6 +261,8 @@ end
---@param params lsp.PublishDiagnosticsParams
---@param ctx lsp.HandlerContext
function M.on_publish_diagnostics(_, params, ctx)
-- TODO(tris203): if empty array then clear diags
-- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics
handle_diagnostics(params.uri, ctx.client_id, params.diagnostics, false)
end
@@ -396,7 +398,9 @@ function M._refresh(bufnr, client_id, only_visible)
local params = {
identifier = cap.identifier,
textDocument = util.make_text_document_params(bufnr),
previousResultId = bufstate.client_result_id[key],
previousResultId = bufstate
and bufstate.client_result_id
and bufstate.client_result_id[key],
}
client:request(method, params, nil, bufnr)
end)