From ca85185bc6eef45fa34ac293288bbe9bd11bb684 Mon Sep 17 00:00:00 2001 From: Alexander Gonzalez Date: Mon, 26 Jul 2021 17:05:59 -0400 Subject: [PATCH] docs: Update the lsp-extensions.md with the Hover Range capability --- docs/dev/lsp-extensions.md | 33 +++++++++++++++++++++++++++++---- editors/code/src/lsp_ext.ts | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index ffc94b178a5..e13f81e1ff0 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -13,7 +13,7 @@ need to adjust this doc as well and ping this issue: This document describes LSP extensions used by rust-analyzer. It's a best effort document, when in doubt, consult the source (and send a PR with clarification ;-) ). We aim to upstream all non Rust-specific extensions to the protocol, but this is not a top priority. -All capabilities are enabled via `experimental` field of `ClientCapabilities` or `ServerCapabilities`. +All capabilities are enabled via the `experimental` field of `ClientCapabilities` or `ServerCapabilities`. Requests which we hope to upstream live under `experimental/` namespace. Requests, which are likely to always remain specific to `rust-analyzer` are under `rust-analyzer/` namespace. @@ -29,7 +29,7 @@ https://clangd.llvm.org/extensions.html#utf-8-offsets **Issue:** https://github.com/microsoft/language-server-protocol/issues/567 -The `initializationOptions` filed of the `InitializeParams` of the initialization request should contain `"rust-analyzer"` section of the configuration. +The `initializationOptions` field of the `InitializeParams` of the initialization request should contain the `"rust-analyzer"` section of the configuration. `rust-analyzer` normally sends a `"workspace/configuration"` request with `{ "items": ["rust-analyzer"] }` payload. 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 **Experimental Client Capability:** `{ "codeActionGroup": boolean }` -If this capability is set, `CodeAction` returned from the server contain an additional field, `group`: +If this capability is set, `CodeAction`s returned from the server contain an additional field, `group`: ```typescript interface CodeAction { @@ -209,7 +209,7 @@ fn main() { **Experimental Server Capability:** `{ "onEnter": boolean }` -This request is sent from client to server to handle Enter keypress. +This request is sent from client to server to handle the Enter key press. **Method:** `experimental/onEnter` @@ -658,6 +658,31 @@ interface TestInfo { } ``` +## Hover Range + +**Issue:** https://github.com/microsoft/language-server-protocol/issues/377 + +This request build upon the current `textDocument/hover` to show the type of the expression currently selected. + +```typescript +interface HoverParams extends lc.WorkDoneProgressParams { + textDocument: lc.TextDocumentIdentifier; + position: lc.Range | lc.Position; +} +``` + +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. + +### Example + +```rust +fn main() { + let expression = $01 + 2 * 3$0; +} +``` + +Triggering a hover inside the selection above will show a result of `i32`. + ## Move Item **Issue:** https://github.com/rust-analyzer/rust-analyzer/issues/6823 diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index deb0db56eee..ac632a01567 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -21,7 +21,7 @@ export const reloadWorkspace = new lc.RequestType0("rust-analyzer/re export const hover = new lc.RequestType("textDocument/hover"); -export interface HoverParams extends lc.WorkDoneProgressParams{ +export interface HoverParams extends lc.WorkDoneProgressParams { textDocument: lc.TextDocumentIdentifier; position: lc.Range | lc.Position; }