Skip to content
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

Filter out help pages unrelated to a function usage #431

Closed

Conversation

yutannihilation
Copy link
Contributor

Fix this error posit-dev/positron#3467 (comment) of completionItem/resolve by filtering out help pages about the other topics than a function usage. I'm not sure if this is the best option, but this should work to some extent.

bar <- function(...) {}

bar()
#   ^
#   get errors when moving a cursor to here

I found this function when I looked around the source code of base R.

https://github.com/r-devel/r-svn/blob/1f537a2469956b505ad10135eeee282fe33a8475/src/library/tools/R/Rd.R#L689-L690

DavisVaughan added a commit to posit-dev/positron that referenced this pull request Aug 30, 2024
I was investigating #3467,
particularly the `completionItem/resolve` failure pop up you get when
you do

```r
bar <- function(...) {}

bar()
```

And hit `Tab` while your cursor is here `bar(<tab>)`

<img width="1483" alt="Screenshot 2024-08-29 at 4 37 52 PM"
src="https://github.com/user-attachments/assets/b45e0121-ebae-49f7-be1a-9c9228f7fb69">

posit-dev/ark#431 is an attempt to fix the
underlying issue here, and I do think we will merge a variant of that.

However, I realized that this is yet again a case of VS Code being too
aggressive about showing non-actionable LSP messages to the user, so I
went to see if we could turn this one off. As usual, there was an option
for this!

Note that the `RevealOutputChannelOn` enum is used in [exactly 1
place](https://github.com/search?q=repo%3Amicrosoft%2Fvscode-languageserver-node%20RevealOutputChannelOn&type=code)
in the `Client` middleware:

Particularly, right
[here](https://github.com/microsoft/vscode-languageserver-node/blob/14ddabfc22187b698e83ecde072247aa40727308/client/src/common/client.ts#L1180-L1188)
in `logOutputMessage()`, where it helps decide whether or not to
`showNotificationMessage()` to the user when `showNotification` is
`true`

It defaults to `RevealOutputChannelOn.Error`, but if we set this to
`RevealOutputChannelOn.Never` then it means that every instance of
`this.error()` in that `client.ts` file will no longer show the user an
error notification. Note that `Request completionItem/resolve failed`
was [one of these
cases](https://github.com/microsoft/vscode-languageserver-node/blob/14ddabfc22187b698e83ecde072247aa40727308/client/src/common/client.ts#L2239).

The most important thing to note is that even with `Never`, the error
message is always always [always
logged](https://github.com/microsoft/vscode-languageserver-node/blob/14ddabfc22187b698e83ecde072247aa40727308/client/src/common/client.ts#L1181)
to the corresponding `Positron Language Server: R x.y.z (console)`
Output channel. This is great. This is exactly what we want...and
nothing more. If the error doesn't crash the LSP, we probably don't want
to show it to the user, even if there is some kind of bug that we
probably should fix, because the user can't do anything about that!

See also this issue which describes in nice detail how this
`revealOutputChannelOn` option works, confirming my analysis here:
microsoft/vscode-languageserver-node#818

As further evidence, we are not alone in wanting to do this 🫡 
https://github.com/search?q=RevealOutputChannelOn.Never&type=code

Notably:
- The PowerShell LSP does this
-
[vscode-R](https://github.com/REditorSupport/vscode-R/blob/b196c7d8257a04509de68a3bfe7acf9c1f2fba85/src/languageService.ts#L138)
does too
-
[rust-analyzer](https://github.com/rust-lang/rust-analyzer/blob/master/editors/code/src/lang_client.ts)
effectively does too by overriding `handleFailedRequest()` entirely, but
I don't think we need to go that far.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 16, 2024
@yutannihilation yutannihilation deleted the check-if-help-has-args branch September 17, 2024 05:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant