-
Notifications
You must be signed in to change notification settings - Fork 812
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
Pass the current selection for a Hover Request #377
Comments
+1, I've also wanted this functionality in TypeScript. The current workaround I've used is to declare a local const with the expression to get the type. |
Can someone explain this feature to me with a TypeScript/JavaScript/Java example? Also, what happens if the hover is not over the selection in the editor? |
Suppose a user wonders what the type of One option is that the user can do: Other motivating expressions: await Promise.all([foo, bar, baz])
foo.then((f) => f.bar())
foo === undefined ? null : bar |
I had to implement this in the haskero plugin too. (As it communicates throughout the language server protocol). @alanz i should try to tweak my haskero plugin to use your language server, it could be nice |
It sounds reasonable to me to include the range in the Hover request. Anyone willing to work on a PR to add this. If so please also check if this can be added to the VS Code client LSP library (https://github.com/Microsoft/vscode-languageserver-node) |
@dbaeumer What would be added to Microsoft/vscode-languageserver-node? You mean update the protocol to reflect the new additional parameter in the request? It's not possible to make any client changes unless VS Code supports this given that /**
* The hover provider interface defines the contract between extensions and
* the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
*/
export interface HoverProvider {
/**
* Provide a hover for the given position and document. Multiple hovers at the same
* position will be merged by the editor. A hover can have a range which defaults
* to the word range at the position when omitted.
*
* @param document The document in which the command was invoked.
* @param position The position at which the command was invoked.
* @param token A cancellation token.
* @return A hover or a thenable that resolves to such. The lack of a result can be
* signaled by returning `undefined` or `null`.
*/
provideHover(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Hover>;
} I think to move forward with this we need to decide on three things:
|
I hope the |
Any updates on this? I want the "get type of the expression" for |
This would be quite useful for |
rust-analyzer adds this as an extension: Hover RangeExperimental Server Capability: { "hoverRange": boolean } This extension allows passing a interface HoverParams extends WorkDoneProgressParams {
textDocument: TextDocumentIdentifier;
position: Range | Position;
} Whenever the client sends a Turns out, it's very straightforward to just support this in VS Code as well: |
What does the client send as |
The current implementation just sends the position, yes. |
An implementation IMO must look like this:
|
This is needed to handle scalameta/metals#3060 It should be handle by LSP package once microsoft/language-server-protocol#377 is resolved
This an alternative solution to scalameta/metals-sublime#45 The current implementation is just a workaround until microsoft/language-server-protocol#377 is part of the LSP spec
This an alternative solution to scalameta/metals-sublime#45 The current implementation is just a workaround until microsoft/language-server-protocol#377 is part of the LSP spec
This a better alternative to scalameta/metals-sublime#45 and this implementation is just a workaround until microsoft/language-server-protocol#377 is part of the LSP spec
FWIW, I wouldn't mix the Range type with the position:
instead I would add a optional range property:
The server can then return whatever it wants based if the range is present or not. |
A workaround for microsoft/language-server-protocol#377 until it is resolved this would allow LSP clients to explicitly know that they can send a range with textDocument/hover instead of a position
This relies on `experimental.rangeHoverProvider` which so far only Metals implement. But this workaround would be removed once microsoft/language-server-protocol#377 is part of the LSP specification.
This relies on `experimental.rangeHoverProvider` which so far only Metals implement. But this workaround would be removed once microsoft/language-server-protocol#377 is part of the LSP specification.
This relies on `experimental.rangeHoverProvider` which so far only Metals implement. But this workaround would be removed once microsoft/language-server-protocol#377 is part of the LSP specification.
I don't have experience with LSP nor TS enough to contribute in the near term, but this submission would be of great benefit to Haskell's LSP server! |
It seems there is a great deal of enthusiasm for this simple extension to the protocol from maintainers of clients for Haskell, Rust, Go, TS, Scala, Ocaml and perhaps other languages. Do we all agree with @predragnikolic that the appropriate change is a new optional interface HoverParams ... {
textDocument: TextDocumentIdentifier;
position: Position;
+ range?: Range;
} Should this change be made just to HoverParams, or to the TextDocumentPositionParams base class? In all other existing uses of TextDocumentPositionParams the @dbaeumer asks whether "LSP should support a kind of selection with an anchor to know how the range got created": Is this necessary? I suspect we can all benefit from the current modest proposal without it. @dbaeumer also says the feature must be "guarded by a server capability since clients can't suddenly send a range". However @predragnikolic's suggestion of using an additional field makes this unnecessary. Any objections to adding a |
Having a range in |
This change adds an optional range field to textDocumentPositionParams so that clients can, for example, query a subexpression such as x.f within a larger expression g(x.f[i]). Also, clarify the text about cursor bias. Fixes microsoft#377 Fixes microsoft#1029
83 thumbs up on the issue body, 8 thumbs up on the specific proposal two comments above, no objections in 3 weeks. Please review this PR: #2027 |
This change adds an optional range field to textDocumentPositionParams so that clients can, for example, query a subexpression such as x.f within a larger expression g(x.f[i]). Also, clarify the text about cursor bias. Fixes microsoft#377 Fixes microsoft#1029
In some languages, such as Haskell, it is meaningful to show the type of an expression, rather than just an identifier.
To allow this, extend the Hover Request to also include a
Range
if the selection is active.At the moment in the haskell vscode plugin this is done in a roundabout way using
workspace/executeCommand
, which means it has to be separately implemented in each client.The text was updated successfully, but these errors were encountered: