aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
authorVeetaha <[email protected]>2020-02-24 22:56:38 +0000
committerVeetaha <[email protected]>2020-02-24 22:56:38 +0000
commit8a8a4d08ef6c695cce04f5e306fad83cc9abddcd (patch)
tree7f6c79aaf8afbaa48f7048351d4b3dc82ab05fdb /editors/code/src
parentd6a96a90f417d48e6391d2233abf752988c04f1a (diff)
vscode: migrate runnables to rust-analyzer-api.ts
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands/runnables.ts29
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 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import * as ra from '../rust-analyzer-api';
3 4
4import { Ctx, Cmd } from '../ctx'; 5import { 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
50export function runSingle(ctx: Ctx): Cmd { 48export 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
67interface RunnablesParams {
68 textDocument: lc.TextDocumentIdentifier;
69 position?: lc.Position;
70}
71
72interface Runnable {
73 label: string;
74 bin: string;
75 args: string[];
76 env: { [index: string]: string };
77 cwd?: string;
78}
79
80class RunnableQuickPick implements vscode.QuickPickItem { 65class 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
99function createTask(spec: Runnable): vscode.Task { 84function 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',