autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 273 forks source link

calling textDocument_hover when selecting in autocomplete #1042

Closed take closed 4 years ago

take commented 4 years ago

Hi thanks for the awesome library :)

IDK if this is the right place to ask, is it possible to call LanguageClient#textDocument_hover() when selecting inside the autocomplete? :eyes:

e.g. in the image below, I want the document to be shown automatically as I go around the completion

Screen Shot 2020-05-31 at 23 47 39
martskins commented 4 years ago

You actually don't need to call hover (in fact that would not work), as the documentation for each item comes from the language server itself in the completion response. You should be able to show that documentation as you scroll through the list by adding this to your config: set completeopt += preview. Note that that will show the documentation in the preview window, if you want to show it somewhere else then you will probably have to config your completion plugin (ncm2, deoplete, or whatever you use) to do so (if it's possible to do so).

take commented 4 years ago

@martskins

Aha thanks! Looks like I don't get the preview info although I have preview inside completeopt. Should I create a issue on the autocomplete plugin repo? :eyes: Or do you know anyways to debug this problem? :bow:

martskins commented 4 years ago

I'd probably set the log level to INFO and check the logs first to see if the completion items that you are getting include the documentation key. Or just try the same config you are using with some other language server (maybe for another language too) and see if that works that way.

Some things that might be useful: Set the logging level: let g:LanguageClient_loggingLevel = 'INFO' Set log file path: let g:LanguageClient_loggingFile = '/some/path/lcn.log'

take commented 4 years ago

@martskins

thanks! I tried it out and seems like there weren't any documentation key although :call LanguageClient#textDocument_hover() does work .... 🤔

log: https://gist.github.com/take/54fb4bf9a30c336bb63ffcdf12102bc1

Screen Shot 2020-06-01 at 19 55 32

Does this mean that the language server does return the document when I specify it via :call LanguageClient#textDocument_hover(), but doesn't when I'm autocompleting it...? 🤔

take commented 4 years ago

I tried both javascript-typescript-langserver and typescript-language-server and got the same results hmmmm 🤔

martskins commented 4 years ago

Looking at javascript-typescript-langserver's code, it seems like it doesn't return the documentation for the returned items in the textDocument/completion call, it instead returns the documentation in the completionItem/resolve call. I'm not sure which events are available in order to identify that you changed selection in your completion options, but if the completion plugin you are using provides some sort of callback for that then you could probably write a function to fire that completionItem/resolve request and open the documentation somewhere.

Maybe someone has a better idea of how to tackle this though, so don't take this as a it can't be done :smile:

take commented 4 years ago

Looking at javascript-typescript-langserver's code, it seems like it doesn't return the documentation for the returned items in the textDocument/completion call, it instead returns the documentation in the completionItem/resolve call.

ooooooo i seeee..... and looks like javascript-typescript-langserver is returning it in resolve due to performance issue... 🤔

I googled completionItem/resolve and found out this issue is a duplicate of #875 :) I'll close this for now, thanks for the help 🙋 @martskins

martskins commented 4 years ago

@take Opened #1043 to try and kicks things off about implementing this in our side, as it seems it may require that extra completionItem/resolve call in some cases/servers.

take commented 4 years ago

@martskins ooooo thanks! I'll try it out :D