aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r--editors/code/src/commands/index.ts2
-rw-r--r--editors/code/src/commands/run_single.ts63
-rw-r--r--editors/code/src/commands/runnables.ts16
3 files changed, 16 insertions, 65 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index c8bb55591..33e2b34a2 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -4,7 +4,6 @@ import * as joinLines from './join_lines';
4import * as matchingBrace from './matching_brace'; 4import * as matchingBrace from './matching_brace';
5import * as onEnter from './on_enter'; 5import * as onEnter from './on_enter';
6import * as parentModule from './parent_module'; 6import * as parentModule from './parent_module';
7import * as runSingle from './run_single';
8import * as runnables from './runnables'; 7import * as runnables from './runnables';
9import * as syntaxTree from './syntaxTree'; 8import * as syntaxTree from './syntaxTree';
10 9
@@ -14,7 +13,6 @@ export {
14 joinLines, 13 joinLines,
15 matchingBrace, 14 matchingBrace,
16 parentModule, 15 parentModule,
17 runSingle,
18 runnables, 16 runnables,
19 syntaxTree, 17 syntaxTree,
20 onEnter 18 onEnter
diff --git a/editors/code/src/commands/run_single.ts b/editors/code/src/commands/run_single.ts
deleted file mode 100644
index 855bcdb06..000000000
--- a/editors/code/src/commands/run_single.ts
+++ /dev/null
@@ -1,63 +0,0 @@
1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient';
3
4interface Runnable {
5 range: lc.Range;
6 label: string;
7 bin: string;
8 args: string[];
9 env: { [index: string]: string };
10}
11
12interface CargoTaskDefinition extends vscode.TaskDefinition {
13 type: 'cargo';
14 label: string;
15 command: string;
16 args: string[];
17 env?: { [key: string]: string };
18}
19
20function createTask(spec: Runnable): vscode.Task {
21 const TASK_SOURCE = 'Rust';
22 const definition: CargoTaskDefinition = {
23 type: 'cargo',
24 label: 'cargo',
25 command: spec.bin,
26 args: spec.args,
27 env: spec.env
28 };
29
30 const execOption: vscode.ShellExecutionOptions = {
31 cwd: '.',
32 env: definition.env
33 };
34 const exec = new vscode.ShellExecution(definition.command, definition.args, execOption);
35
36 const f = vscode.workspace.workspaceFolders![0];
37 const t = new vscode.Task(
38 definition,
39 f,
40 definition.label,
41 TASK_SOURCE,
42 exec,
43 ['$rustc']
44 );
45 t.presentationOptions.clear = true
46 return t;
47}
48
49export async function handle(runnable: Runnable) {
50 const editor = vscode.window.activeTextEditor;
51 if (editor == null || editor.document.languageId !== 'rust') {
52 return;
53 }
54
55 const task = createTask(runnable);
56 task.group = vscode.TaskGroup.Build;
57 task.presentationOptions = {
58 reveal: vscode.TaskRevealKind.Always,
59 panel: vscode.TaskPanelKind.Dedicated,
60 };
61
62 return vscode.tasks.executeTask(task);
63} \ No newline at end of file
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index be17c8944..f9a4e2fc9 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -103,3 +103,19 @@ export async function handle() {
103 return await vscode.tasks.executeTask(task); 103 return await vscode.tasks.executeTask(task);
104 } 104 }
105} 105}
106
107export async function handleSingle(runnable: Runnable) {
108 const editor = vscode.window.activeTextEditor;
109 if (editor == null || editor.document.languageId !== 'rust') {
110 return;
111 }
112
113 const task = createTask(runnable);
114 task.group = vscode.TaskGroup.Build;
115 task.presentationOptions = {
116 reveal: vscode.TaskRevealKind.Always,
117 panel: vscode.TaskPanelKind.Dedicated,
118 };
119
120 return vscode.tasks.executeTask(task);
121} \ No newline at end of file