diff options
author | Jeremy A. Kolb <[email protected]> | 2019-01-11 20:16:55 +0000 |
---|---|---|
committer | Jeremy A. Kolb <[email protected]> | 2019-01-11 20:16:55 +0000 |
commit | faf003763516074c619cee7e43ca8bc365540c92 (patch) | |
tree | 54407f422a1a5b969b659f74fe4608be622ec596 /editors | |
parent | 738c958a044361dc84a0f27e57b40f66a5815990 (diff) |
Code lens support for running tests
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/commands/index.ts | 2 | ||||
-rw-r--r-- | editors/code/src/commands/run_single.ts | 63 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 3 |
3 files changed, 68 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 | ||
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 4acd54d90..acbb1f734 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -55,6 +55,9 @@ export function activate(context: vscode.ExtensionContext) { | |||
55 | ); | 55 | ); |
56 | overrideCommand('type', commands.onEnter.handle); | 56 | overrideCommand('type', commands.onEnter.handle); |
57 | 57 | ||
58 | // Unlike the above this does not send requests to the language server | ||
59 | registerCommand('ra-lsp.run-single', commands.runSingle.handle); | ||
60 | |||
58 | // Notifications are events triggered by the language server | 61 | // Notifications are events triggered by the language server |
59 | const allNotifications: Iterable< | 62 | const allNotifications: Iterable< |
60 | [string, lc.GenericNotificationHandler] | 63 | [string, lc.GenericNotificationHandler] |