about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorIgor Matuszewski <Xanewok@gmail.com>2019-03-18 21:13:49 +0100
committerIgor Matuszewski <Xanewok@gmail.com>2019-03-18 21:13:49 +0100
commit4bd61430622fcd289de1374c9e7c8d9260f38cf3 (patch)
tree06db4faf928ebe8ac2414bd80115c9fc0c718242 /editors/code
parent21b73f984433ca6ca1500826af59f8dd8bc22618 (diff)
downloadrust-4bd61430622fcd289de1374c9e7c8d9260f38cf3.tar.gz
rust-4bd61430622fcd289de1374c9e7c8d9260f38cf3.zip
Prefer installing `cargo-watch` via Task API
This gives us much more fine-grained stdout buffering and ANSI terminal colors.
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/extension.ts37
1 files changed, 14 insertions, 23 deletions
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index d5b496b1b3f..f06c5445d4c 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;
         }
     }