aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/runnables.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/runnables.ts')
-rw-r--r--editors/code/src/commands/runnables.ts76
1 files changed, 38 insertions, 38 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 45c16497d..37db6ea10 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -1,10 +1,10 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient' 2import * as lc from 'vscode-languageclient';
3import { Server } from '../server'; 3import { Server } from '../server';
4 4
5interface RunnablesParams { 5interface RunnablesParams {
6 textDocument: lc.TextDocumentIdentifier, 6 textDocument: lc.TextDocumentIdentifier;
7 position?: lc.Position, 7 position?: lc.Position;
8} 8}
9 9
10interface Runnable { 10interface Runnable {
@@ -12,17 +12,17 @@ interface Runnable {
12 label: string; 12 label: string;
13 bin: string; 13 bin: string;
14 args: string[]; 14 args: string[];
15 env: { [index: string]: string }, 15 env: { [index: string]: string };
16} 16}
17 17
18class RunnableQuickPick implements vscode.QuickPickItem { 18class RunnableQuickPick implements vscode.QuickPickItem {
19 label: string; 19 public label: string;
20 description?: string | undefined; 20 public description?: string | undefined;
21 detail?: string | undefined; 21 public detail?: string | undefined;
22 picked?: boolean | undefined; 22 public picked?: boolean | undefined;
23 23
24 constructor(public runnable: Runnable) { 24 constructor(public runnable: Runnable) {
25 this.label = runnable.label 25 this.label = runnable.label;
26 } 26 }
27} 27}
28 28
@@ -30,59 +30,59 @@ interface CargoTaskDefinition extends vscode.TaskDefinition {
30 type: 'cargo'; 30 type: 'cargo';
31 label: string; 31 label: string;
32 command: string; 32 command: string;
33 args: Array<string>; 33 args: string[];
34 env?: { [key: string]: string }; 34 env?: { [key: string]: string };
35} 35}
36 36
37function createTask(spec: Runnable): vscode.Task { 37function createTask(spec: Runnable): vscode.Task {
38 const TASK_SOURCE = 'Rust'; 38 const TASK_SOURCE = 'Rust';
39 let definition: CargoTaskDefinition = { 39 const definition: CargoTaskDefinition = {
40 type: 'cargo', 40 type: 'cargo',
41 label: 'cargo', 41 label: 'cargo',
42 command: spec.bin, 42 command: spec.bin,
43 args: spec.args, 43 args: spec.args,
44 env: spec.env 44 env: spec.env,
45 } 45 };
46 46
47 let execCmd = `${definition.command} ${definition.args.join(' ')}`; 47 const execCmd = `${definition.command} ${definition.args.join(' ')}`;
48 let execOption: vscode.ShellExecutionOptions = { 48 const execOption: vscode.ShellExecutionOptions = {
49 cwd: '.', 49 cwd: '.',
50 env: definition.env, 50 env: definition.env,
51 }; 51 };
52 let exec = new vscode.ShellExecution(`clear; ${execCmd}`, execOption); 52 const exec = new vscode.ShellExecution(`clear; ${execCmd}`, execOption);
53 53
54 let f = vscode.workspace.workspaceFolders![0] 54 const f = vscode.workspace.workspaceFolders![0];
55 let t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']); 55 const t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']);
56 return t; 56 return t;
57} 57}
58 58
59let prevRunnable: RunnableQuickPick | undefined = undefined 59let prevRunnable: RunnableQuickPick | undefined;
60export async function handle() { 60export async function handle() {
61 let editor = vscode.window.activeTextEditor 61 const editor = vscode.window.activeTextEditor;
62 if (editor == null || editor.document.languageId != "rust") return 62 if (editor == null || editor.document.languageId != 'rust') { return; }
63 let textDocument: lc.TextDocumentIdentifier = { 63 const textDocument: lc.TextDocumentIdentifier = {
64 uri: editor.document.uri.toString() 64 uri: editor.document.uri.toString(),
65 } 65 };
66 let params: RunnablesParams = { 66 const params: RunnablesParams = {
67 textDocument, 67 textDocument,
68 position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active) 68 position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active),
69 } 69 };
70 let runnables = await Server.client.sendRequest<Runnable[]>('m/runnables', params) 70 const runnables = await Server.client.sendRequest<Runnable[]>('m/runnables', params);
71 let items: RunnableQuickPick[] = [] 71 const items: RunnableQuickPick[] = [];
72 if (prevRunnable) { 72 if (prevRunnable) {
73 items.push(prevRunnable) 73 items.push(prevRunnable);
74 } 74 }
75 for (let r of runnables) { 75 for (const r of runnables) {
76 if (prevRunnable && JSON.stringify(prevRunnable.runnable) == JSON.stringify(r)) { 76 if (prevRunnable && JSON.stringify(prevRunnable.runnable) == JSON.stringify(r)) {
77 continue 77 continue;
78 } 78 }
79 items.push(new RunnableQuickPick(r)) 79 items.push(new RunnableQuickPick(r));
80 } 80 }
81 let item = await vscode.window.showQuickPick(items) 81 const item = await vscode.window.showQuickPick(items);
82 if (item) { 82 if (item) {
83 item.detail = "rerun" 83 item.detail = 'rerun';
84 prevRunnable = item 84 prevRunnable = item;
85 let task = createTask(item.runnable) 85 const task = createTask(item.runnable);
86 return await vscode.tasks.executeTask(task) 86 return await vscode.tasks.executeTask(task);
87 } 87 }
88} 88}