Skip to content

Commit f978f0e

Browse files
azdanovmehalter
andauthored
docs: add section to adjust cmp label and menu length (#165)
* feat: add section to adjust cmp label and menu length * chore: modify menu item only if it exists Co-authored-by: Micah Halter <[email protected]> * chore: close code block * refactor: extract truncate logic Co-authored-by: Micah Halter <[email protected]> --------- Co-authored-by: Micah Halter <[email protected]>
1 parent 61e6a00 commit f978f0e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/content/docs/recipes/cmp.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,33 @@ 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+
local function truncate(str, len)
157+
if not str then return end
158+
local truncated = vim.fn.strcharpart(str, 0, len)
159+
return truncated == str and str or truncated .. astroui.get_icon "Ellipsis"
160+
end
161+
162+
if not opts.formatting then opts.formatting = {} end
163+
opts.formatting.format = astrocore.patch_func(opts.formatting.format, function(format, ...)
164+
-- get item from original formatting function
165+
local vim_item = format(...)
166+
167+
-- truncate text fields to maximum of 25% of the window
168+
vim_item.abbr = truncate(vim_item.abbr, math.floor(0.25 * vim.o.columns))
169+
vim_item.menu = truncate(vim_item.menu, math.floor(0.25 * vim.o.columns))
170+
171+
return vim_item
172+
end)
173+
end,
174+
}
175+
```

0 commit comments

Comments
 (0)