feat(lsp): support CompletionItem.labelDetails #38403

Problem: CompletionItem.labelDetails is ignored, losing
function signatures and module info in the completion menu.

Solution: Append labelDetails.detail to abbr and use
labelDetails.description for menu with fallback to item.detail.

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemLabelDetails
This commit is contained in:
glepnir
2026-03-22 07:07:26 +08:00
committed by GitHub
parent 2069be281c
commit cc518cf9ba
3 changed files with 18 additions and 2 deletions

View File

@@ -187,6 +187,21 @@ describe('vim.lsp.completion: item conversion', function()
eq({ { word = 'text-red-300', kind_hlgroup = '@lsp.color.fca5a5', kind = '' } }, result)
end)
it('uses labelDetails for abbr and menu', function()
local completion_list = {
{
label = 'printf',
kind = 3,
detail = 'int',
labelDetails = { detail = '(const char *restrict, ...)', description = 'stdio.h' },
},
}
local result = complete('|', completion_list)
local item = result.items[1]
eq('printf(const char *restrict, ...)', item.abbr)
eq('stdio.h', item.menu)
end)
---@param prefix string
---@param items lsp.CompletionItem[]
---@param expected table[]