fix(lsp): treat nil inlay hint result as empty array (#35458)

`gopls` seems to send a nil result when there are no inlay hints for the
buffer. [The protocol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint)
allows for the server to send an array or nil, and it isn't clear what
nil should represent. I think it's reasonable to treat it as an empty
array though.
This commit is contained in:
Maria José Solano
2025-08-24 15:46:08 -07:00
committed by GitHub
parent 6018aed92f
commit 1f63735f17

View File

@@ -44,9 +44,9 @@ function M.on_inlayhint(err, result, ctx)
return
end
local bufnr = assert(ctx.bufnr)
if
util.buf_versions[bufnr] ~= ctx.version
or not result
or not api.nvim_buf_is_loaded(bufnr)
or not bufstates[bufnr].enabled
then
@@ -61,6 +61,9 @@ function M.on_inlayhint(err, result, ctx)
local client_hints = bufstate.client_hints
local client = assert(vim.lsp.get_client_by_id(client_id))
-- If there's no error but the result is nil, clear existing hints.
result = result or {}
local new_lnum_hints = vim.defaulttable()
local num_unprocessed = #result
if num_unprocessed == 0 then