Handle nil result in pull diagnostic handler (#5147)

- A stale or cancelled textDocument/diagnostic request can be answered
  with a nil result and no error, which is valid per the LSP
  specification. Guard against it so the handler does nothing rather
  than indexing the nil result.
This commit is contained in:
Paul Johnson
2026-07-25 22:21:28 +09:00
committed by GitHub
parent d0ea943232
commit 5fab9dec37
2 changed files with 28 additions and 1 deletions
+27
View File
@@ -444,4 +444,31 @@ describe("ale.lsp.start", function()
},
}, vim_fn_calls)
end)
it("should ignore pull model diagnostics with a nil result", function()
lsp.start({name = "server:/code"})
eq(1, #start_calls)
local handlers = start_calls[1][1].handlers
eq("function", type(handlers["textDocument/diagnostic"]))
-- A stale request can be answered with a nil result and no error,
-- which is valid per the LSP specification. The handler should do
-- nothing rather than index the nil result.
handlers["textDocument/diagnostic"](
nil,
nil,
{
params = {
textDocument = {
uri = "file://code/foo.py",
},
},
}
)
eq({}, vim_fn_calls)
end)
end)