diff options
Diffstat (limited to 'editors/code/src/run.ts')
-rw-r--r-- | editors/code/src/run.ts | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index bb060cfe1..7ecdeeeaf 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import * as ra from './lsp_ext'; | 3 | import * as ra from './lsp_ext'; |
4 | import * as toolchain from "./toolchain"; | 4 | import * as tasks from './tasks'; |
5 | 5 | ||
6 | import { Ctx } from './ctx'; | 6 | import { Ctx } from './ctx'; |
7 | import { makeDebugConfig } from './debug'; | 7 | import { makeDebugConfig } from './debug'; |
8 | import { Config } from './config'; | ||
8 | 9 | ||
9 | const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }]; | 10 | const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }]; |
10 | 11 | ||
@@ -95,52 +96,28 @@ export class RunnableQuickPick implements vscode.QuickPickItem { | |||
95 | } | 96 | } |
96 | } | 97 | } |
97 | 98 | ||
98 | interface CargoTaskDefinition extends vscode.TaskDefinition { | 99 | export async function createTask(runnable: ra.Runnable, config: Config): Promise<vscode.Task> { |
99 | type: 'cargo'; | 100 | if (runnable.kind !== "cargo") { |
100 | label: string; | 101 | // rust-analyzer supports only one kind, "cargo" |
101 | command: string; | 102 | // do not use tasks.TASK_TYPE here, these are completely different meanings. |
102 | args: string[]; | ||
103 | env?: { [key: string]: string }; | ||
104 | } | ||
105 | |||
106 | export function createTask(runnable: ra.Runnable): vscode.Task { | ||
107 | const TASK_SOURCE = 'Rust'; | ||
108 | 103 | ||
109 | let command; | 104 | throw `Unexpected runnable kind: ${runnable.kind}`; |
110 | switch (runnable.kind) { | ||
111 | case "cargo": command = toolchain.getPathForExecutable("cargo"); | ||
112 | } | 105 | } |
106 | |||
113 | const args = [...runnable.args.cargoArgs]; // should be a copy! | 107 | const args = [...runnable.args.cargoArgs]; // should be a copy! |
114 | if (runnable.args.executableArgs.length > 0) { | 108 | if (runnable.args.executableArgs.length > 0) { |
115 | args.push('--', ...runnable.args.executableArgs); | 109 | args.push('--', ...runnable.args.executableArgs); |
116 | } | 110 | } |
117 | const definition: CargoTaskDefinition = { | 111 | const definition: tasks.CargoTaskDefinition = { |
118 | type: 'cargo', | 112 | type: tasks.TASK_TYPE, |
119 | label: runnable.label, | 113 | command: args[0], // run, test, etc... |
120 | command, | 114 | args: args.slice(1), |
121 | args, | 115 | cwd: runnable.args.workspaceRoot, |
122 | env: Object.assign({}, process.env as { [key: string]: string }, { "RUST_BACKTRACE": "short" }), | 116 | env: Object.assign({}, process.env as { [key: string]: string }, { "RUST_BACKTRACE": "short" }), |
123 | }; | 117 | }; |
124 | 118 | ||
125 | const execOption: vscode.ShellExecutionOptions = { | 119 | const cargoTask = await tasks.buildCargoTask(definition, runnable.label, args, config.cargoRunner); |
126 | cwd: runnable.args.workspaceRoot || '.', | 120 | cargoTask.presentationOptions.clear = true; |
127 | env: definition.env, | 121 | |
128 | }; | 122 | return cargoTask; |
129 | const exec = new vscode.ShellExecution( | ||
130 | definition.command, | ||
131 | definition.args, | ||
132 | execOption, | ||
133 | ); | ||
134 | |||
135 | const f = vscode.workspace.workspaceFolders![0]; | ||
136 | const t = new vscode.Task( | ||
137 | definition, | ||
138 | f, | ||
139 | definition.label, | ||
140 | TASK_SOURCE, | ||
141 | exec, | ||
142 | ['$rustc'], | ||
143 | ); | ||
144 | t.presentationOptions.clear = true; | ||
145 | return t; | ||
146 | } | 123 | } |