Skip to content

Commit 012578b

Browse files
committed
Add plugin colorful-menu.nvim
1 parent 43fa572 commit 012578b

3 files changed

Lines changed: 112 additions & 1 deletion

File tree

lua/config/colorful_menu.lua

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
-- You don't need to set these options.
2+
require("colorful-menu").setup {
3+
ls = {
4+
lua_ls = {
5+
-- Maybe you want to dim arguments a bit.
6+
arguments_hl = "@comment",
7+
},
8+
gopls = {
9+
-- By default, we render variable/function's type in the right most side,
10+
-- to make them not to crowd together with the original label.
11+
12+
-- when true:
13+
-- foo *Foo
14+
-- ast "go/ast"
15+
16+
-- when false:
17+
-- foo *Foo
18+
-- ast "go/ast"
19+
align_type_to_right = true,
20+
-- When true, label for field and variable will format like "foo: Foo"
21+
-- instead of go's original syntax "foo Foo". If align_type_to_right is
22+
-- true, this option has no effect.
23+
add_colon_before_type = false,
24+
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
25+
preserve_type_when_truncate = true,
26+
},
27+
-- for lsp_config or typescript-tools
28+
ts_ls = {
29+
-- false means do not include any extra info,
30+
-- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
31+
extra_info_hl = "@comment",
32+
},
33+
vtsls = {
34+
-- false means do not include any extra info,
35+
-- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
36+
extra_info_hl = "@comment",
37+
},
38+
["rust-analyzer"] = {
39+
-- Such as (as Iterator), (use std::io).
40+
extra_info_hl = "@comment",
41+
-- Similar to the same setting of gopls.
42+
align_type_to_right = true,
43+
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
44+
preserve_type_when_truncate = true,
45+
},
46+
clangd = {
47+
-- Such as "From <stdio.h>".
48+
extra_info_hl = "@comment",
49+
-- Similar to the same setting of gopls.
50+
align_type_to_right = true,
51+
-- the hl group of leading dot of "•std::filesystem::permissions(..)"
52+
import_dot_hl = "@comment",
53+
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
54+
preserve_type_when_truncate = true,
55+
},
56+
zls = {
57+
-- Similar to the same setting of gopls.
58+
align_type_to_right = true,
59+
},
60+
roslyn = {
61+
extra_info_hl = "@comment",
62+
},
63+
dartls = {
64+
extra_info_hl = "@comment",
65+
},
66+
-- The same applies to pyright/pylance
67+
basedpyright = {
68+
-- It is usually import path such as "os"
69+
extra_info_hl = "@comment",
70+
},
71+
pylsp = {
72+
extra_info_hl = "@comment",
73+
-- Dim the function argument area, which is the main
74+
-- difference with pyright.
75+
arguments_hl = "@comment",
76+
},
77+
-- If true, try to highlight "not supported" languages.
78+
fallback = true,
79+
-- this will be applied to label description for unsupport languages
80+
fallback_extra_info_hl = "@comment",
81+
},
82+
-- If the built-in logic fails to find a suitable highlight group for a label,
83+
-- this highlight is applied to the label.
84+
fallback_highlight = "@variable",
85+
-- If provided, the plugin truncates the final displayed text to
86+
-- this width (measured in display cells). Any highlights that extend
87+
-- beyond the truncation point are ignored. When set to a float
88+
-- between 0 and 1, it'll be treated as percentage of the width of
89+
-- the window: math.floor(max_width * vim.api.nvim_win_get_width(0))
90+
-- Default 60.
91+
max_width = 60,
92+
}

lua/config/nvim-cmp.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require("cmp_nvim_ultisnips")
1010
require("cmp_cmdline")
1111

1212
local MiniIcons = require("mini.icons")
13+
local colorful_menu = require("colorful-menu")
1314

1415
cmp.setup {
1516
snippet = {
@@ -54,10 +55,22 @@ cmp.setup {
5455
},
5556
-- solution taken from https://github.com/echasnovski/mini.nvim/issues/1007#issuecomment-2258929830
5657
formatting = {
57-
format = function(_, vim_item)
58+
format = function(entry, vim_item)
59+
-- Add icon to the kind of completion items
5860
local icon, hl = MiniIcons.get("lsp", vim_item.kind)
5961
vim_item.kind = icon .. " " .. vim_item.kind
6062
vim_item.kind_hl_group = hl
63+
64+
local highlights_info = colorful_menu.cmp_highlights(entry)
65+
66+
-- highlight_info is nil means we are missing the ts parser, it's
67+
-- better to fallback to use default `vim_item.abbr`. What this plugin
68+
-- offers is two fields: `vim_item.abbr_hl_group` and `vim_item.abbr`.
69+
if highlights_info ~= nil then
70+
vim_item.abbr_hl_group = highlights_info.highlights
71+
vim_item.abbr = highlights_info.text
72+
end
73+
6174
return vim_item
6275
end,
6376
},

lua/plugin_specs.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ local plugin_specs = {
807807
require("config.nvim-lint")
808808
end,
809809
},
810+
{
811+
"xzbdmw/colorful-menu.nvim",
812+
config = function()
813+
require("config.colorful_menu")
814+
end,
815+
},
810816
}
811817

812818
require("lazy").setup {

0 commit comments

Comments
 (0)