Skip to content

Commit ca85185

Browse files
committed
docs: Update the lsp-extensions.md with the Hover Range capability
1 parent 506db18 commit ca85185

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

docs/dev/lsp-extensions.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ need to adjust this doc as well and ping this issue:
1313
This document describes LSP extensions used by rust-analyzer.
1414
It's a best effort document, when in doubt, consult the source (and send a PR with clarification ;-) ).
1515
We aim to upstream all non Rust-specific extensions to the protocol, but this is not a top priority.
16-
All capabilities are enabled via `experimental` field of `ClientCapabilities` or `ServerCapabilities`.
16+
All capabilities are enabled via the `experimental` field of `ClientCapabilities` or `ServerCapabilities`.
1717
Requests which we hope to upstream live under `experimental/` namespace.
1818
Requests, which are likely to always remain specific to `rust-analyzer` are under `rust-analyzer/` namespace.
1919

@@ -29,7 +29,7 @@ https://clangd.llvm.org/extensions.html#utf-8-offsets
2929

3030
**Issue:** https://github.com/microsoft/language-server-protocol/issues/567
3131

32-
The `initializationOptions` filed of the `InitializeParams` of the initialization request should contain `"rust-analyzer"` section of the configuration.
32+
The `initializationOptions` field of the `InitializeParams` of the initialization request should contain the `"rust-analyzer"` section of the configuration.
3333

3434
`rust-analyzer` normally sends a `"workspace/configuration"` request with `{ "items": ["rust-analyzer"] }` payload.
3535
However, the server can't do this during initialization.
@@ -81,7 +81,7 @@ At the moment, rust-analyzer guarantees that only a single edit will have `Inser
8181

8282
**Experimental Client Capability:** `{ "codeActionGroup": boolean }`
8383

84-
If this capability is set, `CodeAction` returned from the server contain an additional field, `group`:
84+
If this capability is set, `CodeAction`s returned from the server contain an additional field, `group`:
8585

8686
```typescript
8787
interface CodeAction {
@@ -209,7 +209,7 @@ fn main() {
209209

210210
**Experimental Server Capability:** `{ "onEnter": boolean }`
211211

212-
This request is sent from client to server to handle <kbd>Enter</kbd> keypress.
212+
This request is sent from client to server to handle the <kbd>Enter</kbd> key press.
213213

214214
**Method:** `experimental/onEnter`
215215

@@ -658,6 +658,31 @@ interface TestInfo {
658658
}
659659
```
660660

661+
## Hover Range
662+
663+
**Issue:** https://github.com/microsoft/language-server-protocol/issues/377
664+
665+
This request build upon the current `textDocument/hover` to show the type of the expression currently selected.
666+
667+
```typescript
668+
interface HoverParams extends lc.WorkDoneProgressParams {
669+
textDocument: lc.TextDocumentIdentifier;
670+
position: lc.Range | lc.Position;
671+
}
672+
```
673+
674+
Whenever the client sends a `Range`, it is understood as the current selection and any hover included in the range will show the type of the expression if possible.
675+
676+
### Example
677+
678+
```rust
679+
fn main() {
680+
let expression = $01 + 2 * 3$0;
681+
}
682+
```
683+
684+
Triggering a hover inside the selection above will show a result of `i32`.
685+
661686
## Move Item
662687

663688
**Issue:** https://github.com/rust-analyzer/rust-analyzer/issues/6823

editors/code/src/lsp_ext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/re
2121

2222
export const hover = new lc.RequestType<HoverParams, lc.Hover | null, void>("textDocument/hover");
2323

24-
export interface HoverParams extends lc.WorkDoneProgressParams{
24+
export interface HoverParams extends lc.WorkDoneProgressParams {
2525
textDocument: lc.TextDocumentIdentifier;
2626
position: lc.Range | lc.Position;
2727
}

0 commit comments

Comments
 (0)