Improve cargo-watch usage

This commit is contained in:
Edwin Cheng 2019-03-31 20:00:50 +08:00
parent c2912892ef
commit b3683df0cd
4 changed files with 177 additions and 36 deletions

View file

@ -1,9 +1,11 @@
import * as child_process from 'child_process';
import * as util from 'util';
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import { Server } from '../server';
import { CargoWatchProvider } from './cargo_watch';
interface RunnablesParams {
textDocument: lc.TextDocumentIdentifier;
@ -127,32 +129,13 @@ export async function handleSingle(runnable: Runnable) {
return vscode.tasks.executeTask(task);
}
export const autoCargoWatchTask: vscode.Task = {
name: 'cargo watch',
source: 'rust-analyzer',
definition: {
type: 'watch'
},
execution: new vscode.ShellExecution('cargo', ['watch'], { cwd: '.' }),
isBackground: true,
problemMatchers: ['$rustc-watch'],
presentationOptions: {
clear: true
},
// Not yet exposed in the vscode.d.ts
// https://github.com/Microsoft/vscode/blob/ea7c31d770e04b51d586b0d3944f3a7feb03afb9/src/vs/workbench/contrib/tasks/common/tasks.ts#L444-L456
runOptions: ({
runOn: 2 // RunOnOptions.folderOpen
} as unknown) as vscode.RunOptions
};
/**
* Interactively asks the user whether we should run `cargo check` in order to
* provide inline diagnostics; the user is met with a series of dialog boxes
* that, when accepted, allow us to `cargo install cargo-watch` and then run it.
*/
export async function interactivelyStartCargoWatch() {
export async function interactivelyStartCargoWatch(context: vscode.ExtensionContext) {
if (Server.config.enableCargoWatchOnStartup === 'disabled') {
return;
}
@ -212,5 +195,7 @@ export async function interactivelyStartCargoWatch() {
}
}
vscode.tasks.executeTask(autoCargoWatchTask);
let validater = new CargoWatchProvider();
validater.activate(context.subscriptions);
}