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

Jumps for argument snippet placeholders beyond the second not working. #157

Closed oblitum closed 5 years ago

oblitum commented 5 years ago

Describe the bug I'm using ccls for LSP C++ server and it's working reasonably well with coc (though ncm2 + LanguageClient-neovim is still faster on refreshing results, and providing better ones). There's a problem with snippet expansion for arguments in coc. For this code:

struct S {
    int foo(int x, int y);
    int foo(int a, int b, int c);
};

int main()  {
    S s;
    s.
}

It expands the member functions correctly, but when I choose the second overload and enter its snippet, the cursor goes to the first argument, I fill a value, I then can jump correctly with <c-j> to the second, I fill another value, but when I press <c-j> again to go to the third argument it doesn't work, and if I press again it just breaks the line like pressing enter (which is the default for <c-j>).

Simply jumping, without filling anything, works for jumping over all placeholders without problems.

Expected behavior That <c-j> keeps jumping placeholders correctly.

chemzqm commented 5 years ago

though ncm2 + LanguageClient-neovim is still faster on refreshing results, and providing better ones

You have that experience simply because ncm2 and deoplete doesn't have support for filter complete item on TextChangedP, it's filtered by vim use strict match. Coc does smart case and fuzzy filter if needed on TextChangedP to provide correct results so there could be complete popup redraw. Coc would always be faster on increment filter since it does filter on input change but the others trigger another completion.

oblitum commented 5 years ago

OK (though the subject is not relevant to this issue, maybe it needs one of its own), I've found completion for stuff after std:: for C++ (when there's an #include <iostream> in the source for example) to be very imprecise and slower with coc than the others. That possibly happens because std:: is a namespace with many results inside, and coc may not be prepared for that yet.

chemzqm commented 5 years ago

I've found completion for stuff after std:: for C++ (when there's an #include in the source for example) to be very imprecise and slower with coc than the others.

Using same language server?

oblitum commented 5 years ago

@chemzqm yes, I'm using ccls. A simple example is to try to complete std::cout with a simple C++ source, just with an #include <iostream> and a main function. coc actually simple doesn't even is able to suggest cout, while others can.

chemzqm commented 5 years ago

I've tried with clangd, it's fast and give std::cout as expected

screen shot 2018-11-11 at 3 23 40 pm
chemzqm commented 5 years ago

The slow could be caused by other source, checkout https://github.com/neoclide/coc.nvim/wiki/F.A.Q#how-to-get-log-of-cocnvim to get the log, use debug mode to get the log for each completion source.

oblitum commented 5 years ago

This image set demonstrates what I get comparing coc and ncm2+LanguageClient: https://imgur.com/a/D5gixNi. The first two images is the result from coc, the last three from ncm2+LanguageClient.

oblitum commented 5 years ago

The slow could be caused by other source, checkout https://github.com/neoclide/coc.nvim/wiki/F.A.Q#how-to-get-log-of-cocnvim to get the log, use debug mode to get the log for each completion source.

OK. I'll dig it, just not at the moment.

chemzqm commented 5 years ago

I've got the reason, I should improve the logic for ignoring sortText field, you have to type 3 character to make strict match items comes first for now.

oblitum commented 5 years ago

@chemzqm ok, but that may not be the sole problem in my case, even if I type std::cout entirely, cout doesn't come up, what's weird though, is that the members of std::cout. show up fine (like shown in the images).

oblitum commented 5 years ago

I can make it show up by forcing a coc-refresh after typing std::cou, then typing something and erasing, then std::cout shows up.

chemzqm commented 5 years ago

even if I type std::cout entirely, it doesn't come up. It's possible the language server is slow at accept text change, add

"coc.preferences.triggerCompletionWait": 100,

may solve that problem.

chemzqm commented 5 years ago

I've improved the sort of completion result, you can get it by std::co now.

oblitum commented 5 years ago

It improves the speed a lot, but doesn't fix it not showing up, I need to check the debugging still.

oblitum commented 5 years ago

I've improved the sort of completion result, you can get it by std::co now.

OK, will update.

chemzqm commented 5 years ago

Which clangd version are you using? I can't have snippet using LLVM version 6.0.1.

oblitum commented 5 years ago

@chemzqm the one from ArchLinux repository is 7.0.0, it's the one I have, I'm trying both clangd and ccls. I've just tried with clangd with log=debug and checked the log file on /tmp, there's no useful information in it:

2018-11-11T05:52:40.644 DEBUG (pid:15052) [services] - starting service: clangd
2018-11-11T05:52:40.645 INFO (pid:15052) [services] - clangd state change: stopped => starting
2018-11-11T05:52:40.646 DEBUG (pid:15052) [workspace] - buffer created 1
2018-11-11T05:52:40.647 DEBUG (pid:15052) [languages] - created service source snippets
2018-11-11T05:52:40.647 DEBUG (pid:15052) [events] - Autocmd: BufEnter [ 1 ]
2018-11-11T05:52:40.687 INFO (pid:15052) [services] - clangd state change: starting => running
2018-11-11T05:52:40.688 DEBUG (pid:15052) [languages] - created service source languageserver.clangd
2018-11-11T05:52:40.692 DEBUG (pid:15052) [sources] - Created sources around,dictionary,buffer,emoji,file,include,tag,gocode,word,omni,snippets,languageserver.clangd,languageclient,neco,neosnippet,ultisnips
2018-11-11T05:52:40.698 DEBUG (pid:15052) [events] - Autocmd: BufWinEnter [ 1, 1000 ]
2018-11-11T05:52:40.701 INFO (pid:15052) [plugin] - coc initialized
2018-11-11T05:52:41.236 DEBUG (pid:15052) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T05:52:42.716 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.018 DEBUG (pid:15052) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T05:52:43.377 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.416 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.457 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.497 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.536 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.577 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.617 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:43.918 DEBUG (pid:15052) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T05:52:44.150 DEBUG (pid:15052) [events] - Autocmd: InsertEnter []
2018-11-11T05:52:44.152 DEBUG (pid:15052) [events] - Autocmd: CursorMovedI []
2018-11-11T05:52:44.292 DEBUG (pid:15052) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T05:52:44.822 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ 's' ]
2018-11-11T05:52:44.825 DEBUG (pid:15052) [events] - Autocmd: CursorMovedI []
2018-11-11T05:52:44.826 DEBUG (pid:15052) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T05:52:44.833 DEBUG (pid:15052) [model-complete] - Complete 'ultisnips' takes 3ms
2018-11-11T05:52:44.942 DEBUG (pid:15052) [model-complete] - Complete 'languageserver.clangd' takes 113ms
2018-11-11T05:52:44.942 INFO (pid:15052) [model-complete] - Results from: languageserver.clangd,ultisnips
2018-11-11T05:52:44.947 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:45.038 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ 't' ]
2018-11-11T05:52:45.046 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:45.049 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:45.302 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ 'd' ]
2018-11-11T05:52:45.314 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:45.320 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:45.828 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:45.830 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ ':' ]
2018-11-11T05:52:45.833 DEBUG (pid:15052) [events] - Autocmd: CursorMovedI []
2018-11-11T05:52:45.835 DEBUG (pid:15052) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T05:52:45.948 DEBUG (pid:15052) [model-complete] - Complete 'languageserver.clangd' takes 112ms
2018-11-11T05:52:45.948 INFO (pid:15052) [model-complete] - Results from: languageserver.clangd
2018-11-11T05:52:45.951 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:46.036 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:46.039 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ ':' ]
2018-11-11T05:52:46.046 DEBUG (pid:15052) [events] - Autocmd: CursorMovedI []
2018-11-11T05:52:46.054 DEBUG (pid:15052) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T05:52:46.172 DEBUG (pid:15052) [model-complete] - Complete 'languageserver.clangd' takes 116ms
2018-11-11T05:52:46.172 INFO (pid:15052) [model-complete] - Results from: languageserver.clangd
2018-11-11T05:52:46.178 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:46.473 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ 'c' ]
2018-11-11T05:52:46.475 DEBUG (pid:15052) [events] - Autocmd: CursorMovedI []
2018-11-11T05:52:46.476 DEBUG (pid:15052) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T05:52:46.477 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:46.480 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:47.135 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ 'o' ]
2018-11-11T05:52:47.139 DEBUG (pid:15052) [events] - Autocmd: CursorMovedI []
2018-11-11T05:52:47.141 DEBUG (pid:15052) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T05:52:47.142 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:47.143 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:48.087 DEBUG (pid:15052) [events] - Autocmd: InsertCharPre [ 'u' ]
2018-11-11T05:52:48.092 DEBUG (pid:15052) [events] - Autocmd: CursorMovedI []
2018-11-11T05:52:48.101 DEBUG (pid:15052) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T05:52:48.105 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:48.106 DEBUG (pid:15052) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T05:52:49.997 DEBUG (pid:15052) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T05:52:49.998 DEBUG (pid:15052) [events] - Autocmd: InsertLeave []
2018-11-11T05:52:50.001 DEBUG (pid:15052) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T05:52:50.952 DEBUG (pid:15052) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T05:52:53.889 DEBUG (pid:15052) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T05:52:57.485 DEBUG (pid:15052) [events] - Autocmd: BufUnload [ 1 ]
2018-11-11T05:52:57.489 DEBUG (pid:15052) [workspace] - buffer unload 1
chemzqm commented 5 years ago

There is:

2018-11-11T05:52:44.833 DEBUG (pid:15052) [model-complete] - Complete 'ultisnips' takes 3ms
2018-11-11T05:52:44.942 DEBUG (pid:15052) [model-complete] - Complete 'languageserver.clangd' takes 113ms

ultisnips can be slow sometimes, but not this case.

chemzqm commented 5 years ago

I've tried with clangd 7.0.0 and the snippet works well, I can use <c-j> to third argument position, the snippet session could be canceled by enter vim's normal mode, I think that's the case, you can check the log for this.

oblitum commented 5 years ago

Will check, but I just fill values and press <c-j>, I don't enter normal mode myself.

oblitum commented 5 years ago

I've just inserted foo(10, 1<c-j> fails for member int foo(int a, int b, int c):

2018-11-11T06:12:34.180 DEBUG (pid:19142) [services] - starting service: clangd
2018-11-11T06:12:34.181 INFO (pid:19142) [services] - clangd state change: stopped => starting
2018-11-11T06:12:34.182 DEBUG (pid:19142) [workspace] - buffer created 1
2018-11-11T06:12:34.183 DEBUG (pid:19142) [languages] - created service source snippets
2018-11-11T06:12:34.183 DEBUG (pid:19142) [events] - Autocmd: BufEnter [ 1 ]
2018-11-11T06:12:34.224 INFO (pid:19142) [services] - clangd state change: starting => running
2018-11-11T06:12:34.226 DEBUG (pid:19142) [languages] - created service source languageserver.clangd
2018-11-11T06:12:34.230 DEBUG (pid:19142) [sources] - Created sources around,dictionary,buffer,emoji,file,include,tag,gocode,word,omni,snippets,languageserver.clangd,languageclient,neco,neosnippet,ultisnips
2018-11-11T06:12:34.234 DEBUG (pid:19142) [events] - Autocmd: BufWinEnter [ 1, 1000 ]
2018-11-11T06:12:34.237 INFO (pid:19142) [plugin] - coc initialized
2018-11-11T06:12:34.777 DEBUG (pid:19142) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T06:12:35.200 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:35.501 DEBUG (pid:19142) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T06:12:35.861 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:35.899 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:35.940 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:35.980 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:36.021 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:36.248 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:36.456 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:36.757 DEBUG (pid:19142) [events] - Autocmd: CursorHold [ 1 ]
2018-11-11T06:12:37.290 DEBUG (pid:19142) [events] - Autocmd: InsertEnter []
2018-11-11T06:12:37.292 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:37.418 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:39.139 DEBUG (pid:19142) [events] - Autocmd: InsertCharPre [ 's' ]
2018-11-11T06:12:39.141 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:39.146 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:39.153 DEBUG (pid:19142) [model-complete] - Complete 'ultisnips' takes 3ms
2018-11-11T06:12:39.262 DEBUG (pid:19142) [model-complete] - Complete 'languageserver.clangd' takes 113ms
2018-11-11T06:12:39.262 INFO (pid:19142) [model-complete] - Results from: languageserver.clangd,ultisnips
2018-11-11T06:12:39.267 DEBUG (pid:19142) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T06:12:39.624 DEBUG (pid:19142) [events] - Autocmd: CompleteDone [ {} ]
2018-11-11T06:12:39.626 DEBUG (pid:19142) [events] - Autocmd: InsertCharPre [ '.' ]
2018-11-11T06:12:39.632 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:39.633 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:39.742 DEBUG (pid:19142) [model-complete] - Complete 'languageserver.clangd' takes 107ms
2018-11-11T06:12:39.742 INFO (pid:19142) [model-complete] - Results from: languageserver.clangd
2018-11-11T06:12:39.742 DEBUG (pid:19142) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T06:12:40.010 DEBUG (pid:19142) [events] - Autocmd: InsertCharPre [ 'f' ]
2018-11-11T06:12:40.013 DEBUG (pid:19142) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T06:12:43.765 DEBUG (pid:19142) [events] - Autocmd: TextChangedP [ 1 ]
2018-11-11T06:12:44.871 DEBUG (pid:19142) [events] - Autocmd: CompleteDone [ { word: 'foo',
    menu: 'int [LS]',
    user_data: '{"cid":1541923959,"source":"languageserver.clangd"}',
    info: '',
    kind: 'Method',
    abbr: 'foo(int a, int b, int c)~' } ]
2018-11-11T06:12:44.872 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:44.875 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:44.887 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:44.888 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:44.888 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:44.907 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:44.907 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:44.948 DEBUG (pid:19142) [events] - Autocmd: InsertLeave []
2018-11-11T06:12:44.949 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:44.969 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:47.715 DEBUG (pid:19142) [events] - Autocmd: InsertEnter []
2018-11-11T06:12:47.717 DEBUG (pid:19142) [events] - Autocmd: InsertCharPre [ '1' ]
2018-11-11T06:12:47.718 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:47.719 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:47.722 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:47.723 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:47.801 DEBUG (pid:19142) [events] - Autocmd: InsertCharPre [ '0' ]
2018-11-11T06:12:47.802 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:47.807 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:47.934 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:47.941 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:50.335 DEBUG (pid:19142) [events] - Autocmd: InsertLeave []
2018-11-11T06:12:50.336 DEBUG (pid:19142) [events] - Autocmd: InsertEnter []
2018-11-11T06:12:50.377 DEBUG (pid:19142) [events] - Autocmd: InsertLeave []
2018-11-11T06:12:50.380 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:50.381 DEBUG (pid:19142) [snippets-manager] - [SnippetManager::cancel]
2018-11-11T06:12:50.398 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:12:51.981 DEBUG (pid:19142) [events] - Autocmd: InsertEnter []
2018-11-11T06:12:51.983 DEBUG (pid:19142) [events] - Autocmd: InsertCharPre [ '1' ]
2018-11-11T06:12:51.984 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:51.985 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:53.535 DEBUG (pid:19142) [events] - Autocmd: CursorMovedI []
2018-11-11T06:12:53.537 DEBUG (pid:19142) [events] - Autocmd: TextChangedI [ 1 ]
2018-11-11T06:12:58.482 DEBUG (pid:19142) [events] - Autocmd: InsertLeave []
2018-11-11T06:12:58.483 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]
2018-11-11T06:13:00.752 DEBUG (pid:19142) [events] - Autocmd: BufUnload [ 1 ]
2018-11-11T06:13:00.756 DEBUG (pid:19142) [workspace] - buffer unload 1
chemzqm commented 5 years ago

There is

2018-11-11T06:12:50.377 DEBUG (pid:19142) [events] - Autocmd: InsertLeave []
2018-11-11T06:12:50.380 DEBUG (pid:19142) [events] - Autocmd: CursorMoved [ 1 ]

so the snippet session canceled.

chemzqm commented 5 years ago

I've improved the logic for snippet cancel, it would not canceled on InsertLeave but could be canceled by type <esc> on normal mode which should resolve this issue.

oblitum commented 5 years ago

@chemzqm thanks, it's fixed now.

oblitum commented 5 years ago

(but problem with std::cout completion still remains, I dunno what's the cause...)

chemzqm commented 5 years ago

I can reproduce the problem now, it's wired.

chemzqm commented 5 years ago

It's fixed, coc added support of inComplete complete result.

oblitum commented 5 years ago

@chemzqm great, just tried and it's working as expected :)