From 1f63735f175d178f37e2fd27b190699486614a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maria=20Jos=C3=A9=20Solano?= Date: Sun, 24 Aug 2025 15:46:08 -0700 Subject: [PATCH] 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. --- runtime/lua/vim/lsp/inlay_hint.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua index 5e940f0098..96004067c6 100644 --- a/runtime/lua/vim/lsp/inlay_hint.lua +++ b/runtime/lua/vim/lsp/inlay_hint.lua @@ -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