Out of box, this plugin reconsturct completion_item and applies Treesitter highlight queries to produce richly colorized completion items with variable-size highlight ranges, somehow similar to lspkind.nvim.
Highly beta.
run nvim -u ~/.config/nvim/repro.lua ~/.config/nvim/repro.lua
as a minimal reproduce template
see repro.lua
Has built-in supports for rust-analyzer(rust), gopls(go), typescript-language-server/vtsls, lua-ls, clangd(C/CPP), intelephense(php), zls(zig), roslyn(C#), for any other language, default to directly apply treesitter highlight to label (feel free to open feature request for more languages).
Currently supports nvim-cmp and blink.cmp.
With lazy.nvim:
return {
"xzbdmw/colorful-menu.nvim",
config = function()
-- You don't need to set these options.
require("colorful-menu").setup({
ls = {
lua_ls = {
-- Maybe you want to dim arguments a bit.
arguments_hl = "@comment",
},
gopls = {
-- When true, label for field and variable will format like "foo: Foo"
-- instead of go's original syntax "foo Foo".
add_colon_before_type = false,
},
["typescript-language-server"] = {
extra_info_hl = "@comment",
},
["typescript-tools"] = {
extra_info_hl = "@comment",
},
ts_ls = {
extra_info_hl = "@comment",
},
tsserver = {
extra_info_hl = "@comment",
},
vtsls = {
extra_info_hl = "@comment",
},
["rust-analyzer"] = {
-- Such as (as Iterator), (use std::io).
extra_info_hl = "@comment",
},
clangd = {
-- Such as "From <stdio.h>".
extra_info_hl = "@comment",
},
roslyn = {
extra_info_hl = "@comment",
},
-- If true, try to highlight "not supported" languages.
fallback = true,
},
-- If the built-in logic fails to find a suitable highlight group,
-- this highlight is applied to the label.
fallback_highlight = "@variable",
-- If provided, the plugin truncates the final displayed text to
-- this width (measured in display cells). Any highlights that extend
-- beyond the truncation point are ignored. Default 60.
max_width = 60,
})
end,
}
formatting = {
format = function(entry, vim_item)
local highlights_info = require("colorful-menu").cmp_highlights(entry)
-- if highlight_info==nil, which means missing ts parser, let's fallback to use default `vim_item.abbr`.
-- What this plugin offers is two fields: `vim_item.abbr_hl_group` and `vim_item.abbr`.
if highlights_info ~= nil then
vim_item.abbr_hl_group = highlights_info.highlights
vim_item.abbr = highlights_info.text
end
return vim_item
end,
}
config = function()
require("blink.cmp").setup({
completion = {
menu = {
draw = {
-- We don't need label_description now because label and label_description are already
-- conbined together in label by colorful-menu.nvim.
columns = { { "kind_icon" }, { "label", gap = 1 } },
components = {
label = {
text = require("colorful-menu").blink_components_text,
highlight = require("colorful-menu").blink_components_highlight,
},
},
},
},
},
})
end
If you want to customize a bit more in those options, here is a more granular control approach:
Click to see
config = function()
require("blink.cmp").setup({
completion = {
menu = {
draw = {
-- We don't need label_description now because label and label_description are already
-- conbined together in label by colorful-menu.nvim.
columns = { { "kind_icon" }, { "label", gap = 1 } },
components = {
label = {
width = { fill = true, max = 60 },
text = function(ctx)
local highlights_info = require("colorful-menu").blink_highlights(ctx)
if highlights_info ~= nil then
-- Or you want to add more item to label
return highlights_info.label
else
return ctx.label
end
end,
highlight = function(ctx)
local highlights = {}
local highlights_info = require("colorful-menu").blink_highlights(ctx)
if highlights_info ~= nil then
highlights = highlights_info.highlights
end
for _, idx in ipairs(ctx.label_matched_indices) do
table.insert(highlights, { idx, idx + 1, group = "BlinkCmpLabelMatch" })
end
-- Do something else
return highlights
end,
},
},
},
},
},
})
end
Note: you may want to set CmpItemAbbrMatch or BlinkCmpLabelMatch to only has bold style (without fg) to have the similar effect as blow images.
Click to see video
https://github.com/user-attachments/assets/725ea273-b598-4947-b189-f642fa51cf9b)](https://github.com/user-attachments/assets/1e5b1587-4374-49c3-88e7-1e8ed37b3210intelephense(PHP) Thanks to @pnx
roslyn(C#) Thanks to @seblj
Feel free to open issues or submit pull requests if you encounter any bugs or have feature requests.
MIT License.
Zed for the initial idea of colorize.
@David van Munster for the pr which make this plugin possible.