lsp: provide doc:show in hover, if available#1684
Conversation
doc:show in hover, if available
3351f49 to
d994b02
Compare
|
@xiaq @krader1961 @zzamboni -- Would greatly appreciate a review and/or feedback on this feature... Thanks :-) ! |
|
Hi, thanks for the contribution. I usually review PRs in a FIFO manner, but here are some high-level feedback:
Feel free to address those before I get back to this again, but this is a useful starting point and I wouldn't mind merging this as-is if you prefer. |
|
Thanks !
Yes, this can definitely be improved. Current algorithm
This approach has some false positives like showing hover for Better Algorithm
I found the parsing/AST code a bit intimidating and was not sure how I should approach (2). Can you provide some pointers for (2) ? Is there a pretty printer of some sort for the parse tree to get a feel of it ? If you think it is too complicated to communicate tips for (2) then you could merge this commit as-is as you mentioned and improve upon this feature as you see fit. |
There is already one place that does it, the completer for commands: elvish/pkg/edit/complete/completers.go Line 77 in 66a4c59 The code is very concise thanks to some abstractions defined in |
As can be seen in the screenshot in #1684 (comment), the on-hover doc shows "```elvish" for the code block that contains the usage of the command, which shouldn't appear in the rendered Markdown. This is because the response uses the deprecated MarkedString format, where > The pair of a language and a value is an equivalent to markdown: > ```${language} > ${value} > ``` When this format is used, the "```elvish" code block is embedded inside another "```markdown" codeblock, which leads to this weird rendering artifact. Switching to the new MarkupContent format fixes this issue. However, the github.com/sourcegraph/go-lsp is outdated and doesn't have this type defined, so define it ourselves for now. In future we should switch to a more up-to-date Go package that contains the LSP types. Also remove the superfluous MarkdownShowMaybe function, and just export doc.Source. The former did nothing useful other than prepending "# symbol". I tested the on-hover docs of both Go and JavaScript in VS Code, both start with the declaration of the symbol, not a heading.

I am new to elvish. I am enjoying elvish very much, thank you!
The built in LSP feature in elvish is very useful but a bit basic at the moment.
One thing that I am running into while reading or writing elvish scripts in an editor (where I am connected to a
elvish -lsp) is that I constantly need to refer to the documentation about a particular function (e.g.printfetc) in order to learn the finer aspects of the function.This means I need to constantly do
doc:showin the shell or refer to the elvish website and this breaks my editing "flow".This PR automatically shows the
doc:show(if available) for anything on the cursor in a hover.The implementation is quite simple and it could be more sophisticated but it's working quite well for me.