fix(lsp): handle non-string documentation in completion items #38291

Problem: `get_doc` throws error with "attempt to get length of a userdata
value" when `item.documentation` is truthy but not a string (e.g. vim.NIL
from a JSON null).

Solution: Check `type(item.documentation)` before taking its length.
This commit is contained in:
glepnir
2026-03-14 17:20:34 +08:00
committed by GitHub
parent b4e3461e3f
commit 5653b25e9b
2 changed files with 11 additions and 1 deletions

View File

@@ -261,7 +261,7 @@ local function get_doc(item)
if
has_completeopt('popup')
and item.insertTextFormat == protocol.InsertTextFormat.Snippet
and #(item.documentation or '') == 0
and (type(item.documentation) ~= 'string' or #item.documentation == 0)
and vim.bo.filetype ~= ''
and (item.textEdit or (item.insertText and item.insertText ~= ''))
then