1797: Use VSCode fs API's in extension r=matklad a=LDSpits

This will close #1670.

I've replaced the `CargoWatcher`s `Cargo.toml` check with a version that uses the `fs` API of vscode.

While making this I've identified an issue with the detection of the `cargo.toml`, we can only load projects where the cargo.toml is in the root of the workspace. but that's a separate issue 😄 

Co-authored-by: Lucas Spits <spits.lucas@gmail.com>
This commit is contained in:
bors[bot] 2019-09-11 09:59:04 +00:00 committed by GitHub
commit 7bbb039fbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View file

@ -13,7 +13,7 @@
"Other" "Other"
], ],
"engines": { "engines": {
"vscode": "^1.36.0" "vscode": "^1.37.0"
}, },
"scripts": { "scripts": {
"vscode:prepublish": "npm run compile", "vscode:prepublish": "npm run compile",

View file

@ -1,5 +1,4 @@
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';
@ -15,23 +14,23 @@ import {
import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection'; import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection';
import { areDiagnosticsEqual } from '../utils/diagnostics/vscode'; import { areDiagnosticsEqual } from '../utils/diagnostics/vscode';
export function registerCargoWatchProvider( export async function registerCargoWatchProvider(
subscriptions: vscode.Disposable[] subscriptions: vscode.Disposable[]
): CargoWatchProvider | undefined { ): Promise<CargoWatchProvider | undefined> {
let cargoExists = false; let cargoExists = false;
const cargoTomlFile = path.join(vscode.workspace.rootPath!, 'Cargo.toml');
// Check if the working directory is valid cargo root path // Check if the working directory is valid cargo root path
try { const cargoTomlPath = path.join(vscode.workspace.rootPath!, 'Cargo.toml');
if (fs.existsSync(cargoTomlFile)) { const cargoTomlUri = vscode.Uri.file(cargoTomlPath);
cargoExists = true; const cargoTomlFileInfo = await vscode.workspace.fs.stat(cargoTomlUri);
}
} catch (err) { if (cargoTomlFileInfo) {
cargoExists = false; cargoExists = true;
} }
if (!cargoExists) { if (!cargoExists) {
vscode.window.showErrorMessage( vscode.window.showErrorMessage(
`Couldn\'t find \'Cargo.toml\' in ${cargoTomlFile}` `Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}`
); );
return; return;
} }