diff options
| author | Veetaha <[email protected]> | 2020-02-24 22:56:38 +0000 |
|---|---|---|
| committer | Veetaha <[email protected]> | 2020-02-24 22:56:38 +0000 |
| commit | 8a8a4d08ef6c695cce04f5e306fad83cc9abddcd (patch) | |
| tree | 7f6c79aaf8afbaa48f7048351d4b3dc82ab05fdb | |
| parent | d6a96a90f417d48e6391d2233abf752988c04f1a (diff) | |
vscode: migrate runnables to rust-analyzer-api.ts
| -rw-r--r-- | editors/code/src/commands/runnables.ts | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 7919997ce..06b513466 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
| 2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
| 3 | import * as ra from '../rust-analyzer-api'; | ||
| 3 | 4 | ||
| 4 | import { Ctx, Cmd } from '../ctx'; | 5 | import { Ctx, Cmd } from '../ctx'; |
| 5 | 6 | ||
| @@ -14,16 +15,13 @@ export function run(ctx: Ctx): Cmd { | |||
| 14 | const textDocument: lc.TextDocumentIdentifier = { | 15 | const textDocument: lc.TextDocumentIdentifier = { |
| 15 | uri: editor.document.uri.toString(), | 16 | uri: editor.document.uri.toString(), |
| 16 | }; | 17 | }; |
| 17 | const params: RunnablesParams = { | 18 | |
| 19 | const runnables = await client.sendRequest(ra.runnables, { | ||
| 18 | textDocument, | 20 | textDocument, |
| 19 | position: client.code2ProtocolConverter.asPosition( | 21 | position: client.code2ProtocolConverter.asPosition( |
| 20 | editor.selection.active, | 22 | editor.selection.active, |
| 21 | ), | 23 | ), |
| 22 | }; | 24 | }); |
| 23 | const runnables = await client.sendRequest<Runnable[]>( | ||
| 24 | 'rust-analyzer/runnables', | ||
| 25 | params, | ||
| 26 | ); | ||
| 27 | const items: RunnableQuickPick[] = []; | 25 | const items: RunnableQuickPick[] = []; |
| 28 | if (prevRunnable) { | 26 | if (prevRunnable) { |
| 29 | items.push(prevRunnable); | 27 | items.push(prevRunnable); |
| @@ -48,7 +46,7 @@ export function run(ctx: Ctx): Cmd { | |||
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | export function runSingle(ctx: Ctx): Cmd { | 48 | export function runSingle(ctx: Ctx): Cmd { |
| 51 | return async (runnable: Runnable) => { | 49 | return async (runnable: ra.Runnable) => { |
| 52 | const editor = ctx.activeRustEditor; | 50 | const editor = ctx.activeRustEditor; |
| 53 | if (!editor) return; | 51 | if (!editor) return; |
| 54 | 52 | ||
| @@ -64,26 +62,13 @@ export function runSingle(ctx: Ctx): Cmd { | |||
| 64 | }; | 62 | }; |
| 65 | } | 63 | } |
| 66 | 64 | ||
| 67 | interface RunnablesParams { | ||
| 68 | textDocument: lc.TextDocumentIdentifier; | ||
| 69 | position?: lc.Position; | ||
| 70 | } | ||
| 71 | |||
| 72 | interface Runnable { | ||
| 73 | label: string; | ||
| 74 | bin: string; | ||
| 75 | args: string[]; | ||
| 76 | env: { [index: string]: string }; | ||
| 77 | cwd?: string; | ||
| 78 | } | ||
| 79 | |||
| 80 | class RunnableQuickPick implements vscode.QuickPickItem { | 65 | class RunnableQuickPick implements vscode.QuickPickItem { |
| 81 | public label: string; | 66 | public label: string; |
| 82 | public description?: string | undefined; | 67 | public description?: string | undefined; |
| 83 | public detail?: string | undefined; | 68 | public detail?: string | undefined; |
| 84 | public picked?: boolean | undefined; | 69 | public picked?: boolean | undefined; |
| 85 | 70 | ||
| 86 | constructor(public runnable: Runnable) { | 71 | constructor(public runnable: ra.Runnable) { |
| 87 | this.label = runnable.label; | 72 | this.label = runnable.label; |
| 88 | } | 73 | } |
| 89 | } | 74 | } |
| @@ -96,7 +81,7 @@ interface CargoTaskDefinition extends vscode.TaskDefinition { | |||
| 96 | env?: { [key: string]: string }; | 81 | env?: { [key: string]: string }; |
| 97 | } | 82 | } |
| 98 | 83 | ||
| 99 | function createTask(spec: Runnable): vscode.Task { | 84 | function createTask(spec: ra.Runnable): vscode.Task { |
| 100 | const TASK_SOURCE = 'Rust'; | 85 | const TASK_SOURCE = 'Rust'; |
| 101 | const definition: CargoTaskDefinition = { | 86 | const definition: CargoTaskDefinition = { |
| 102 | type: 'cargo', | 87 | type: 'cargo', |
