Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/content/docs/recipes/cmp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,33 @@ return { -- override nvim-cmp plugin
end,
}
```

### Limit Label and Menu Item Length

To limit the label and menu item length and prevent the documentation window from getting too small, you can use the following configuration:

```lua title="lua/plugins/cmp.lua"
return {
"hrsh7th/nvim-cmp",
opts = function(_, opts)
local astrocore, astroui = require "astrocore", require "astroui"
local function truncate(str, len)
if not str then return end
local truncated = vim.fn.strcharpart(str, 0, len)
return truncated == str and str or truncated .. astroui.get_icon "Ellipsis"
end

if not opts.formatting then opts.formatting = {} end
opts.formatting.format = astrocore.patch_func(opts.formatting.format, function(format, ...)
-- get item from original formatting function
local vim_item = format(...)

-- truncate text fields to maximum of 25% of the window
vim_item.abbr = truncate(vim_item.abbr, math.floor(0.25 * vim.o.columns))
vim_item.menu = truncate(vim_item.menu, math.floor(0.25 * vim.o.columns))

return vim_item
end)
end,
}
```