Replace watcher file existence check with vscode.fs version
import * as child_process from 'child_process';
-import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
@@ -15,23 +14,23 @@ import {
import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection';
import { areDiagnosticsEqual } from '../utils/diagnostics/vscode';
-export function registerCargoWatchProvider(
+export async function registerCargoWatchProvider(
subscriptions: vscode.Disposable[]
-): CargoWatchProvider | undefined {
+): Promise<CargoWatchProvider | undefined> {
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)) {
+ const cargoTomlPath = path.join(vscode.workspace.rootPath!, 'Cargo.toml');
+ const cargoTomlUri = vscode.Uri.file(cargoTomlPath);
+ const cargoTomlFileInfo = await vscode.workspace.fs.stat(cargoTomlUri);
+
+ if (cargoTomlFileInfo) {
cargoExists = true;
}
- } catch (err) {
- cargoExists = false;
- }
if (!cargoExists) {
vscode.window.showErrorMessage(
- `Couldn\'t find \'Cargo.toml\' in ${cargoTomlFile}`
+ `Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}`
);
return;
}
