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

The plugin can block Neovim for a long time

Open gregorias opened this issue 2 years ago • 3 comments

This plugin synchronously calls vim.fn.getcompletion. When that happens, the entire Neovim is blocked until that call completes. Unfortunately, that call can take a long time in some circumstances. For example, completing :e huge_nfs_directory/ takes a minute on my machine. I suspect that https://github.com/hrsh7th/cmp-cmdline/issues/84 is another example of this.

There are a few avenues we could take to remedy this:

  • Make the call asynchronous or add a timeout. Unfortunately, I couldn't find a way to do this. https://github.com/neovim/neovim/issues/19742 suggests there's no existing way for it.
  • https://github.com/neovim/neovim/issues/19742 suggests using CTRL-C. Unfortunately, that doesn't work for cmp-cmdline, because CTRL-C clears the entire commandline. That means that I can't finish the command I'm typing. I either have to wait for completion to finish or abandon it entirely.
  • Avoid using vim.fn.getcompletion. I don't know what alternative there is though.

gregorias avatar Mar 25 '23 14:03 gregorias

Hitting this too at the moment, made me think it was an issue with cmp-path: https://github.com/hrsh7th/cmp-path/issues/68

Temporarily working around this by disabling cmp-cmdline on e and edit:

  -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  cmp.setup.cmdline(':', {
    mapping = cmp.mapping.preset.cmdline(),
    sources = cmp.config.sources({
		{ name = 'path' },
		{ name = 'cmdline', option = { ignore_cmds = { 'Man', '!', 'e', 'edit'}}}
	})
  })

liquiddandruff avatar Apr 12 '23 20:04 liquiddandruff

It is possible to get around blocking calls that take a long time. I wrote a autocompletion plugin (https://github.com/girishji/autosuggest.vim) for cmdline-mode completion in vim9script. I solved this problem by adding a timeout to job_start(). There are certain completions that are long running (like ** expansion). I check them first in a separate process. I assume similar mechanism can be used in neovim as well.

girishji avatar Aug 01 '23 08:08 girishji

hitting this too.

I would be happy (enough) with the ability to exclude some paths from cmp-path completion as a work-around (happy to file a feature request under cmp-path if desired)

miekg avatar Feb 07 '24 12:02 miekg