diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-15 21:05:07 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-15 21:05:07 +0100 |
commit | d0f2bc3b878d1c1d8eaf081e6f670ebb928b7a5f (patch) | |
tree | d704be44422c3fe3981a43055a336141a88922c9 /editors/code/src/toolchain.ts | |
parent | dcea1c536c351a6063ba887813d54911a2b7eb39 (diff) | |
parent | a6b0c056dedb17fa2056e5186bd73af66c5e84e3 (diff) |
Merge #9292
9292: fix: Code: clean-up #8951 r=wxb1ank a=wxb1ank
#8951 was a major change in the VS Code extension and caused quite a few problems. This PR is a catch-all for bugs and improvements in the new code.
This should fix:
- #9284
- [this unreported bug](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446)
- ...and one or two uncaught exceptions I just found
The original lack of testing was my own fault, but this area of the VS Code API is also tricky for a couple reasons:
- The [FileSystem](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446) API does not list or warn about any exceptions, but [FileSystemProvider](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446) (which `FileSystem` is a wrapper of, AFAICT) does.
- At first glance, [Uri.path](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446) *looks* like it works for FS operations. It does not, at least, on Windows. You need to use `Uri.fsPath`.
I only use Windows, so I need people on macOS, Linux, and (possibly) NixOS to test this.
Co-authored-by: wxb1ank <[email protected]>
Diffstat (limited to 'editors/code/src/toolchain.ts')
-rw-r--r-- | editors/code/src/toolchain.ts | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts index 902d0ddda..355dd76fe 100644 --- a/editors/code/src/toolchain.ts +++ b/editors/code/src/toolchain.ts | |||
@@ -159,7 +159,7 @@ export const getPathForExecutable = memoize( | |||
159 | // it is not mentioned in docs and cannot be infered by the type signature... | 159 | // it is not mentioned in docs and cannot be infered by the type signature... |
160 | const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName); | 160 | const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName); |
161 | 161 | ||
162 | if (isFile(standardPath.path)) return standardPath.path; | 162 | if (isFileAtUri(standardPath)) return standardPath.fsPath; |
163 | } catch (err) { | 163 | } catch (err) { |
164 | log.error("Failed to read the fs info", err); | 164 | log.error("Failed to read the fs info", err); |
165 | } | 165 | } |
@@ -177,9 +177,17 @@ function lookupInPath(exec: string): boolean { | |||
177 | : [candidate]; | 177 | : [candidate]; |
178 | }); | 178 | }); |
179 | 179 | ||
180 | return candidates.some(isFile); | 180 | return candidates.some(isFileAtPath); |
181 | } | 181 | } |
182 | 182 | ||
183 | async function isFile(path: string): Promise<boolean> { | 183 | async function isFileAtPath(path: string): Promise<boolean> { |
184 | return ((await vscode.workspace.fs.stat(vscode.Uri.file(path))).type & vscode.FileType.File) !== 0; | 184 | return isFileAtUri(vscode.Uri.file(path)); |
185 | } | ||
186 | |||
187 | async function isFileAtUri(uri: vscode.Uri): Promise<boolean> { | ||
188 | try { | ||
189 | return ((await vscode.workspace.fs.stat(uri)).type & vscode.FileType.File) !== 0; | ||
190 | } catch { | ||
191 | return false; | ||
192 | } | ||
185 | } | 193 | } |