diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-11 10:59:04 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-11 10:59:04 +0100 |
commit | 7bbb039fbdd124cb6549eb67bbe7316f03ff40e8 (patch) | |
tree | 1826ee317c28a76b78f4020f9379c556339af803 /editors | |
parent | 92800961a03501f24c661bbb093e5078f504214d (diff) | |
parent | 934d7990fd5bf87d858acb296c8f13909e770fda (diff) |
Merge #1797
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 <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/package.json | 2 | ||||
-rw-r--r-- | editors/code/src/commands/cargo_watch.ts | 21 |
2 files changed, 11 insertions, 12 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index 7a48d6794..38824acb4 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -13,7 +13,7 @@ | |||
13 | "Other" | 13 | "Other" |
14 | ], | 14 | ], |
15 | "engines": { | 15 | "engines": { |
16 | "vscode": "^1.36.0" | 16 | "vscode": "^1.37.0" |
17 | }, | 17 | }, |
18 | "scripts": { | 18 | "scripts": { |
19 | "vscode:prepublish": "npm run compile", | 19 | "vscode:prepublish": "npm run compile", |
diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts index 4c3c10c8b..00b24dbce 100644 --- a/editors/code/src/commands/cargo_watch.ts +++ b/editors/code/src/commands/cargo_watch.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as child_process from 'child_process'; | 1 | import * as child_process from 'child_process'; |
2 | import * as fs from 'fs'; | ||
3 | import * as path from 'path'; | 2 | import * as path from 'path'; |
4 | import * as vscode from 'vscode'; | 3 | import * as vscode from 'vscode'; |
5 | 4 | ||
@@ -15,23 +14,23 @@ import { | |||
15 | import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection'; | 14 | import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection'; |
16 | import { areDiagnosticsEqual } from '../utils/diagnostics/vscode'; | 15 | import { areDiagnosticsEqual } from '../utils/diagnostics/vscode'; |
17 | 16 | ||
18 | export function registerCargoWatchProvider( | 17 | export async function registerCargoWatchProvider( |
19 | subscriptions: vscode.Disposable[] | 18 | subscriptions: vscode.Disposable[] |
20 | ): CargoWatchProvider | undefined { | 19 | ): Promise<CargoWatchProvider | undefined> { |
21 | let cargoExists = false; | 20 | let cargoExists = false; |
22 | const cargoTomlFile = path.join(vscode.workspace.rootPath!, 'Cargo.toml'); | 21 | |
23 | // Check if the working directory is valid cargo root path | 22 | // Check if the working directory is valid cargo root path |
24 | try { | 23 | const cargoTomlPath = path.join(vscode.workspace.rootPath!, 'Cargo.toml'); |
25 | if (fs.existsSync(cargoTomlFile)) { | 24 | const cargoTomlUri = vscode.Uri.file(cargoTomlPath); |
26 | cargoExists = true; | 25 | const cargoTomlFileInfo = await vscode.workspace.fs.stat(cargoTomlUri); |
27 | } | 26 | |
28 | } catch (err) { | 27 | if (cargoTomlFileInfo) { |
29 | cargoExists = false; | 28 | cargoExists = true; |
30 | } | 29 | } |
31 | 30 | ||
32 | if (!cargoExists) { | 31 | if (!cargoExists) { |
33 | vscode.window.showErrorMessage( | 32 | vscode.window.showErrorMessage( |
34 | `Couldn\'t find \'Cargo.toml\' in ${cargoTomlFile}` | 33 | `Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}` |
35 | ); | 34 | ); |
36 | return; | 35 | return; |
37 | } | 36 | } |