nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

Alternative to `source[n].max_item_count`

Open Jasha10 opened this issue 3 years ago • 10 comments

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_count is now removed.

Now performance.max_view_entries can 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"},
    ...

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' }

Jasha10 avatar May 26 '23 22:05 Jasha10

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,
})

chrisgrieser avatar May 29 '23 14:05 chrisgrieser

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 },
		}

iabdelkareem avatar Jun 07 '23 08:06 iabdelkareem

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 avatar Jun 08 '23 21:06 tonyjara

@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.

Jasha10 avatar Jun 09 '23 03:06 Jasha10

@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 avatar Jun 09 '23 10:06 folke

@folke Oh, that is indeed a nice and cleaner solution. Thank you for sharing

chrisgrieser avatar Jun 09 '23 11:06 chrisgrieser

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.

ouuan avatar Jun 09 '23 11:06 ouuan

@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)

iabdelkareem avatar Jun 09 '23 12:06 iabdelkareem

I restored the max_item_count.

hrsh7th avatar Jun 09 '23 12:06 hrsh7th

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?

bew avatar Sep 17 '23 21:09 bew