From 4bd61430622fcd289de1374c9e7c8d9260f38cf3 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 18 Mar 2019 21:13:49 +0100 Subject: Prefer installing `cargo-watch` via Task API This gives us much more fine-grained stdout buffering and ANSI terminal colors. --- editors/code/src/extension.ts | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'editors') diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index d5b496b1b..f06c5445d 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -155,30 +155,21 @@ async function askToCargoWatch() { return; } - try { - // await vscode.tasks.executeTask(createTask({label: '', bin: 'cargo', args: ['install', 'cargo-watch'], env: {}})); - - const channel = vscode.window.createOutputChannel('cargo-watch'); - channel.show(false); - const sup = spawn('cargo', ['install', 'cargo-watch']); - sup.stderr.on('data', chunk => { - const output = new TextDecoder().decode(chunk); - channel.append(output); - }); - await new Promise((resolve, reject) => { - sup.on('close', (code, signal) => { - if (code === 0) { - resolve(code); - } else { - reject(code); - } - }); + const label = 'install-cargo-watch'; + const taskFinished = new Promise((resolve, reject) => { + let disposable = vscode.tasks.onDidEndTask(({ execution }) => { + if (execution.task.name === label) { + disposable.dispose(); + resolve(); + }; }); - channel.dispose(); - } catch (err) { - vscode.window.showErrorMessage( - `Couldn't install \`cargo-watch\`: ${err.message}` - ); + }); + + vscode.tasks.executeTask(createTask({ label, bin: 'cargo', args: ['install', 'cargo-watch'], env: {} })); + await taskFinished; + const { stderr } = await util.promisify(exec)('cargo watch --version').catch(e => e); + if (stderr !== '') { + vscode.window.showErrorMessage(`Couldn't install \`cargo-\`watch: ${stderr}`); return; } } -- cgit v1.2.3