From 06053a0a7636b620d36d49678a5d73424e0010e9 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 2 Apr 2019 14:58:58 +0800 Subject: Add Cargo.toml file check before cargo watch start --- editors/code/src/commands/cargo_watch.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts index fb8fcaeb3..6d8e4d885 100644 --- a/editors/code/src/commands/cargo_watch.ts +++ b/editors/code/src/commands/cargo_watch.ts @@ -1,4 +1,5 @@ import * as child_process from 'child_process'; +import * as fs from 'fs'; import * as path from 'path'; import * as vscode from 'vscode'; import { Server } from '../server'; @@ -14,6 +15,27 @@ export class CargoWatchProvider { private outputChannel?: vscode.OutputChannel; public activate(subscriptions: vscode.Disposable[]) { + let cargoExists = false; + const cargoTomlFile = path.join( + vscode.workspace.rootPath!, + 'Cargo.toml' + ); + // Check if the working directory is valid cargo root path + try { + if (fs.existsSync(cargoTomlFile)) { + cargoExists = true; + } + } catch (err) { + cargoExists = false; + } + + if (!cargoExists) { + vscode.window.showErrorMessage( + `Couldn\'t find \'Cargo.toml\' in ${cargoTomlFile}` + ); + return; + } + subscriptions.push(this); this.diagnosticCollection = vscode.languages.createDiagnosticCollection( 'rustc' -- cgit v1.2.3