aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands
diff options
context:
space:
mode:
authorIgor Matuszewski <[email protected]>2019-03-18 21:30:23 +0000
committerIgor Matuszewski <[email protected]>2019-03-18 21:30:23 +0000
commit60cac299640912ad1ad75644bfa0088d7ba6e367 (patch)
tree50aab7bd4a56995fa965ebd4b53d70506a8b9b4d /editors/code/src/commands
parent5c3cc8c95f392c523bb638d78e0217780d6e8476 (diff)
Separate out the interactive cargo watch procedure
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r--editors/code/src/commands/runnables.ts68
1 files changed, 67 insertions, 1 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 23fd280b4..285afaaf6 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -1,5 +1,8 @@
1import { exec } from 'child_process';
2import * as util from 'util';
1import * as vscode from 'vscode'; 3import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 4import * as lc from 'vscode-languageclient';
5
3import { Server } from '../server'; 6import { Server } from '../server';
4 7
5interface RunnablesParams { 8interface RunnablesParams {
@@ -33,7 +36,7 @@ interface CargoTaskDefinition extends vscode.TaskDefinition {
33 env?: { [key: string]: string }; 36 env?: { [key: string]: string };
34} 37}
35 38
36export function createTask(spec: Runnable): vscode.Task { 39function createTask(spec: Runnable): vscode.Task {
37 const TASK_SOURCE = 'Rust'; 40 const TASK_SOURCE = 'Rust';
38 const definition: CargoTaskDefinition = { 41 const definition: CargoTaskDefinition = {
39 type: 'cargo', 42 type: 'cargo',
@@ -143,3 +146,66 @@ export const autoCargoWatchTask: vscode.Task = {
143 runOn: 2 // RunOnOptions.folderOpen 146 runOn: 2 // RunOnOptions.folderOpen
144 } as unknown) as vscode.RunOptions 147 } as unknown) as vscode.RunOptions
145}; 148};
149
150/**
151 * Interactively asks the user whether we should run `cargo check` in order to
152 * provide inline diagnostics; the user is met with a series of dialog boxes
153 * that, when accepted, allow us to `cargo install cargo-watch` and then run it.
154 */
155export async function interactivelyStartCargoWatch() {
156 const execAsync = util.promisify(exec);
157
158 const watch = await vscode.window.showInformationMessage(
159 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
160 'yes',
161 'no'
162 );
163 if (watch === 'no') {
164 return;
165 }
166
167 const { stderr } = await execAsync('cargo watch --version').catch(e => e);
168 if (stderr.includes('no such subcommand: `watch`')) {
169 const msg =
170 'The `cargo-watch` subcommand is not installed. Install? (takes ~1-2 minutes)';
171 const install = await vscode.window.showInformationMessage(
172 msg,
173 'yes',
174 'no'
175 );
176 if (install === 'no') {
177 return;
178 }
179
180 const label = 'install-cargo-watch';
181 const taskFinished = new Promise((resolve, reject) => {
182 let disposable = vscode.tasks.onDidEndTask(({ execution }) => {
183 if (execution.task.name === label) {
184 disposable.dispose();
185 resolve();
186 }
187 });
188 });
189
190 vscode.tasks.executeTask(
191 createTask({
192 label,
193 bin: 'cargo',
194 args: ['install', 'cargo-watch'],
195 env: {}
196 })
197 );
198 await taskFinished;
199 const { stderr } = await execAsync('cargo watch --version').catch(
200 e => e
201 );
202 if (stderr !== '') {
203 vscode.window.showErrorMessage(
204 `Couldn't install \`cargo-\`watch: ${stderr}`
205 );
206 return;
207 }
208 }
209
210 vscode.tasks.executeTask(autoCargoWatchTask);
211}