Skip to content
Merged
Changes from 2 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
31 changes: 31 additions & 0 deletions src/content/docs/recipes/cmp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,34 @@ 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"
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 label to maximum of 25% of the window
local label = vim_item.abbr
local truncated_label = vim.fn.strcharpart(label, 0, math.floor(0.25 * vim.o.columns))
if truncated_label ~= label then vim_item.abbr = truncated_label .. astroui.get_icon "Ellipsis" end

-- truncate menu to maximum of 25% of the window
if vim_item.menu then
local menu = vim_item.menu
local truncated_menu = vim.fn.strcharpart(menu, 0, math.floor(0.25 * vim.o.columns))
if truncated_menu ~= menu then vim_item.menu = truncated_menu .. astroui.get_icon "Ellipsis" end
end

return vim_item
end)
end,
}