start cargo watch if not started interactively

This commit is contained in:
Bernardo 2019-04-19 18:28:14 +02:00
parent 3d3adabbef
commit 422f4ac080
3 changed files with 20 additions and 3 deletions

View file

@ -153,6 +153,12 @@ export async function interactivelyStartCargoWatch(
} }
} }
return startCargoWatch(context);
}
export async function startCargoWatch(
context: vscode.ExtensionContext
): Promise<CargoWatchProvider | undefined> {
const execPromise = util.promisify(child_process.exec); const execPromise = util.promisify(child_process.exec);
const { stderr } = await execPromise('cargo watch --version').catch(e => e); const { stderr } = await execPromise('cargo watch --version').catch(e => e);
@ -197,5 +203,9 @@ export async function interactivelyStartCargoWatch(
} }
} }
return registerCargoWatchProvider(context.subscriptions); const provider = await registerCargoWatchProvider(context.subscriptions);
if (provider) {
provider.start();
}
return provider;
} }

View file

@ -3,7 +3,10 @@ import * as lc from 'vscode-languageclient';
import * as commands from './commands'; import * as commands from './commands';
import { CargoWatchProvider } from './commands/cargo_watch'; import { CargoWatchProvider } from './commands/cargo_watch';
import { interactivelyStartCargoWatch } from './commands/runnables'; import {
interactivelyStartCargoWatch,
startCargoWatch
} from './commands/runnables';
import { SyntaxTreeContentProvider } from './commands/syntaxTree'; import { SyntaxTreeContentProvider } from './commands/syntaxTree';
import * as events from './events'; import * as events from './events';
import * as notifications from './notifications'; import * as notifications from './notifications';
@ -134,6 +137,10 @@ export function activate(context: vscode.ExtensionContext) {
registerCommand('rust-analyzer.startCargoWatch', () => { registerCommand('rust-analyzer.startCargoWatch', () => {
if (provider) { if (provider) {
provider.start(); provider.start();
} else {
startCargoWatch(context).then(p => {
provider = p;
});
} }
}); });
registerCommand('rust-analyzer.stopCargoWatch', () => { registerCommand('rust-analyzer.stopCargoWatch', () => {