Skip to content

Commit 1b3b8d3

Browse files
authored
feat: add section to adjust cmp label and menu length
1 parent 7f15bb4 commit 1b3b8d3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/content/docs/recipes/cmp.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,32 @@ return { -- override nvim-cmp plugin
143143
end,
144144
}
145145
```
146+
147+
### Limit Label and Menu Item Length
148+
149+
To limit the label and menu item length and prevent the documentation window from getting too small, you can use the following configuration:
150+
151+
```lua title="lua/plugins/cmp.lua"
152+
return {
153+
"hrsh7th/nvim-cmp",
154+
opts = function(_, opts)
155+
local astrocore, astroui = require "astrocore", require "astroui"
156+
if not opts.formatting then opts.formatting = {} end
157+
opts.formatting.format = astrocore.patch_func(opts.formatting.format, function(format, ...)
158+
-- get item from original formatting function
159+
local vim_item = format(...)
160+
161+
-- truncate label to maximum of 25% of the window
162+
local label = vim_item.abbr
163+
local truncated_label = vim.fn.strcharpart(label, 0, math.floor(0.25 * vim.o.columns))
164+
if truncated_label ~= label then vim_item.abbr = truncated_label .. astroui.get_icon "Ellipsis" end
165+
166+
-- truncate menu to maximum of 25% of the window
167+
local menu = vim_item.menu or ""
168+
local truncated_menu = vim.fn.strcharpart(menu, 0, math.floor(0.25 * vim.o.columns))
169+
if truncated_menu ~= menu then vim_item.menu = truncated_menu .. astroui.get_icon "Ellipsis" end
170+
171+
return vim_item
172+
end)
173+
end,
174+
}

0 commit comments

Comments
 (0)