backport: fix(lsp): show meaningful error on invalid completion response (#39476)

Problem: vim.NIL is truthy in Lua, so `#(result.items or result)`
crashes on `#vim.NIL` when servers return null.

Solution: skip spec-allowed result=null silently, raise an error
on items=null with the server name.

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion
(cherry picked from commit b9431b340f)

Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
neovim-backports[bot]andglepnir authored and GitHub committed 2026-04-28 11:27:50 -04:00
1 parent 24a4bf20c0
commit 378f5f49b3
2 files changed
+25 -1

No files matched your search

@@ -1182,6 +1182,24 @@ describe('vim.lsp.completion: protocol', function()
eq({ triggerKind = 2, triggerCharacter = 'h' }, exec_lua('return _G.params.context'))
end)
end)
it('errors on invalid items=null in completion response #39400', function()
create_server('dummy', {
isIncomplete = false,
items = vim.NIL,
})
feed('ih')
local err = t.pcall_err(function()
exec_lua(function()
vim.api.nvim_win_set_cursor(0, { 1, 1 })
vim.lsp.completion.get()
vim.wait(1000, function()
return false
end)
end)
end)
t.matches('items=null', err)
end)
end)
describe('vim.lsp.completion: integration', function()