aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2019-01-11 20:16:55 +0000
committerJeremy A. Kolb <[email protected]>2019-01-11 20:16:55 +0000
commitfaf003763516074c619cee7e43ca8bc365540c92 (patch)
tree54407f422a1a5b969b659f74fe4608be622ec596 /editors/code/src/commands
parent738c958a044361dc84a0f27e57b40f66a5815990 (diff)
Code lens support for running tests
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
2 files changed, 65 insertions, 0 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index 33e2b34a2..c8bb55591 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -4,6 +4,7 @@ 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';
7import * as runnables from './runnables'; 8import * as runnables from './runnables';
8import * as syntaxTree from './syntaxTree'; 9import * as syntaxTree from './syntaxTree';
9 10
@@ -13,6 +14,7 @@ export {
13 joinLines, 14 joinLines,
14 matchingBrace, 15 matchingBrace,
15 parentModule, 16 parentModule,
17 runSingle,
16 runnables, 18 runnables,
17 syntaxTree, 19 syntaxTree,
18 onEnter 20 onEnter
diff --git a/editors/code/src/commands/run_single.ts b/editors/code/src/commands/run_single.ts
new file mode 100644
index 000000000..855bcdb06
--- /dev/null
+++ b/editors/code/src/commands/run_single.ts
@@ -0,0 +1,63 @@
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