diff options
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/index.ts | 2 | ||||
-rw-r--r-- | editors/code/src/commands/run_single.ts | 63 |
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'; | |||
4 | import * as matchingBrace from './matching_brace'; | 4 | import * as matchingBrace from './matching_brace'; |
5 | import * as onEnter from './on_enter'; | 5 | import * as onEnter from './on_enter'; |
6 | import * as parentModule from './parent_module'; | 6 | import * as parentModule from './parent_module'; |
7 | import * as runSingle from './run_single'; | ||
7 | import * as runnables from './runnables'; | 8 | import * as runnables from './runnables'; |
8 | import * as syntaxTree from './syntaxTree'; | 9 | import * 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 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | import * as lc from 'vscode-languageclient'; | ||
3 | |||
4 | interface Runnable { | ||
5 | range: lc.Range; | ||
6 | label: string; | ||
7 | bin: string; | ||
8 | args: string[]; | ||
9 | env: { [index: string]: string }; | ||
10 | } | ||
11 | |||
12 | interface CargoTaskDefinition extends vscode.TaskDefinition { | ||
13 | type: 'cargo'; | ||
14 | label: string; | ||
15 | command: string; | ||
16 | args: string[]; | ||
17 | env?: { [key: string]: string }; | ||
18 | } | ||
19 | |||
20 | function 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 | |||
49 | export 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 | ||