Alternative to `source[n].max_item_count`
Description
This issue is to track alternatives to the source[n].max_item_count functionality.
This functionality was removed in commits https://github.com/hrsh7th/nvim-cmp/commit/abb5c7519d40314240effc70d781149c0f097af3 and https://github.com/hrsh7th/nvim-cmp/commit/8a3d2dd7641f75c1b6291311f56454adba79a196, as announced in the breaking changes issue:
This is minor breaking change. The
source[n].max_item_countis now removed.Now
performance.max_view_entriescan be used for performance.
From comment by @ambroisie on commit https://github.com/hrsh7th/nvim-cmp/commit/8a3d2dd7641f75c1b6291311f56454adba79a196:
I use(d) this option to limit the number of suggestions from e.g: the buffer source, as they might not be as relevant as other sources.
Is there a way to keep this behaviour, without limiting the number of suggestions of all sources?
From comment by @hrsh7th on commit https://github.com/hrsh7th/nvim-cmp/commit/8a3d2dd7641f75c1b6291311f56454adba79a196:
Please create issue. I can't track this.
The source layer max_item_count does not work collectly (sorting) but I understand how to useful that the option.
I'll re-add it later. or welcome PR.
Example usage:
Personally, I use this feature to ensure that no single source will overwhelm the list of completions and crowd out other sources.
sources = cmp.config.sources({
{name = "nvim_lsp"},
{ name = "buffer",
max_item_count = 15}, -- make sure completions from buffer don't overwhelm other sources
{name = "other_source"},
...
- [X] I have checked the FAQ and it didn't resolve my problem.
- [X] I have checked Breaking change announcement.
EDIT:
The last commit that supported the source[n].max_item_count feature is https://github.com/hrsh7th/nvim-cmp/commit/950d0e3a93ba61c13b031c086d11eacf4bd48d24.
You can install nvim-cmp from this commit to keep using the feature.
With Lazy.nvim:
{
"hrsh7th/nvim-cmp",
commit = "950d0e3a93ba61c13b031c086d11eacf4bd48d24",
}
With Packer.nvim:
use {
"hrsh7th/nvim-cmp",
commit = "950d0e3a93ba61c13b031c086d11eacf4bd48d24",
}
With vim-plug:
Plug 'hrsh7th/nvim-cmp', { 'commit': '950d0e3a93ba61c13b031c086d11eacf4bd48d24' }
I personally use max_item_count to limit the amount of matches in the command line-related sources, since I did not want them to cover up the buffer too much.
After the breaking change, I found this workaround as alternative solution to the problem:
-- show 15 items in editor but only 7 in cmdline to prevent obsfucating view
autocmd({ "CmdlineLeave", "VimEnter" }, {
callback = function() opt.pumheight = 15 end,
})
autocmd("CmdlineEnter", {
callback = function() opt.pumheight = 7 end,
})
Same here I use it to limit the number of snippets not only for performance.
sources = {
{ name = "luasnip", max_item_count = 3, group_index = 1 },
{ name = "nvim_lsp", group_index = 1 },
{ name = "treesitter", group_index = 2 },
{ name = "path", group_index = 2 },
{ name = "buffer", group_index = 2, keyword_length = 5 },
-- { name = "spell", group_index = 2 },
{ name = "emoji", group_index = 2 },
{ name = "calc", group_index = 2 },
}
I loved this feature so much, I scraped my whole setup trying to see why It didn't work anymore, is there any plan to bring it back?
@tonyjara see my edit to the original post. You can install nvim-cmp from commit https://github.com/hrsh7th/nvim-cmp/commit/950d0e3a93ba61c13b031c086d11eacf4bd48d24 to keep using the max_item_count feature.
@chrisgrieser you can use the below instead now:
config.performance.max_view_entries*
performance.max_view_entries~
`number`
Maximum number of items to show in the entries list.
@folke Oh, that is indeed a nice and cleaner solution. Thank you for sharing
I'd like to point out that performance.max_view_entries has been mentioned both in the breaking change announcement and in the issue body. This issue is meant for the use cases that are supported only by source[n].max_item_count and not covered by performance.max_view_entries.
@chrisgrieser you can use the below instead now:
config.performance.max_view_entries* performance.max_view_entries~ `number` Maximum number of items to show in the entries list.
But that limits the results for the entire list, right? It doesn't support limiting the number of items for a specific source (e.g., I want to limit luasnip to show max 3 suggestions)
I restored the max_item_count.
I restored the max_item_count.
Awesome, I think the breaking-change comment should be changed/updated then or a new one added to cancel it?