Skip to content

Commit a83ab82

Browse files
committed
Spec better runnables
1 parent 0303982 commit a83ab82

File tree

4 files changed

+49
-38
lines changed

4 files changed

+49
-38
lines changed

crates/rust-analyzer/src/caps.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
8787
"ssr": true,
8888
"onEnter": true,
8989
"parentModule": true,
90+
"runnables": {
91+
"kinds": [ "cargo" ],
92+
},
9093
})),
9194
}
9295
}

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub enum Runnables {}
110110
impl Request for Runnables {
111111
type Params = RunnablesParams;
112112
type Result = Vec<Runnable>;
113-
const METHOD: &'static str = "rust-analyzer/runnables";
113+
const METHOD: &'static str = "experimental/runnables";
114114
}
115115

116116
#[derive(Serialize, Deserialize, Debug)]

docs/dev/lsp-extensions.md

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,50 @@ Moreover, it would be cool if editors didn't need to implement even basic langua
311311
This is how `SelectionRange` request works.
312312
* Alternatively, should we perhaps flag certain `SelectionRange`s as being brace pairs?
313313

314+
## Runnables
315+
316+
**Issue:** https://github.com/microsoft/language-server-protocol/issues/944
317+
318+
**Server Capability:** `{ "runnables": { "kinds": string[] } }`
319+
320+
This request is send from client to server to get the list of things that can be run (tests, binaries, `cargo check -p`).
321+
322+
**Method:** `experimental/runnables`
323+
324+
**Request:**
325+
326+
```typescript
327+
interface RunnablesParams {
328+
textDocument: TextDocumentIdentifier;
329+
/// If null, compute runnables for the whole file.
330+
position?: Position;
331+
}
332+
```
333+
334+
**Response:** `Runnable[]`
335+
336+
```typescript
337+
interface Runnable {
338+
label: string;
339+
/// If this Runnable is associated with a specific function/module, etc, the location of this item
340+
location?: LocationLink;
341+
/// Running things is necessary technology specific, `kind` needs to be advertised via server capabilities,
342+
// the type of `args` is specific to `kind`. The actual running is handled by the client.
343+
kind: string;
344+
args: any;
345+
}
346+
```
347+
348+
rust-analyzer supports only one `kind`, `"cargo"`. The `args` for `"cargo"` look like this:
349+
350+
```typescript
351+
{
352+
workspaceRoot?: string;
353+
cargoArgs: string[];
354+
executableArgs: string[];
355+
}
356+
```
357+
314358
## Analyzer Status
315359

316360
**Method:** `rust-analyzer/analyzerStatus`
@@ -399,39 +443,3 @@ interface InlayHint {
399443
label: string,
400444
}
401445
```
402-
403-
## Runnables
404-
405-
**Method:** `rust-analyzer/runnables`
406-
407-
This request is send from client to server to get the list of things that can be run (tests, binaries, `cargo check -p`).
408-
Note that we plan to move this request to `experimental/runnables`, as it is not really Rust-specific, but the current API is not necessary the right one.
409-
Upstream issue: https://github.com/microsoft/language-server-protocol/issues/944
410-
411-
**Request:**
412-
413-
```typescript
414-
interface RunnablesParams {
415-
textDocument: TextDocumentIdentifier;
416-
/// If null, compute runnables for the whole file.
417-
position?: Position;
418-
}
419-
```
420-
421-
**Response:** `Runnable[]`
422-
423-
```typescript
424-
interface Runnable {
425-
/// The range this runnable is applicable for.
426-
range: lc.Range;
427-
/// The label to show in the UI.
428-
label: string;
429-
/// The following fields describe a process to spawn.
430-
kind: "cargo" | "rustc" | "rustup";
431-
args: string[];
432-
/// Args for cargo after `--`.
433-
extraArgs: string[];
434-
env: { [key: string]: string };
435-
cwd: string | null;
436-
}
437-
```

editors/code/src/lsp_ext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface Runnable {
5656
executableArgs: string[];
5757
};
5858
}
59-
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("rust-analyzer/runnables");
59+
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables");
6060

6161
export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;
6262

0 commit comments

Comments
 (0)