nvim-lua / completion-nvim

A async completion framework aims to provide completion to neovim's built in LSP written in Lua
Apache License 2.0
973 stars 78 forks source link

Completion popup flicker on every additional letter and on backspace. #237

Open kkharji opened 4 years ago

kkharji commented 4 years ago

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.

bluz71 commented 4 years ago

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.

Shougo commented 4 years ago

@tami5 Your reproduce steps are very fuzzy.

kkharji commented 4 years ago

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

hrsh7th commented 4 years ago

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

Shougo commented 4 years ago

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

haorenW1025 commented 4 years ago

@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 commented 4 years ago

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

kkharji commented 4 years ago

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

hrsh7th commented 4 years ago

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.

haorenW1025 commented 4 years ago

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

kkharji commented 4 years ago

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

bluz71 commented 4 years ago

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.

luathn commented 3 years ago

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