2020-10-14 06:30:06 -05:00
<!-- -
2023-07-08 11:25:54 -05:00
lsp_ext.rs hash: 149a5be3c5e469d1
2020-10-14 06:30:06 -05:00
If you need to change the above hash to make the test pass, please check if you
2021-04-13 13:32:45 -05:00
need to adjust this doc as well and ping this issue:
2020-10-14 06:30:06 -05:00
2022-07-08 08:44:49 -05:00
https://github.com/rust-lang/rust-analyzer/issues/4604
2020-10-14 06:30:06 -05:00
--->
2020-05-17 14:24:33 -05:00
# LSP Extensions
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.
2021-07-26 16:05:59 -05:00
All capabilities are enabled via the `experimental` field of `ClientCapabilities` or `ServerCapabilities` .
2020-05-24 08:49:32 -05:00
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.
2020-05-17 14:24:33 -05:00
2022-07-08 08:44:49 -05:00
If you want to be notified about the changes to this document, subscribe to [#4604 ](https://github.com/rust-lang/rust-analyzer/issues/4604 ).
2020-06-01 10:51:15 -05:00
2021-05-27 03:16:14 -05:00
## Configuration in `initializationOptions`
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/567
2021-05-27 03:16:14 -05:00
2021-07-26 16:05:59 -05:00
The `initializationOptions` field of the `InitializeParams` of the initialization request should contain the `"rust-analyzer"` section of the configuration.
2021-05-27 03:16:14 -05:00
`rust-analyzer` normally sends a `"workspace/configuration"` request with `{ "items": ["rust-analyzer"] }` payload.
However, the server can't do this during initialization.
At the same time some essential configuration parameters are needed early on, before servicing requests.
For this reason, we ask that `initializationOptions` contains the configuration, as if the server did make a `"workspace/configuration"` request.
2020-06-01 10:42:46 -05:00
2020-07-22 09:05:36 -05:00
If a language client does not know about `rust-analyzer` 's configuration options it can get sensible defaults by doing any of the following:
* Not sending `initializationOptions`
2021-05-27 03:16:14 -05:00
* Sending `"initializationOptions": null`
* Sending `"initializationOptions": {}`
2020-06-01 10:42:46 -05:00
2020-05-22 10:29:55 -05:00
## Snippet `TextEdit`
2020-05-17 14:24:33 -05:00
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/724
2020-05-22 12:14:14 -05:00
2021-03-09 03:02:20 -06:00
**Experimental Client Capability:** `{ "snippetTextEdit": boolean }`
2020-05-17 14:24:33 -05:00
2022-03-27 03:45:57 -05:00
If this capability is set, `WorkspaceEdit` s returned from `codeAction` requests and `TextEdit` s returned from `textDocument/onTypeFormatting` requests might contain `SnippetTextEdit` s instead of usual `TextEdit` s:
2020-05-17 14:24:33 -05:00
```typescript
interface SnippetTextEdit extends TextEdit {
insertTextFormat?: InsertTextFormat;
2021-04-18 05:50:44 -05:00
annotationId?: ChangeAnnotationIdentifier;
2020-05-17 14:24:33 -05:00
}
```
```typescript
export interface TextDocumentEdit {
2021-04-06 10:37:41 -05:00
textDocument: OptionalVersionedTextDocumentIdentifier;
edits: (TextEdit | SnippetTextEdit)[];
2020-05-17 14:24:33 -05:00
}
```
2022-03-27 03:45:57 -05:00
When applying such code action or text edit, the editor should insert snippet, with tab stops and placeholder.
2020-05-17 14:24:33 -05:00
At the moment, rust-analyzer guarantees that only a single edit will have `InsertTextFormat.Snippet` .
2020-05-21 12:50:23 -05:00
### Example
"Add `derive` " code action transforms `struct S;` into `#[derive($0)] struct S;`
### Unresolved Questions
* Where exactly are `SnippetTextEdit` s allowed (only in code actions at the moment)?
* Can snippets span multiple files (so far, no)?
2020-05-24 08:49:32 -05:00
## `CodeAction` Groups
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/994
2020-05-24 08:49:32 -05:00
2021-03-09 03:02:20 -06:00
**Experimental Client Capability:** `{ "codeActionGroup": boolean }`
2020-05-24 08:49:32 -05:00
2021-07-26 16:05:59 -05:00
If this capability is set, `CodeAction` s returned from the server contain an additional field, `group` :
2020-05-24 08:49:32 -05:00
```typescript
interface CodeAction {
title: string;
group?: string;
...
}
```
All code-actions with the same `group` should be grouped under single (extendable) entry in lightbulb menu.
The set of actions `[ { title: "foo" }, { group: "frobnicate", title: "bar" }, { group: "frobnicate", title: "baz" }]` should be rendered as
```
💡
+-------------+
| foo |
+-------------+-----+
| frobnicate >| bar |
+-------------+-----+
| baz |
+-----+
```
Alternatively, selecting `frobnicate` could present a user with an additional menu to choose between `bar` and `baz` .
### Example
```rust
fn main() {
let x: Entry/*cursor here*/ = todo!();
}
```
Invoking code action at this position will yield two code actions for importing `Entry` from either `collections::HashMap` or `collection::BTreeMap` , grouped under a single "import" group.
### Unresolved Questions
* Is a fixed two-level structure enough?
* Should we devise a general way to encode custom interaction protocols for GUI refactorings?
2020-05-25 08:55:25 -05:00
## Parent Module
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/1002
2020-05-25 08:55:25 -05:00
2021-03-09 03:02:20 -06:00
**Experimental Server Capability:** `{ "parentModule": boolean }`
2020-05-25 08:55:25 -05:00
2020-09-03 03:13:02 -05:00
This request is sent from client to server to handle "Goto Parent Module" editor action.
2020-05-25 08:55:25 -05:00
**Method:** `experimental/parentModule`
**Request:** `TextDocumentPositionParams`
**Response:** `Location | Location[] | LocationLink[] | null`
### Example
```rust
// src/main.rs
mod foo;
// src/foo.rs
/* cursor here*/
```
`experimental/parentModule` returns a single `Link` to the `mod foo;` declaration.
### Unresolved Question
* An alternative would be to use a more general "gotoSuper" request, which would work for super methods, super classes and super modules.
2021-04-06 10:37:41 -05:00
This is the approach IntelliJ Rust is taking.
2020-05-25 08:55:25 -05:00
However, experience shows that super module (which generally has a feeling of navigation between files) should be separate.
2021-04-06 10:37:41 -05:00
If you want super module, but the cursor happens to be inside an overridden function, the behavior with single "gotoSuper" request is surprising.
2020-05-25 08:55:25 -05:00
2020-05-22 10:29:55 -05:00
## Join Lines
2020-05-21 12:50:23 -05:00
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/992
2020-05-22 12:14:14 -05:00
2021-03-09 03:02:20 -06:00
**Experimental Server Capability:** `{ "joinLines": boolean }`
2020-05-21 12:50:23 -05:00
2020-09-03 03:13:02 -05:00
This request is sent from client to server to handle "Join Lines" editor action.
2020-05-21 12:50:23 -05:00
2020-05-24 09:18:46 -05:00
**Method:** `experimental/joinLines`
2020-05-21 12:50:23 -05:00
**Request:**
```typescript
interface JoinLinesParams {
textDocument: TextDocumentIdentifier,
/// Currently active selections/cursor offsets.
/// This is an array to support multiple cursors.
ranges: Range[],
}
```
2020-05-25 08:55:25 -05:00
**Response:** `TextEdit[]`
2020-05-21 12:50:23 -05:00
### Example
```rust
fn main() {
/*cursor here*/let x = {
92
};
}
```
2020-05-29 16:41:04 -05:00
`experimental/joinLines` yields (curly braces are automagically removed)
2020-05-21 12:50:23 -05:00
```rust
fn main() {
let x = 92;
}
```
### Unresolved Question
* What is the position of the cursor after `joinLines` ?
2021-04-06 10:37:41 -05:00
Currently, this is left to editor's discretion, but it might be useful to specify on the server via snippets.
2020-05-21 12:50:23 -05:00
However, it then becomes unclear how it works with multi cursor.
2020-05-21 17:28:49 -05:00
2020-05-25 07:12:53 -05:00
## On Enter
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/1001
2020-05-25 07:12:53 -05:00
2021-03-09 03:02:20 -06:00
**Experimental Server Capability:** `{ "onEnter": boolean }`
2020-05-25 07:12:53 -05:00
2021-07-26 16:05:59 -05:00
This request is sent from client to server to handle the < kbd > Enter< / kbd > key press.
2020-05-25 07:12:53 -05:00
**Method:** `experimental/onEnter`
**Request:**: `TextDocumentPositionParams`
**Response:**
```typescript
SnippetTextEdit[]
```
### Example
```rust
fn main() {
// Some /*cursor here*/ docs
let x = 92;
}
```
`experimental/onEnter` returns the following snippet
```rust
fn main() {
// Some
// $0 docs
let x = 92;
}
```
The primary goal of `onEnter` is to handle automatic indentation when opening a new line.
This is not yet implemented.
The secondary goal is to handle fixing up syntax, like continuing doc strings and comments, and escaping `\n` in string literals.
As proper cursor positioning is raison-d'etat for `onEnter` , it uses `SnippetTextEdit` .
### Unresolved Question
* How to deal with synchronicity of the request?
One option is to require the client to block until the server returns the response.
Another option is to do a OT-style merging of edits from client and server.
2021-02-03 06:40:24 -06:00
A third option is to do a record-replay: client applies heuristic on enter immediately, then applies all user's keypresses.
2020-05-25 07:12:53 -05:00
When the server is ready with the response, the client rollbacks all the changes and applies the recorded actions on top of the correct response.
* How to deal with multiple carets?
* Should we extend this to arbitrary typed events and not just `onEnter` ?
2020-05-21 17:28:49 -05:00
## Structural Search Replace (SSR)
2021-03-09 03:02:20 -06:00
**Experimental Server Capability:** `{ "ssr": boolean }`
2020-05-21 17:28:49 -05:00
2020-09-03 03:13:02 -05:00
This request is sent from client to server to handle structural search replace -- automated syntax tree based transformation of the source.
2020-05-21 17:28:49 -05:00
**Method:** `experimental/ssr`
**Request:**
```typescript
interface SsrParams {
/// Search query.
/// The specific syntax is specified outside of the protocol.
query: string,
/// If true, only check the syntax of the query and don't compute the actual edit.
2021-11-12 13:15:08 -06:00
parseOnly: boolean,
2020-07-22 00:00:28 -05:00
/// The current text document. This and `position` will be used to determine in what scope
/// paths in `query` should be resolved.
2021-07-30 08:30:04 -05:00
textDocument: TextDocumentIdentifier;
2020-07-22 00:00:28 -05:00
/// Position where SSR was invoked.
2021-07-30 08:30:04 -05:00
position: Position;
2022-02-12 08:47:54 -06:00
/// Current selections. Search/replace will be restricted to these if non-empty.
selections: Range[];
2020-05-21 17:28:49 -05:00
}
```
**Response:**
```typescript
WorkspaceEdit
```
### Example
2020-07-22 00:00:28 -05:00
SSR with query `foo($a, $b) ==>> ($a).foo($b)` will transform, eg `foo(y + 5, z)` into `(y + 5).foo(z)` .
2020-05-21 17:28:49 -05:00
### Unresolved Question
* Probably needs search without replace mode
* Needs a way to limit the scope to certain files.
2020-05-24 09:18:46 -05:00
## Matching Brace
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/999
2020-05-24 09:18:46 -05:00
2021-03-09 03:02:20 -06:00
**Experimental Server Capability:** `{ "matchingBrace": boolean }`
2020-05-24 09:18:46 -05:00
2020-09-01 03:36:48 -05:00
This request is sent from client to server to handle "Matching Brace" editor action.
2020-05-24 09:18:46 -05:00
**Method:** `experimental/matchingBrace`
**Request:**
```typescript
interface MatchingBraceParams {
textDocument: TextDocumentIdentifier,
/// Position for each cursor
positions: Position[],
}
```
**Response:**
```typescript
Position[]
```
### Example
```rust
fn main() {
let x: Vec< ()>/*cursor here*/ = vec![]
}
```
`experimental/matchingBrace` yields the position of `<` .
In many cases, matching braces can be handled by the editor.
However, some cases (like disambiguating between generics and comparison operations) need a real parser.
Moreover, it would be cool if editors didn't need to implement even basic language parsing
### Unresolved Question
2023-04-13 17:35:00 -05:00
* Should we return a nested brace structure, to allow [paredit ](https://paredit.org/ )-like actions of jump *out* of the current brace pair?
2020-05-24 09:18:46 -05:00
This is how `SelectionRange` request works.
* Alternatively, should we perhaps flag certain `SelectionRange` s as being brace pairs?
2020-05-24 10:01:40 -05:00
2020-06-02 10:34:18 -05:00
## Runnables
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/944
2020-06-02 10:34:18 -05:00
2021-03-09 03:02:20 -06:00
**Experimental Server Capability:** `{ "runnables": { "kinds": string[] } }`
2020-06-02 10:34:18 -05:00
2020-09-03 03:13:02 -05:00
This request is sent from client to server to get the list of things that can be run (tests, binaries, `cargo check -p` ).
2020-06-02 10:34:18 -05:00
**Method:** `experimental/runnables`
**Request:**
```typescript
interface RunnablesParams {
textDocument: TextDocumentIdentifier;
/// If null, compute runnables for the whole file.
position?: Position;
}
```
**Response:** `Runnable[]`
```typescript
interface Runnable {
label: string;
/// If this Runnable is associated with a specific function/module, etc, the location of this item
location?: LocationLink;
/// Running things is necessary technology specific, `kind` needs to be advertised via server capabilities,
// the type of `args` is specific to `kind` . The actual running is handled by the client.
kind: string;
args: any;
}
```
rust-analyzer supports only one `kind` , `"cargo"` . The `args` for `"cargo"` look like this:
```typescript
{
workspaceRoot?: string;
cargoArgs: string[];
2020-10-16 11:30:05 -05:00
cargoExtraArgs: string[];
2020-06-02 10:34:18 -05:00
executableArgs: string[];
2020-10-16 11:30:05 -05:00
expectTest?: boolean;
overrideCargo?: string;
2020-06-02 10:34:18 -05:00
}
```
2020-09-01 03:36:48 -05:00
## Open External Documentation
2023-04-28 03:27:16 -05:00
This request is sent from the client to the server to obtain web and local URL(s) for documentation related to the symbol under the cursor, if available.
2020-09-01 03:36:48 -05:00
2023-04-28 03:27:16 -05:00
**Method:** `experimental/externalDocs`
2020-09-01 03:36:48 -05:00
2023-04-28 03:27:16 -05:00
**Request:** `TextDocumentPositionParams`
**Response:** `string | null`
## Local Documentation
2020-09-01 03:36:48 -05:00
2023-04-28 03:27:16 -05:00
**Experimental Client Capability:** `{ "localDocs": boolean }`
2020-09-01 03:36:48 -05:00
2023-04-28 03:27:16 -05:00
If this capability is set, the `Open External Documentation` request returned from the server will have the following structure:
```typescript
interface ExternalDocsResponse {
web?: string;
local?: string;
}
```
2020-09-01 03:36:48 -05:00
2020-05-24 10:01:40 -05:00
## Analyzer Status
**Method:** `rust-analyzer/analyzerStatus`
2020-09-29 15:05:18 -05:00
**Request:**
```typescript
interface AnalyzerStatusParams {
/// If specified, show dependencies of the current file.
textDocument?: TextDocumentIdentifier;
}
```
2020-05-24 10:01:40 -05:00
**Response:** `string`
Returns internal status message, mostly for debugging purposes.
2020-07-01 07:57:59 -05:00
## Reload Workspace
2020-05-24 10:01:40 -05:00
2020-07-01 07:57:59 -05:00
**Method:** `rust-analyzer/reloadWorkspace`
2020-05-24 10:01:40 -05:00
**Request:** `null`
**Response:** `null`
2020-07-01 07:57:59 -05:00
Reloads project information (that is, re-executes `cargo metadata` ).
2020-05-24 10:01:40 -05:00
2023-03-26 01:39:28 -05:00
## Rebuild proc-macros
2023-03-25 14:54:24 -05:00
2023-03-26 01:39:28 -05:00
**Method:** `rust-analyzer/rebuildProcMacros`
2023-03-25 14:54:24 -05:00
**Request:** `null`
**Response:** `null`
Rebuilds build scripts and proc-macros, and runs the build scripts to reseed the build data.
2021-04-06 06:16:35 -05:00
## Server Status
2020-07-02 05:37:04 -05:00
2021-04-19 09:55:51 -05:00
**Experimental Client Capability:** `{ "serverStatusNotification": boolean }`
2020-07-02 05:37:04 -05:00
2021-04-06 06:16:35 -05:00
**Method:** `experimental/serverStatus`
2020-07-02 05:37:04 -05:00
2020-08-17 06:56:27 -05:00
**Notification:**
```typescript
2021-04-06 06:16:35 -05:00
interface ServerStatusParams {
/// `ok` means that the server is completely functional.
///
/// `warning` means that the server is partially functional.
2021-04-19 10:10:33 -05:00
/// It can answer correctly to most requests, but some results
/// might be wrong due to, for example, some missing dependencies.
2021-04-06 06:16:35 -05:00
///
/// `error` means that the server is not functional. For example,
2021-04-19 10:10:33 -05:00
/// there's a fatal build configuration problem. The server might
/// still give correct answers to simple requests, but most results
/// will be incomplete or wrong.
2021-04-06 06:16:35 -05:00
health: "ok" | "warning" | "error",
/// Is there any pending background work which might change the status?
/// For example, are dependencies being downloaded?
2021-11-12 13:15:08 -06:00
quiescent: boolean,
2021-04-06 06:16:35 -05:00
/// Explanatory message to show on hover.
message?: string,
2020-08-17 06:56:27 -05:00
}
```
2020-07-02 05:37:04 -05:00
This notification is sent from server to client.
2021-04-06 06:16:35 -05:00
The client can use it to display *persistent* status to the user (in modline).
It is similar to the `showMessage` , but is intended for stares rather than point-in-time events.
2021-04-19 10:10:33 -05:00
Note that this functionality is intended primarily to inform the end user about the state of the server.
In particular, it's valid for the client to completely ignore this extension.
Clients are discouraged from but are allowed to use the `health` status to decide if it's worth sending a request to the server.
2020-07-02 05:37:04 -05:00
2022-12-17 16:43:26 -06:00
### Controlling Flycheck
The flycheck/checkOnSave feature can be controlled via notifications sent by the client to the server.
**Method:** `rust-analyzer/runFlycheck`
**Notification:**
```typescript
interface RunFlycheckParams {
/// The text document whose cargo workspace flycheck process should be started.
/// If the document is null or does not belong to a cargo workspace all flycheck processes will be started.
textDocument: lc.TextDocumentIdentifier | null;
}
```
Triggers the flycheck processes.
**Method:** `rust-analyzer/clearFlycheck`
**Notification:**
```typescript
interface ClearFlycheckParams {}
```
Clears the flycheck diagnostics.
**Method:** `rust-analyzer/cancelFlycheck`
**Notification:**
```typescript
interface CancelFlycheckParams {}
```
Cancels all running flycheck processes.
2020-05-24 10:01:40 -05:00
## Syntax Tree
**Method:** `rust-analyzer/syntaxTree`
**Request:**
```typescript
2021-05-21 17:03:36 -05:00
interface SyntaxTreeParams {
2020-05-24 10:01:40 -05:00
textDocument: TextDocumentIdentifier,
range?: Range,
}
```
**Response:** `string`
Returns textual representation of a parse tree for the file/selected region.
Primarily for debugging, but very useful for all people working on rust-analyzer itself.
2021-01-01 13:25:18 -06:00
## View Hir
**Method:** `rust-analyzer/viewHir`
**Request:** `TextDocumentPositionParams`
**Response:** `string`
Returns a textual representation of the HIR of the function containing the cursor.
For debugging or when working on rust-analyzer itself.
2023-02-26 06:34:41 -06:00
## View Mir
**Method:** `rust-analyzer/viewMir`
**Request:** `TextDocumentPositionParams`
**Response:** `string`
Returns a textual representation of the MIR of the function containing the cursor.
For debugging or when working on rust-analyzer itself.
2023-04-28 12:14:30 -05:00
## Interpret Function
**Method:** `rust-analyzer/interpretFunction`
**Request:** `TextDocumentPositionParams`
**Response:** `string`
Tries to evaluate the function using internal rust analyzer knowledge, without compiling
the code. Currently evaluates the function under cursor, but will give a runnable in
future. Highly experimental.
2022-03-31 07:50:33 -05:00
## View File Text
**Method:** `rust-analyzer/viewFileText`
**Request:** `TextDocumentIdentifier`
**Response:** `string`
Returns the text of a file as seen by the server.
This is for debugging file sync problems.
2021-05-21 17:03:36 -05:00
## View ItemTree
**Method:** `rust-analyzer/viewItemTree`
**Request:**
```typescript
interface ViewItemTreeParams {
textDocument: TextDocumentIdentifier,
}
```
**Response:** `string`
Returns a textual representation of the `ItemTree` of the currently open file, for debugging.
2021-05-11 09:45:51 -05:00
## View Crate Graph
**Method:** `rust-analyzer/viewCrateGraph`
2021-07-01 17:08:05 -05:00
**Request:**
```typescript
interface ViewCrateGraphParams {
full: boolean,
}
```
2021-05-11 09:45:51 -05:00
**Response:** `string`
Renders rust-analyzer's crate graph as an SVG image.
2021-07-01 17:08:05 -05:00
If `full` is `true` , the graph includes non-workspace crates (crates.io dependencies as well as sysroot crates).
2021-12-07 09:41:24 -06:00
## Shuffle Crate Graph
**Method:** `rust-analyzer/shuffleCrateGraph`
**Request:** `null`
Shuffles the crate IDs in the crate graph, for debugging purposes.
2020-05-24 10:01:40 -05:00
## Expand Macro
**Method:** `rust-analyzer/expandMacro`
**Request:**
```typescript
interface ExpandMacroParams {
textDocument: TextDocumentIdentifier,
2020-05-25 07:56:26 -05:00
position: Position,
2020-05-24 10:01:40 -05:00
}
```
**Response:**
```typescript
interface ExpandedMacro {
name: string,
expansion: string,
}
```
Expands macro call at a given position.
2020-05-27 05:20:47 -05:00
2020-06-03 06:34:11 -05:00
## Hover Actions
2021-03-09 03:02:20 -06:00
**Experimental Client Capability:** `{ "hoverActions": boolean }`
2020-06-03 06:34:11 -05:00
If this capability is set, `Hover` request returned from the server might contain an additional field, `actions` :
```typescript
interface Hover {
...
actions?: CommandLinkGroup[];
}
interface CommandLink extends Command {
/**
* A tooltip for the command, when represented in the UI.
*/
tooltip?: string;
}
interface CommandLinkGroup {
title?: string;
commands: CommandLink[];
}
```
Such actions on the client side are appended to a hover bottom as command links:
```
+-----------------------------+
| Hover content |
| |
+-----------------------------+
| _Action1_ | _Action2_ | < - first group , no TITLE
+-----------------------------+
| TITLE _Action1_ | _Action2_ | < - second group
+-----------------------------+
...
2020-07-01 07:57:59 -05:00
```
2020-11-12 19:48:07 -06:00
## Open Cargo.toml
2022-07-08 08:44:49 -05:00
**Upstream Issue:** https://github.com/rust-lang/rust-analyzer/issues/6462
2020-11-12 19:48:07 -06:00
2021-07-27 11:40:19 -05:00
**Experimental Server Capability:** `{ "openCargoToml": boolean }`
2020-11-12 19:48:07 -06:00
This request is sent from client to server to open the current project's Cargo.toml
**Method:** `experimental/openCargoToml`
**Request:** `OpenCargoTomlParams`
**Response:** `Location | null`
### Example
```rust
// Cargo.toml
[package]
// src/main.rs
/* cursor here*/
```
`experimental/openCargoToml` returns a single `Link` to the start of the `[package]` keyword.
2021-02-27 12:07:58 -06:00
## Related tests
This request is sent from client to server to get the list of tests for the specified position.
**Method:** `rust-analyzer/relatedTests`
2021-03-11 08:59:27 -06:00
**Request:** `TextDocumentPositionParams`
2021-02-27 12:07:58 -06:00
**Response:** `TestInfo[]`
```typescript
interface TestInfo {
runnable: Runnable;
}
```
2021-03-16 07:37:00 -05:00
2021-07-26 16:05:59 -05:00
## Hover Range
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/377
2021-07-26 16:05:59 -05:00
2021-07-27 16:50:26 -05:00
**Experimental Server Capability:** { "hoverRange": boolean }
2021-07-30 08:30:04 -05:00
This extension allows passing a `Range` as a `position` field of `HoverParams` .
The primary use-case is to use the hover request to show the type of the expression currently selected.
2021-07-26 16:05:59 -05:00
```typescript
2021-07-30 08:30:04 -05:00
interface HoverParams extends WorkDoneProgressParams {
textDocument: TextDocumentIdentifier;
position: Range | Position;
2021-07-26 16:05:59 -05:00
}
```
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` .
2021-07-26 17:15:40 -05:00
## Move Item
2021-03-16 07:37:00 -05:00
2022-07-08 08:44:49 -05:00
**Upstream Issue:** https://github.com/rust-lang/rust-analyzer/issues/6823
2021-03-16 07:37:00 -05:00
This request is sent from client to server to move item under cursor or selection in some direction.
2021-04-04 13:49:32 -05:00
**Method:** `experimental/moveItem`
2021-03-16 07:37:00 -05:00
**Request:** `MoveItemParams`
2021-04-13 13:32:45 -05:00
**Response:** `SnippetTextEdit[]`
2021-03-16 07:37:00 -05:00
```typescript
export interface MoveItemParams {
2021-07-30 08:30:04 -05:00
textDocument: TextDocumentIdentifier,
range: Range,
2021-03-16 07:37:00 -05:00
direction: Direction
}
export const enum Direction {
Up = "Up",
Down = "Down"
}
```
2021-02-23 06:03:31 -06:00
2021-05-19 05:28:58 -05:00
## Workspace Symbols Filtering
2021-02-23 06:03:31 -06:00
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/941
2021-02-23 06:03:31 -06:00
2021-05-19 05:28:58 -05:00
**Experimental Server Capability:** `{ "workspaceSymbolScopeKindFiltering": boolean }`
2021-02-23 06:03:31 -06:00
2021-05-19 05:28:58 -05:00
Extends the existing `workspace/symbol` request with ability to filter symbols by broad scope and kind of symbol.
If this capability is set, `workspace/symbol` parameter gains two new optional fields:
2021-02-23 06:03:31 -06:00
```typescript
2021-05-19 05:28:58 -05:00
interface WorkspaceSymbolParams {
/**
* Return only the symbols defined in the specified scope.
*/
2021-02-23 06:03:31 -06:00
searchScope?: WorkspaceSymbolSearchScope;
2021-05-19 05:28:58 -05:00
/**
* Return only the symbols of specified kinds.
*/
2021-02-23 06:03:31 -06:00
searchKind?: WorkspaceSymbolSearchKind;
2021-05-19 05:28:58 -05:00
...
2021-02-23 06:03:31 -06:00
}
const enum WorkspaceSymbolSearchScope {
2021-05-19 05:28:58 -05:00
Workspace = "workspace",
WorkspaceAndDependencies = "workspaceAndDependencies"
2021-02-23 06:03:31 -06:00
}
const enum WorkspaceSymbolSearchKind {
2021-05-19 05:28:58 -05:00
OnlyTypes = "onlyTypes",
AllSymbols = "allSymbols"
2021-02-23 06:03:31 -06:00
}
```
feat: gate custom clint-side commands behind capabilities
Some features of rust-analyzer requires support for custom commands on
the client side. Specifically, hover & code lens need this.
Stock LSP doesn't have a way for the server to know which client-side
commands are available. For that reason, we historically were just
sending the commands, not worrying whether the client supports then or
not.
That's not really great though, so in this PR we add infrastructure for
the client to explicitly opt-into custom commands, via `extensions`
field of the ClientCapabilities.
To preserve backwards compatability, if the client doesn't set the
field, we assume that it does support all custom commands. In the
future, we'll start treating that case as if the client doesn't support
commands.
So, if you maintain a rust-analyzer client and implement
`rust-analyzer/runSingle` and such, please also advertise this via a
capability.
2021-07-30 11:16:33 -05:00
## Client Commands
2021-07-30 11:50:39 -05:00
**Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/642
feat: gate custom clint-side commands behind capabilities
Some features of rust-analyzer requires support for custom commands on
the client side. Specifically, hover & code lens need this.
Stock LSP doesn't have a way for the server to know which client-side
commands are available. For that reason, we historically were just
sending the commands, not worrying whether the client supports then or
not.
That's not really great though, so in this PR we add infrastructure for
the client to explicitly opt-into custom commands, via `extensions`
field of the ClientCapabilities.
To preserve backwards compatability, if the client doesn't set the
field, we assume that it does support all custom commands. In the
future, we'll start treating that case as if the client doesn't support
commands.
So, if you maintain a rust-analyzer client and implement
`rust-analyzer/runSingle` and such, please also advertise this via a
capability.
2021-07-30 11:16:33 -05:00
**Experimental Client Capability:** `{ "commands?": ClientCommandOptions }`
Certain LSP types originating on the server, notably code lenses, embed commands.
Commands can be serviced either by the server or by the client.
However, the server doesn't know which commands are available on the client.
This extensions allows the client to communicate this info.
```typescript
export interface ClientCommandOptions {
2021-07-30 11:50:39 -05:00
/**
* The commands to be executed on the client
*/
commands: string[];
feat: gate custom clint-side commands behind capabilities
Some features of rust-analyzer requires support for custom commands on
the client side. Specifically, hover & code lens need this.
Stock LSP doesn't have a way for the server to know which client-side
commands are available. For that reason, we historically were just
sending the commands, not worrying whether the client supports then or
not.
That's not really great though, so in this PR we add infrastructure for
the client to explicitly opt-into custom commands, via `extensions`
field of the ClientCapabilities.
To preserve backwards compatability, if the client doesn't set the
field, we assume that it does support all custom commands. In the
future, we'll start treating that case as if the client doesn't support
commands.
So, if you maintain a rust-analyzer client and implement
`rust-analyzer/runSingle` and such, please also advertise this via a
capability.
2021-07-30 11:16:33 -05:00
}
```
2023-01-09 10:44:38 -06:00
## Colored Diagnostic Output
**Experimental Client Capability:** `{ "colorDiagnosticOutput": boolean }`
If this capability is set, the "full compiler diagnostics" provided by `checkOnSave`
will include ANSI color and style codes to render the diagnostic in a similar manner
as `cargo` . This is translated into `--message-format=json-diagnostic-rendered-ansi`
when flycheck is run, instead of the default `--message-format=json` .
The full compiler rendered diagnostics are included in the server response
regardless of this capability:
```typescript
// https://microsoft.github.io/language-server-protocol/specifications/specification-current#diagnostic
export interface Diagnostic {
...
data?: {
/**
* The human-readable compiler output as it would be printed to a terminal.
* Includes ANSI color and style codes if the client has set the experimental
* `colorDiagnosticOutput` capability.
*/
rendered?: string;
};
}
2023-04-02 21:04:32 -05:00
```
## Dependency Tree
2023-04-04 11:47:01 -05:00
**Method:** `rust-analyzer/fetchDependencyList`
2023-04-02 21:04:32 -05:00
**Request:**
```typescript
2023-04-13 11:06:43 -05:00
export interface FetchDependencyListParams {}
2023-04-02 21:04:32 -05:00
```
2023-04-26 09:47:34 -05:00
**Response:**
2023-04-02 21:04:32 -05:00
```typescript
2023-04-13 11:06:43 -05:00
export interface FetchDependencyListResult {
2023-04-02 21:04:32 -05:00
crates: {
name: string;
version: string;
path: string;
}[];
}
```
2023-04-26 09:47:34 -05:00
Returns all crates from this workspace, so it can be used create a viewTree to help navigate the dependency tree.
2023-07-07 22:03:55 -05:00
## View Recursive Memory Layout
2023-07-08 11:25:54 -05:00
**Method:** `rust-analyzer/viewRecursiveMemoryLayout`
2023-07-07 22:03:55 -05:00
2023-07-08 11:25:54 -05:00
**Request:** `TextDocumentPositionParams`
2023-07-07 22:03:55 -05:00
**Response:**
```typescript
export interface RecursiveMemoryLayoutNode = {
/// Name of the item, or [ROOT], `.n` for tuples
item_name: string;
/// Full name of the type (type aliases are ignored)
typename: string;
/// Size of the type in bytes
size: number;
/// Alignment of the type in bytes
alignment: number;
/// Offset of the type relative to its parent (or 0 if its the root)
offset: number;
/// Index of the node's parent (or -1 if its the root)
parent_idx: number;
/// Index of the node's children (or -1 if it does not have children)
children_start: number;
/// Number of child nodes (unspecified it does not have children)
children_len: number;
};
export interface RecursiveMemoryLayout = {
nodes: RecursiveMemoryLayoutNode[];
};
```
Returns a vector of nodes representing items in the datatype as a tree, `RecursiveMemoryLayout::nodes[0]` is the root node.
If `RecursiveMemoryLayout::nodes::length == 0` we could not find a suitable type.
Generic Types do not give anything because they are incomplete. Fully specified generic types do not give anything if they are selected directly but do work when a child of other types [this is consistent with other behavior ](https://github.com/rust-lang/rust-analyzer/issues/15010 ).
### Unresolved questions:
- How should enums/unions be represented? currently they do not produce any children because they have multiple distinct sets of children.
- Should niches be represented? currently they are not reported.
- A visual representation of the memory layout is not specified, see the provided implementation for an example, however it may not translate well to terminal based editors or other such things.