mirror of
https://github.com/neovim/neovim.git
synced 2026-11-03 12:49:53 -06:00
fix(lsp): respect documentation markup kind in completion preview #38338
Problem: Completion preview always assumes plain text, ignoring LSP documentation "kind". Solution: Pass markup kind from completion item to info window, or fallback to PlainText.
This commit is contained in:
1 parent
5773f0e994
commit
0da9827673
2 files changed
+20
-2
No files matched your search
@@ -267,7 +267,10 @@ local function get_doc(item)
|
|||||||
then
|
then
|
||||||
-- Shows snippet preview in doc popup if completeopt=popup.
|
-- Shows snippet preview in doc popup if completeopt=popup.
|
||||||
local text = parse_snippet(item.insertText or item.textEdit.newText)
|
local text = parse_snippet(item.insertText or item.textEdit.newText)
|
||||||
return ('```%s\n%s\n```'):format(vim.bo.filetype, text)
|
item.documentation = {
|
||||||
|
kind = lsp.protocol.MarkupKind.Markdown,
|
||||||
|
value = ('```%s\n%s\n```'):format(vim.bo.filetype, text),
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local doc = item.documentation
|
local doc = item.documentation
|
||||||
@@ -778,7 +781,20 @@ local function on_completechanged(group, bufnr)
|
|||||||
local completed_item = vim.v.event.completed_item or {}
|
local completed_item = vim.v.event.completed_item or {}
|
||||||
if (completed_item.info or '') ~= '' then
|
if (completed_item.info or '') ~= '' then
|
||||||
local data = vim.fn.complete_info({ 'selected' })
|
local data = vim.fn.complete_info({ 'selected' })
|
||||||
update_popup_window(data.preview_winid, data.preview_bufnr)
|
local kind = vim.tbl_get(
|
||||||
|
completed_item,
|
||||||
|
'user_data',
|
||||||
|
'nvim',
|
||||||
|
'lsp',
|
||||||
|
'completion_item',
|
||||||
|
'documentation',
|
||||||
|
'kind'
|
||||||
|
)
|
||||||
|
update_popup_window(
|
||||||
|
data.preview_winid,
|
||||||
|
data.preview_bufnr,
|
||||||
|
kind or lsp.protocol.MarkupKind.PlainText
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -780,8 +780,10 @@ describe('vim.lsp.completion: item conversion', function()
|
|||||||
local result = complete('|', completion_list)
|
local result = complete('|', completion_list)
|
||||||
eq('for .. ipairs', result.items[1].word)
|
eq('for .. ipairs', result.items[1].word)
|
||||||
eq('```lua\nfor index, value in ipairs(t) do\n\t\nend\n```', result.items[1].info)
|
eq('```lua\nfor index, value in ipairs(t) do\n\t\nend\n```', result.items[1].info)
|
||||||
|
eq('markdown', result.items[1].user_data.nvim.lsp.completion_item.documentation.kind)
|
||||||
eq('for .. ipairs 2', result.items[2].word)
|
eq('for .. ipairs 2', result.items[2].word)
|
||||||
eq('```lua\nfor i, v in ipairs(t) do\n\t\nend\n```', result.items[2].info)
|
eq('```lua\nfor i, v in ipairs(t) do\n\t\nend\n```', result.items[2].info)
|
||||||
|
eq('markdown', result.items[2].user_data.nvim.lsp.completion_item.documentation.kind)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user