-
-
Notifications
You must be signed in to change notification settings - Fork 959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested snippet expansion breaks initial snippet placeholder navigation #156
Comments
The language server could provide an option to disable snippet feature, but I don't know if there's such option for clangd. There is signature help support with coc, you can use something like:
|
The issue is not the server providing the parameter information but how the client is doing it in the user interface. The problem I've mentioned is solely related to client implementation, which in this case is coc. |
Thanks for this info. |
It's not additionalTextEdit actually, it's snippet returned from language server, coc just expand the snippet on completion confirm. |
You can't disable snippet feature of coc, language server like coc-json requires snippet to work. |
Changed title, I may have used the wrong term.
In the list of links I've provided at the issue, some of them do that. Clang provides per parameter info and prototypes after
That's sad, I can use LanguageClient-neovim ( |
As I've said, that would break other language server from working, clangd should provide the option to disable snippet or not provide params in label of complete items, they should be exists in The signatureHelp could be improved, trigger character is not respected for now, it's a bug. Another solution is create a coc extension with completion middlewire to fix this issue with clangd, the hack of get function name from label would possibly break other language server used by coc. |
OK, I didn't verify the source code and implementation of clangd yet to see whether it's providing full prototype where should just be the function name. It's weird though because other LSP completers are working fine at providing just a function name for the insertion text. I've tried with ncm2 both vim-lsp and LanguageClient-neovim, using clangd and ccls, which is another server. Currently I'm not even using clangd, I'm using ccls, but the problem, when using coc, still remains. |
They just spilt the label to get the part of function name, coc not doing that since coc does completion resolve on select change of completion item and it requires the word of vim completion item to be unique (until vim could emit selected complete item on completion item change). If I do the split, |
I've changed the title to point to the actual issue. If it can be fixed while still having snippets, then OK. |
It's possible to improve nested snippet, but would require some time, should be easier if you can use an option from clangd to disable snippet https://reviews.llvm.org/D51214?id=162370. |
Nice, and thanks for pointing that issue. Sadly ccls should then be suffering from same problem maybe?... |
I'm a long time YouCompleteMe user but I'm looking for options now, hence I'm trying these several new ones, but I'm doing my tests just with a minimal setup just to give the completion plugins a try. That's the reason I've picked just one language for now, c++, and I'm trying with both clangd and ccls. I've hit this issue with them and I'm assuming you're right about it involving server implementation, so I'm expecting that for other languages I won't experience the same issue of the title? Or that at least the issue can be avoided somehow, full prototype not being inserted for other languages being one behavior that would solve it. |
You may or may not, there's no guarantee. Different language server could have different problems when working with vim, and that's why coc support extensions which could use middleware to fix those problems. |
Oh well, OK... I suspect I'll hit this for all languages and few will have servers where I can disable this, and it's a bad route in any way because I would then need to do it (configuration) server per server. |
You don't need to disable snippet as long as the function params not exists in label, which should be in detail field as tsserver. Or wait for vim/neovim support emit selected completion item, then we can do split for function name. |
OK. So I'm understanding that it's also a problem due to how coc has its completion resolve dependent upon the (neo)vim limitations on item selection. Due to how (neo)vim is contrived on information on "item emit", I'd rely the design and uniqueness of items on another data and event rather than selection and completion-item But, anyway, that just an opinion. |
There's no event for completion item select in vim/neovim, so coc have to rely on unique word of complete item for correct completion resolve on select change. I've just added the option |
OK, thanks. Sadly, as you said, there's an issue when that's |
Just fixed that, forget to add |
@chemzqm great! that's almost near echodoc, but still echodoc is doing better because it's showing the correct selected overload, |
And another thing is that for C++ what's shown in the command line is a bit strange than echodoc, I get |
echodoc using abbr field of vim's completion item on complete done, but coc using the result from language server, the server should return all overload signatures and coc could show them all. |
Could coc remember and associate which overload is the one I've selected in the menu and use that information to just show in the command line the one related with my selection? (This is just one solution, on my YouCompleteMe fork and on vim-clangd it's completely different approach that uses the preview window for overload display and signatureHelp on popup). |
It should be just the result from language server, checkout the output channel: https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel |
OK. |
I think the answer is no for now, since it's not standard to include function signature in complete item. |
You can ask echodoc to make use of virtual text feature of neovim, so you can have better experience with it. |
hi @MaskRay. The problem here is not LanguageClient, I was referring to the message and discussion just above, not the start of the issue, it's change on Coc here to output the detail data at the command line. For clangd it's displaying the member return type, but for ccls it displays the type of the variable being accessed, which is weird or not useful information in this situation. |
@oblitum Can you upload a screencast? For clangd it returns In ccls if (result_type.size())
for (auto i = first; i < out.size(); ++i) {
// ' : ' for variables,
// ' -> ' (trailing return type-like) for functions
out[i].label += (out[i].label == out[i].filterText ? " : " : " -> ");
out[i].label += result_type;
} |
In case the discussion is too confuse I'll produce a testcase later. To sum it up, Coc is getting LSP detail info from server and showing it. For clangd it shows one thing, for ccls it shows another. For example, for: struct S {
int foo(int a);
int foo(int x, int y);
};
int main() {
S s;
s.<browse the menu here>
} When browsing the popup there, Coc shows detail data, there are two functions, both return |
@oblitum I have mentioned in my previous comments: it is irony-mode style completion and I find it useful. ls_item.detail = CCS->getParentContextName().str(); You can set |
@MaskRay ah, ok then, I didn't get it. Thanks for the info. |
@MaskRay I've made |
That is client issue. It probably uniquifies completion items with But I'm unsure how useful it is. |
@MaskRay ok, I just thought the same, that it was client decision... Anyway, that's it. At least you captured what's the situation. |
@MaskRay regarding usability, I dunno what's more useful as detail, I think return value is better than the type of the variable I'm accessing, because it's the same detail for all members. I just don't have a formed opinion on what to make out of detail. Just |
Parent context in |
I've improved coc to extra word from snippet body of snippet complete item at 388294a, so this may not happen any more. |
@chemzqm yeah, it shows the two prototypes at the popup now, but the detail for both is the same prototype, if I try snippet expand for both, I just get the same one expanded. So I prefer it with |
The resolve on completion done using abbr, so I think I should add uuid to complete item to avoid this issue. |
@MaskRay I think I just realized why type for parent context is more useful. I was thinking too naively, my testcase also didn't help. There's two things, return type of member is already available from prototype in popup, so, it would just get duplicated in detail, like clangd does. Having the type of parent context becomes clearly more useful when you're member-accessing expressions whose type isn't readily visible/known, like in |
Indeed, the parent information starts to get useful on non-toy examples. FYI, in my mind, the ideal completion for C++ would look like this: With For this to work, I need the
There is something special with the Emacs completion backend, which I tried to work around by making the Not sure if this is of any help. Another thing, regarding the snippet issue. With Emacs' yasnippet, it's possible to enter snippet edits recursively. So you can do:
And never be left with an unexpanded snippet |
@Sarcasm thanks for your input. Yes that's the main theme of this issue, reason why it's still open. |
@Sarcasm the issue with snippets for me, even if they were working in nested form, is that they would still break/miss the placeholders if I decide to go about formatting the function call prior to inputting arguments, like displacing placeholders/args over multiple lines or reaching their end. 99% of implementations of snippets I know of in Vim at least will make the placeholders vanish and the snippet turned into plain text you have to manually patch. I had one very old implementation of snippets once whose placeholders were based on textual marks around formal parameters, the marks were concealed (Vim conceal feature) but used to define placeholder's highlighting and their location. With this I could have snippets that didn't simply vanish if I pressed enter or simply jumped placeholders too much hitting end-of-snippet. The drawback is that such markers were actual text that could be left in source or interfere with diagnostics. Old gif without conceal: Out of that experience I started to be inclined to like more param hints than snippets because I'd be free to edit as I wished. With Coc + echodoc at least I'm having the snippets expanded at my confirmation, and I get the per param info expanding them or not (not fully whitespace agnostic though). |
I think if I'd implement that today I would use special whitespace chars as delimiters, plus obligatory highlighting: fewer chance of producing any effect to compilation, and still having the placeholders highlighted/present in case they're forgot in source. |
Just tested b5827b3, working fine. Only thing is that "[LS]" is glued to the item's text, so it also goes to echodoc. |
echodoc is triky at extracting signature, it may provide hooks so you can fix the wrong signature. |
Agreed. |
Thanks! |
At tip (I'm on b4a2bb6 currently), this isn't necessary anymore. Even with |
Is your feature request related to a problem? Please describe.
I'm in general not liking the current implementations for function argument snippets that are being provided by several code completers because they're very limited. For example, for
int foo(int a, int b)
, if I accept the snippet forfoo
call with another snippet completion for a innerfoo
call as argument, this happens:foo(foo(4, 2), <placeholder jumps of first snippet don't work anymore!>int b)
, which means, I'll have to edit and remove the remainingint b
by hand, without snippet's jump and selection. That's very bad.Describe the solution you'd like
I can't say whether there's a best solution but I'd like at least to disable these snippets for function arguments so that I can just stick to echodoc.vim for example. LanguageClient-neovim provides
g:LanguageClient_hasSnippetSupport = 0
to help on that, for example.Describe alternatives you've considered
Alternative means of dealing with arguments are described here:
The text was updated successfully, but these errors were encountered: