mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Prefer installing cargo-watch
via Task API
This gives us much more fine-grained stdout buffering and ANSI terminal colors.
This commit is contained in:
parent
21b73f9844
commit
4bd6143062
1 changed files with 14 additions and 23 deletions
|
@ -155,30 +155,21 @@ async function askToCargoWatch() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const label = 'install-cargo-watch';
|
||||||
// await vscode.tasks.executeTask(createTask({label: '', bin: 'cargo', args: ['install', 'cargo-watch'], env: {}}));
|
const taskFinished = new Promise((resolve, reject) => {
|
||||||
|
let disposable = vscode.tasks.onDidEndTask(({ execution }) => {
|
||||||
|
if (execution.task.name === label) {
|
||||||
|
disposable.dispose();
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const channel = vscode.window.createOutputChannel('cargo-watch');
|
vscode.tasks.executeTask(createTask({ label, bin: 'cargo', args: ['install', 'cargo-watch'], env: {} }));
|
||||||
channel.show(false);
|
await taskFinished;
|
||||||
const sup = spawn('cargo', ['install', 'cargo-watch']);
|
const { stderr } = await util.promisify(exec)('cargo watch --version').catch(e => e);
|
||||||
sup.stderr.on('data', chunk => {
|
if (stderr !== '') {
|
||||||
const output = new TextDecoder().decode(chunk);
|
vscode.window.showErrorMessage(`Couldn't install \`cargo-\`watch: ${stderr}`);
|
||||||
channel.append(output);
|
|
||||||
});
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
sup.on('close', (code, signal) => {
|
|
||||||
if (code === 0) {
|
|
||||||
resolve(code);
|
|
||||||
} else {
|
|
||||||
reject(code);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
channel.dispose();
|
|
||||||
} catch (err) {
|
|
||||||
vscode.window.showErrorMessage(
|
|
||||||
`Couldn't install \`cargo-watch\`: ${err.message}`
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue