Skip to content

Add links to help pages in hover#578

Merged
renkun-ken merged 2 commits intoREditorSupport:masterfrom
ManuelHentschel:hover
Mar 12, 2021
Merged

Add links to help pages in hover#578
renkun-ken merged 2 commits intoREditorSupport:masterfrom
ManuelHentschel:hover

Conversation

@ManuelHentschel
Copy link
Copy Markdown
Member

What problem did you solve?
This PR adds a hover provider that that shows links to matching help pages when hovering over names of R functions.

How can I check this pull request?
Hover over the name of a (documented) R function, wait for hover to show up and check if a link to a help page shows up.

Limitations:
On my machine the link shows up below other hovers, which can be a bit cumbersome if a large help page is shown e.g. by the languageserver.
The hover can be a bit eager, e.g. showing dplyr::n when hovering over a single n. This would be rather hard to solve properly, since the hover is unaware of any tokenization or other languageserver functions. If this is too annoying, the hover can be disabled completely using r.helpPanel.enableHoverLinks = false

Copy link
Copy Markdown
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@renkun-ken renkun-ken merged commit bcc4ef8 into REditorSupport:master Mar 12, 2021
@ManuelHentschel ManuelHentschel deleted the hover branch March 12, 2021 11:42
@renkun-ken
Copy link
Copy Markdown
Member

renkun-ken commented Mar 13, 2021

@ManuelHentschel I guess we could move this feature to CodeActions so that hover from languageserver will not already appear above these help links?

@renkun-ken
Copy link
Copy Markdown
Member

Looks like the CodeActions may not be a proper place to do this as it does nothing to the source code.

@ManuelHentschel
Copy link
Copy Markdown
Member Author

@ManuelHentschel I guess we could move this feature to CodeActions so that hover from languageserver will not already appear above these help links?

I didn't manage to add the help links anywhere in the language server, since commands in markdown links only work if MarkdownString.isTrusted is set to true somehow, which I don't think is possible (and probably wouldn't be a good idea anyways)

@renkun-ken
Copy link
Copy Markdown
Member

I tried using CodeActions to do this, and it looks better I think.

image

@ManuelHentschel
Copy link
Copy Markdown
Member Author

ManuelHentschel commented Mar 13, 2021

That does look nice. How does the communication between languageserver and helppanel work here?
I only tried command-links in markdown, which are affected by the isTrusted problem I mentioned above.

Providing these links from within the languageserver might also allow us to only show relevant links (e.g. if the ls knows, which package the function is from, or if the currently selected word is inside a string).

@renkun-ken
Copy link
Copy Markdown
Member

renkun-ken commented Mar 13, 2021

It is not provided by languageserver. I just switch from HoverProvider to CodeActionProvider in vscode-R. Then a vscode.CodeAction could be used to trigger any vscode.Command with arguments.

@renkun-ken
Copy link
Copy Markdown
Member

In this case, I'm not sure if the setting helpPanel.enableHoverLinks is useful anymore? Maybe we could rename it to helpPanel.enableCodeActions or something more obvious? Or we simply remove it until somebody really needs such a setting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants