fix(lsp): retrigger diagnostics request on server cancellation (#31345) (#31427)

Co-authored-by: Jesse <github@jessebakker.com>
(cherry picked from commit 29c72cdf4a)
This commit is contained in:
Gregory Anders
2024-12-02 12:13:23 -06:00
committed by GitHub
parent e80e8a0980
commit 308e9719cf
7 changed files with 122 additions and 8 deletions

View File

@@ -315,11 +315,19 @@ end
--- )
--- ```
---
---@param _ lsp.ResponseError?
---@param error lsp.ResponseError?
---@param result lsp.DocumentDiagnosticReport
---@param ctx lsp.HandlerContext
---@param config vim.diagnostic.Opts Configuration table (see |vim.diagnostic.config()|).
function M.on_diagnostic(_, result, ctx, config)
function M.on_diagnostic(error, result, ctx, config)
if error ~= nil and error.code == protocol.ErrorCodes.ServerCancelled then
if error.data == nil or error.data.retriggerRequest ~= false then
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
client.request(ctx.method, ctx.params)
end
return
end
if result == nil or result.kind == 'unchanged' then
return
end

View File

@@ -716,7 +716,8 @@ for k, fn in pairs(M) do
})
end
if err then
-- ServerCancelled errors should be propagated to the request handler
if err and err.code ~= protocol.ErrorCodes.ServerCancelled then
-- LSP spec:
-- interface ResponseError:
-- code: integer;

View File

@@ -166,6 +166,7 @@ local constants = {
-- Defined by the protocol.
RequestCancelled = -32800,
ContentModified = -32801,
ServerCancelled = -32802,
},
-- Describes the content type that a client supports in various