mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-30 23:27:24 +00:00
Add Cargo.toml file check before cargo watch start
This commit is contained in:
parent
02e450f354
commit
06053a0a76
1 changed files with 22 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
import * as child_process from 'child_process';
|
import * as child_process from 'child_process';
|
||||||
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { Server } from '../server';
|
import { Server } from '../server';
|
||||||
|
@ -14,6 +15,27 @@ export class CargoWatchProvider {
|
||||||
private outputChannel?: vscode.OutputChannel;
|
private outputChannel?: vscode.OutputChannel;
|
||||||
|
|
||||||
public activate(subscriptions: vscode.Disposable[]) {
|
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);
|
subscriptions.push(this);
|
||||||
this.diagnosticCollection = vscode.languages.createDiagnosticCollection(
|
this.diagnosticCollection = vscode.languages.createDiagnosticCollection(
|
||||||
'rustc'
|
'rustc'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue