neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.33k stars 956 forks source link

Completion suggestion takes a while to appear #4140

Closed marekdedic closed 2 years ago

marekdedic commented 2 years ago

Result from CocInfo

## versions

vim version: NVIM v0.7.2
node version: v18.8.0
coc.nvim version: 0.0.82-a5276d63 2022-09-01 20:10:57 +0800
coc.nvim directory: /home/user/.local/share/nvim/plugged/coc.nvim
term: tmux
platform: linux

## Log of coc.nvim

2022-09-03T17:48:50.686 INFO (pid:213027) [services] - registered service "tsserver"
2022-09-03T17:48:50.690 INFO (pid:213027) [plugin] - coc.nvim initialized with node: v18.8.0 after 119ms
2022-09-03T17:48:50.712 INFO (pid:213027) [services] - service tsserver started
2022-09-03T17:48:52.888 INFO (pid:213027) [attach] - receive notification: showInfo []

Describe the bug

Hi, I have set the mapping as advised in the README:

vim.api.nvim_set_keymap('i', '<CR>', 'coc#pum#visible() ? coc#pum#confirm() : <CR><c-r>=coc#on_enter()<CR>', {silent = true, expr = true})

With this config, upon pressing enter, the cursor jumps to where the end of the suggestion should be, however, the suggestion itself only appears after a while, say a second.

Reproduce the bug

local Plug = vim.fn['plug#']

vim.call('plug#begin', vim.fn.stdpath('data') .. '/plugged')

Plug('neoclide/coc.nvim', {branch = 'release'})
vim.api.nvim_set_keymap('i', '<CR>', 'coc#pum#visible() ? coc#pum#confirm() : <CR><c-r>=coc#on_enter()<CR>', {silent = true, expr = true})

vim.call('plug#end')
chemzqm commented 2 years ago

With this config, upon pressing enter, the cursor jumps to where the end of the suggestion should be, however, the suggestion itself only appears after a while, say a second.

The key-mapping for coc#pum#confirm() should only confirm completion, I don't understand what do you mean by suggestion itself only appears after a while, it should not be trigger without character type by default.

marekdedic commented 2 years ago

Ok, I'll try to describe the process in more detail. I have the completion menu open, I select an item.

  1. Press Enter
  2. The menu disappears
  3. Nothing gets written in the open file/buffer
  4. The cursor gets moved to approximately where the selected item would end
  5. ~1s delay
  6. The actual text of the completion item appears in the file
chemzqm commented 2 years ago

Seem your vim or the node blocked for some reason, checkout: https://github.com/neoclide/coc.nvim/wiki/F.A.Q#how-could-i-profile-vim https://github.com/neoclide/coc.nvim/wiki/F.A.Q#how-to-get-log-of-cocnvim

marekdedic commented 2 years ago

I have tried profiling vim and there is no script that would take long enough to be responsible for the delay. I tried looking into the log, nothing really interesting there - it tells me how long it took to find the completion suggestions - that is not my problem, my issue is when I select one of them...

marekdedic commented 2 years ago

profile.log

chemzqm commented 2 years ago

Maybe you need nowait, checkout your key-mapping by :imap <CR>

marekdedic commented 2 years ago

Adding nowait = true doesn't chage the behaviour :(

chemzqm commented 2 years ago

You can check the trace log: https://github.com/neoclide/coc.nvim/wiki/F.A.Q#how-to-get-log-of-cocnvim

marekdedic commented 2 years ago

And the imap only shows the mapping I defined for CoC

marekdedic commented 2 years ago

I see a weird time jump between lines 115 and 116, is that it? coc-log.log

marekdedic commented 2 years ago

Hmm, I solved the issue incidentally by changing the mapping from

vim.api.nvim_set_keymap('i', '<CR>', 'coc#pum#visible() ? coc#pum#confirm() : <CR><c-r>=coc#on_enter()<CR>', {silent = true, expr = true})

to

vim.api.nvim_set_keymap('i', '<CR>', 'coc#pum#visible() ? coc#pum#confirm() : "<CR><c-r>=coc#on_enter()<CR>"', {silent = true, expr = true})

I don't know why that helped, but it did :shrug: