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

Completion popup flicker on every additional letter and on backspace.

Open kkharji opened this issue 5 years ago • 13 comments

My testing minimal init.vim

vim.cmd('set runtimepath+=~/.local/share/nvim/site/pack/packer/start/completion-nvim')
function compnvim.setup() 
  rg.use({ 
    'nvim-lua/completion-nvim', 
    opt = true, 
    exec = compnvim.exec, 
    options = compnvim.options, 
    viml = compnvim.viml, 
    aug = compnvim.aug, })
end

compnvim.exec = function()
  rg.use({'steelsojka/completion-buffers', opt = true })
  rg.use({'kristijanhusak/completion-tags', opt = true })
end

compnvim.aug = { 
  {'BufEnter', '*', [[packadd completion-nvim completion-buffers completion-tags | lua require'completion'.on_attach()]]}, 
}

compnvim.viml = [[
  set completeopt=menuone,noinsert,noselect
  imap <C-space> <Plug>(completion_trigger)
  inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
  inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
  inoremap <expr> <C-j>   pumvisible() ? "\<C-n>" : "\<Tab>"
  inoremap <expr> <C-k> pumvisible() ? "\<C-p>" : "\<S-Tab>"
  " imap <c-n> <Plug>(completion_next_source) "use <c-j> to switch to previous completion
  " imap <c-p> <Plug>(completion_prev_source) "use <c-k> to switch to next completion
  ]]

compnvim.options = {
  completion_enable_auto_popup = 1, 
  completion_word_min_length = 1, -- no effect
  completion_trigger_keyword_length = 1,
  completion_auto_change_source = 1,
  completion_enable_auto_hover = 1,
  completion_enable_auto_paren = 1,
  completion_enable_auto_signature = 1,
  completion_matching_strategy_list = {'exact', 'fuzzy', 'substring'},
  completion_sorting = 'none',
  completion_timer_cycle = 200,
  completion_trigger_on_delete = 1,
  -- completion_trigger_character = {'.', ':'}, breaks completion
  -- completion_enable_snippet = 'ultisnips',
  completion_chain_complete_list = {
    default = {
      default = {
        { complete_items = { 'lsp', 'snippets', 'tags' }},
        { complete_items = { 'buffer' }}
      },
      string = {
        { complete_items = { 'path' }},
        { complete_items = { 'buffer', 'buffers' }}
      },
      comment = {
        { complete_items = { 'path' }},
        { complete_items = { 'buffer', 'buffers' }}
      }
    },
    typescript =  {
      { complete_items = { 'lsp' }},
      { complete_items = { 'ts', 'buffers' }}
    };
    javascript =  {
      { complete_items = { 'lsp' }},
      { complete_items = { 'ts', 'buffers' }}
    };
  },
  completion_customize_lsp_label = {
    Function = ' [function]',
    Method = ' [method]',
    Reference = ' [refrence]',
    Enum = ' [enum]',
    Field = 'ﰠ [field]',
    Keyword = ' [key]',
    Variable = ' [variable]',
    Folder = ' [folder]',
    Snippet = ' [snippet]',
    Operator = ' [operator]',
    Module = ' [module]',
    Text = 'ﮜ[text]',
    Class = ' [class]',
    Interface = ' [interface]'
  },
}

How to reproduce

  1. Install
  2. Open a file
  3. Type a keyword then as you type it flickers/flashes

Expected behavior Completion window doesn't flicker when a letter get typed or get deleted.

kkharji avatar Oct 12 '20 22:10 kkharji

My Neovim setup allows me to easily switch between LSC and Neovim LSP + completion.nvim.

Both setups do roughly the same thing, auto-complete via language servers.

In my tests, Neovim LSP + completion.nvim popup rendering is exactly the same as LSC. I suspect both are populating and using Vim's completion popup.

A recent post over on Reddit discussed this issue, especially with comparison to COC.

If I was speculate, I suspect COC is using a floating window for completions maybe with asynchronous population (I don't know this, just a hunch).

I don't believe completion.nvim is doing anything substantially incorrect, other auto-completion plugins, apart from COC, behave very similarly.

It just may be a limitation of Vim's completion popup system.

bluz71 avatar Oct 13 '20 01:10 bluz71

@tami5 Your reproduce steps are very fuzzy.

Shougo avatar Oct 13 '20 02:10 Shougo

If I was speculate, I suspect COC is using a floating window for completions maybe with asynchronous population (I don't know this, just a hunch). I don't believe completion.nvim is doing anything substantially incorrect, other auto-completion plugins, apart from COC, behave very similarly. It just may be a limitation of Vim's completion popup system.

@bluz71 it makes more sense now to why am having such a different experience compered to using coc. I hope completion-nvim would support floating windows as it offer better experience

kkharji avatar Oct 13 '20 06:10 kkharji

Probably, this issue relates to this https://github.com/nvim-lua/completion-nvim/pull/207

hrsh7th avatar Oct 13 '20 06:10 hrsh7th

I have tested coc.nvim and if I use backspace, completion popup flicker.

Shougo avatar Oct 13 '20 07:10 Shougo

@hrsh7th Hmm so what's wrong with the PR though? If it solve the issue we should probably merge it.

@tami5 I don't think coc uses a floating window for completion since I've read their source code before... and even if it does I'm not planning to implement it. I think that since vim already have a completion mechanism built-in, we should try to stick to it without creating our own completion style. Also you should elaborate more on what is flicker, maybe a gif demonstrate it because I don't really get what you mean.

haorenW1025 avatar Oct 14 '20 17:10 haorenW1025

Ahh also @Shougo Thanks a lot for help testing it:) Really appreciate!

haorenW1025 avatar Oct 14 '20 17:10 haorenW1025

@haorenW1025 I'll try to paste a gif soon. Thanks for taking a look into the issue. Adding #207 workaround fix the issue to a great extent.

kkharji avatar Oct 14 '20 17:10 kkharji

My previous PR was broken when using gopls.

For example, completion-nvim#master does not show any items when the line is fmt.Paaaaaa|. But My version shows Print Printf Println unexpectedly.

hrsh7th avatar Oct 15 '20 08:10 hrsh7th

@tami5 After some investigation, I think I know why the flickering happens. This is because when supporting fuzzy completion we'll have to manually triggered complete instead of let neovim filter the results, which eventually causes the flickering(see https://github.com/neovim/neovim/issues/12620 for more discussion about it). Currently I can only avoid flickering when not using fuzzy complete. Please see if using #249 with setting completion_matching_strategy_list = {'exact'} work for you.

haorenW1025 avatar Oct 20 '20 10:10 haorenW1025

Nice catch @haorenW1025, I was wondering why this isn't a real issue for the completion-nvim, and now I understand that many may not be utilizing fuzzy match. I'm going subscribe to 249, and report there. Thanks

kkharji avatar Oct 20 '20 11:10 kkharji

Well if indeed I had exact matching strategy and I stated above that I saw no difference between LSC and completion.nvim. That explains why I could not see what the original poster saw.

Nice debugging.

bluz71 avatar Oct 20 '20 21:10 bluz71

Because this plugin can not use fuzzy mode, so I use nvim-compe instead. Waiting for a PR fix it.

luathn avatar Mar 31 '21 10:03 luathn