mirror of
https://github.com/neovim/neovim.git
synced 2026-05-27 07:18:36 +00:00
fix(lsp): show meaningful error on invalid completion response #39445
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
This commit is contained in:
@@ -1004,7 +1004,13 @@ local function trigger(bufnr, clients, ctx)
|
||||
end
|
||||
|
||||
local result = response.result
|
||||
if result and #(result.items or result) > 0 then
|
||||
if type(result) == 'table' and result.items == vim.NIL then
|
||||
error(
|
||||
('%s: completion response has items=null, expected CompletionItem[]'):format(
|
||||
client and client.name or 'UNKNOWN'
|
||||
)
|
||||
)
|
||||
elseif result and result ~= vim.NIL and #(result.items or result) > 0 then
|
||||
Context.isIncomplete = Context.isIncomplete or result.isIncomplete
|
||||
local encoding = client and client.offset_encoding or 'utf-16'
|
||||
local client_matches, tmp_server_start_boundary
|
||||
|
||||
Reference in New Issue
Block a user