Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add section to adjust cmp label and menu length #165

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions src/content/docs/recipes/cmp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,32 @@ 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
local menu = vim_item.menu or ""
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
azdanov marked this conversation as resolved.
Show resolved Hide resolved

return vim_item
end)
end,
}
azdanov marked this conversation as resolved.
Show resolved Hide resolved