mirror of
https://github.com/neovim/neovim.git
synced 2025-10-01 23:48:32 +00:00
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:
@@ -172,7 +172,7 @@ function tests.prepare_rename_nil()
|
||||
body = function()
|
||||
notify('start')
|
||||
expect_request('textDocument/prepareRename', function()
|
||||
return nil, nil
|
||||
return {}, nil
|
||||
end)
|
||||
notify('shutdown')
|
||||
end,
|
||||
@@ -197,7 +197,7 @@ function tests.prepare_rename_placeholder()
|
||||
end)
|
||||
expect_request('textDocument/rename', function(params)
|
||||
assert_eq(params.newName, 'renameto')
|
||||
return nil, nil
|
||||
return {}, nil
|
||||
end)
|
||||
notify('shutdown')
|
||||
end,
|
||||
@@ -226,7 +226,7 @@ function tests.prepare_rename_range()
|
||||
end)
|
||||
expect_request('textDocument/rename', function(params)
|
||||
assert_eq(params.newName, 'renameto')
|
||||
return nil, nil
|
||||
return {}, nil
|
||||
end)
|
||||
notify('shutdown')
|
||||
end,
|
||||
|
@@ -129,7 +129,7 @@ body {
|
||||
exec_lua(function()
|
||||
_G.server2 = _G._create_server({
|
||||
colorProvider = {
|
||||
documentSelector = nil,
|
||||
documentSelector = vim.NIL,
|
||||
},
|
||||
handlers = {
|
||||
['textDocument/documentColor'] = function(_, _, callback)
|
||||
|
@@ -1976,7 +1976,7 @@ describe('LSP', function()
|
||||
{
|
||||
NIL,
|
||||
{
|
||||
arguments = { 'EXTRACT_METHOD', { metadata = {} }, 3, 0, 6123, NIL },
|
||||
arguments = { 'EXTRACT_METHOD', { metadata = { field = vim.NIL } }, 3, 0, 6123, NIL },
|
||||
command = 'refactor.perform',
|
||||
title = 'EXTRACT_METHOD',
|
||||
},
|
||||
@@ -4498,7 +4498,7 @@ describe('LSP', function()
|
||||
name = 'prepare_rename_placeholder',
|
||||
expected_handlers = {
|
||||
{ NIL, {}, { method = 'shutdown', client_id = 1 } },
|
||||
{ NIL, NIL, { method = 'textDocument/rename', client_id = 1, bufnr = 1 } },
|
||||
{ {}, NIL, { method = 'textDocument/rename', client_id = 1, bufnr = 1 } },
|
||||
{ NIL, {}, { method = 'start', client_id = 1 } },
|
||||
},
|
||||
expected_text = 'placeholder', -- see fake lsp response
|
||||
@@ -4508,7 +4508,7 @@ describe('LSP', function()
|
||||
name = 'prepare_rename_range',
|
||||
expected_handlers = {
|
||||
{ NIL, {}, { method = 'shutdown', client_id = 1 } },
|
||||
{ NIL, NIL, { method = 'textDocument/rename', client_id = 1, bufnr = 1 } },
|
||||
{ {}, NIL, { method = 'textDocument/rename', client_id = 1, bufnr = 1 } },
|
||||
{ NIL, {}, { method = 'start', client_id = 1 } },
|
||||
},
|
||||
expected_text = 'line', -- see test case and fake lsp response
|
||||
|
Reference in New Issue
Block a user