feat(lsp): show color preview in completion items #32138

Problem: Color completion items display as plain text without visual preview

Solution: Parse RGB/hex colors from documentation and render with colored symbol ■
This commit is contained in:
glepnir
2026-02-28 23:02:52 +08:00
committed by GitHub
parent c1e60f36f3
commit 3e8a4e1092
3 changed files with 64 additions and 1 deletions

View File

@@ -171,6 +171,21 @@ describe('vim.lsp.completion: item conversion', function()
eq(expected, got)
end)
it('generate "■" symbol with highlight group for CompletionItemKind.Color', function()
local completion_list = {
{ label = 'text-red-300', kind = 16, documentation = 'color: rgb(252, 165, 165)' },
}
local result = complete('|', completion_list)
result = vim.tbl_map(function(x)
return {
word = x.word,
kind_hlgroup = x.kind_hlgroup,
kind = x.kind,
}
end, result.items)
eq({ { word = 'text-red-300', kind_hlgroup = '@lsp.color.fca5a5', kind = '' } }, result)
end)
---@param prefix string
---@param items lsp.CompletionItem[]
---@param expected table[]