fix(lsp): decode 'null' in server responses as vim.NIL #34849

Problem:
Previously, 'null' value in LSP responses were decoded as 'nil'.
This caused ambiguity for fields typed as '? | null' and led to
loss of explicit 'null' values, particularly in 'data' parameters.

Solution:
Decode all JSON 'null' values as 'vim.NIL' and adjust handling
where needed. This better aligns with the LSP specification,
where 'null' and absent fields are distinct, and 'null' should
not be used to represent missing values.

This also enables proper validation of response messages to
ensure that exactly one of 'result' or 'error' is present, as
required by the JSON-RPC specification.
This commit is contained in:
skewb1k
2025-08-03 17:42:44 +03:00
committed by GitHub
parent 2ef48fc65c
commit 40aef0d02e
9 changed files with 42 additions and 26 deletions

View File

@@ -520,7 +520,7 @@ function M.apply_text_document_edit(
-- do not check the version after the first edit.
not (index and index > 1)
and (
text_document.version
text_document.version ~= vim.NIL
and text_document.version > 0
and M.buf_versions[bufnr] > text_document.version
)
@@ -827,8 +827,12 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft, triggers
if signature.parameters and #signature.parameters > 0 then
-- First check if the signature has an activeParameter. If it doesn't check if the response
-- had that property instead. Else just default to 0.
local active_parameter =
math.max(signature.activeParameter or signature_help.activeParameter or 0, 0)
--
-- NOTE: Using tonumber() as a temporary workaround to handle `vim.NIL` until #34838 is merged
local active_parameter = math.max(
tonumber(signature.activeParameter) or tonumber(signature_help.activeParameter) or 0,
0
)
-- If the activeParameter is > #parameters, then set it to the last
-- NOTE: this is not fully according to the spec, but a client-side interpretation