feat(lsp): show snippet preview if completeopt=popup #32553

Problem:
LSP completion does not show snippet preview.

Solution:
Show snippet preview if 'completeopt' includes popup.
This commit is contained in:
glepnir
2026-03-11 02:34:58 +08:00
committed by GitHub
parent fc90585095
commit 145548a24a
2 changed files with 34 additions and 0 deletions

View File

@@ -243,6 +243,18 @@ end
---@param item lsp.CompletionItem
---@return string
local function get_doc(item)
if
vim.o.completeopt:find('popup')
and item.insertTextFormat == protocol.InsertTextFormat.Snippet
and #(item.documentation or '') == 0
and vim.bo.filetype ~= ''
and (item.textEdit or (item.insertText and item.insertText ~= ''))
then
-- Shows snippet preview in doc popup if completeopt=popup.
local text = parse_snippet(item.insertText or item.textEdit.newText)
return ('```%s\n%s\n```'):format(vim.bo.filetype, text)
end
local doc = item.documentation
if not doc then
return ''