From 422f4ac080c1347421a1ba6efcbc8f5b40414f46 Mon Sep 17 00:00:00 2001 From: Bernardo Date: Fri, 19 Apr 2019 18:28:14 +0200 Subject: [PATCH] start cargo watch if not started interactively --- editors/code/package.json | 2 +- editors/code/src/commands/runnables.ts | 12 +++++++++++- editors/code/src/extension.ts | 9 ++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index dd9843241a..83ceb19f73 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -275,4 +275,4 @@ } ] } -} \ No newline at end of file +} diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 5790252b74..26372c1e8b 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -153,6 +153,12 @@ export async function interactivelyStartCargoWatch( } } + return startCargoWatch(context); +} + +export async function startCargoWatch( + context: vscode.ExtensionContext +): Promise { const execPromise = util.promisify(child_process.exec); 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; } diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index b48ad9b29b..48dd2a6146 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -3,7 +3,10 @@ import * as lc from 'vscode-languageclient'; import * as commands from './commands'; import { CargoWatchProvider } from './commands/cargo_watch'; -import { interactivelyStartCargoWatch } from './commands/runnables'; +import { + interactivelyStartCargoWatch, + startCargoWatch +} from './commands/runnables'; import { SyntaxTreeContentProvider } from './commands/syntaxTree'; import * as events from './events'; import * as notifications from './notifications'; @@ -134,6 +137,10 @@ export function activate(context: vscode.ExtensionContext) { registerCommand('rust-analyzer.startCargoWatch', () => { if (provider) { provider.start(); + } else { + startCargoWatch(context).then(p => { + provider = p; + }); } }); registerCommand('rust-analyzer.stopCargoWatch', () => {