From d6d03716cf8628de7d9a261e1caeb5cefeb74774 Mon Sep 17 00:00:00 2001 From: Marcus Caisey Date: Wed, 13 May 2026 17:53:27 +0100 Subject: fix(lsp): show detail in popup when server can't completionItem/resolve Problem: `CompletionItem.detail` is only shown in the info popup if the server supports `completionItem/resolve`. Solution: If the server doesn't support `completionItem/resolve`, prepend the complete item `info` with `CompletionItem.detail` in a fenced codeblock, same as we do when the server supports `completionItem/resolve`. To ensure that completion items are displayed in the same way, regardless of whether the server supports `completionItem/resolve`, i've extracted out the test logic from the `selecting an item triggers completionItem/resolve + (snippet) preview` case so that we can run the same tests against a server which supports `completionItem/resolve` and one which doesn't. Hopefully this should prevent the two behaviours diverging again. --- runtime/lua/vim/lsp/completion.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua index 111405bc05..44de65ca1b 100644 --- a/runtime/lua/vim/lsp/completion.lua +++ b/runtime/lua/vim/lsp/completion.lua @@ -435,12 +435,21 @@ function M._lsp_to_complete_items( hl_group = 'DiagnosticDeprecated' end local kind, kind_hlgroup = generate_kind(item) + local info = get_doc(item) + if item.detail and item.detail ~= '' then + if info == '' then + info = ('```%s\n%s\n```'):format(vim.bo.filetype, item.detail) + elseif not info:find(item.detail, 1, true) then + local detail_block = ('```%s\n%s\n```'):format(vim.bo.filetype, item.detail) + info = detail_block .. '\n' .. info + end + end local completion_item = { word = word, abbr = ('%s%s'):format(item.label, vim.tbl_get(item, 'labelDetails', 'detail') or ''), kind = kind, menu = vim.tbl_get(item, 'labelDetails', 'description') or '', - info = get_doc(item), + info = info, icase = 1, dup = 1, empty = 1, @@ -800,7 +809,8 @@ local function on_completechanged(group, bufnr) return end local data = vim.fn.complete_info({ 'selected' }) - if (completed_item.info or '') ~= '' then + local info = completed_item.info or '' + if info ~= '' then local kind = vim.tbl_get(lsp_item, 'documentation', 'kind') update_popup_window( data.preview_winid, @@ -818,6 +828,7 @@ local function on_completechanged(group, bufnr) then if has_completeopt('popup') + and info == '' and lsp_item.insertTextFormat == protocol.InsertTextFormat.Snippet then -- Shows snippet preview in doc popup if completeopt=popup. -- cgit