diff options
| author | wxb1ank <wxblank@gmail.com> | 2021-05-23 22:37:10 -0400 |
|---|---|---|
| committer | wxb1ank <wxblank@gmail.com> | 2021-06-02 12:11:32 -0400 |
| commit | 0448b7364666ba59b39bbd5564fe8a34b67b8f01 (patch) | |
| tree | 483dcccf2033eaba79bef5865b0d929da073413c /editors/code/src/toolchain.ts | |
| parent | 3ca7f61a8d736d8e56f0d413b109e6e6562c0a30 (diff) | |
| download | rust-0448b7364666ba59b39bbd5564fe8a34b67b8f01.tar.gz rust-0448b7364666ba59b39bbd5564fe8a34b67b8f01.zip | |
migrate from `fs` to `vscode.FileSystem` API
Diffstat (limited to 'editors/code/src/toolchain.ts')
| -rw-r--r-- | editors/code/src/toolchain.ts | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts index 68826c478d3..ba1b8617ae1 100644 --- a/editors/code/src/toolchain.ts +++ b/editors/code/src/toolchain.ts @@ -1,9 +1,8 @@ import * as cp from 'child_process'; import * as os from 'os'; import * as path from 'path'; -import * as fs from 'fs'; import * as readline from 'readline'; -import { OutputChannel } from 'vscode'; +import * as vscode from 'vscode'; import { execute, log, memoize } from './util'; interface CompilationArtifact { @@ -19,7 +18,7 @@ export interface ArtifactSpec { } export class Cargo { - constructor(readonly rootFolder: string, readonly output: OutputChannel) { } + constructor(readonly rootFolder: string, readonly output: vscode.OutputChannel) { } // Made public for testing purposes static artifactSpec(args: readonly string[]): ArtifactSpec { @@ -158,9 +157,9 @@ export const getPathForExecutable = memoize( try { // hmm, `os.homedir()` seems to be infallible // it is not mentioned in docs and cannot be infered by the type signature... - const standardPath = path.join(os.homedir(), ".cargo", "bin", executableName); + const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName); - if (isFile(standardPath)) return standardPath; + if (isFile(standardPath.path)) return standardPath.path; } catch (err) { log.error("Failed to read the fs info", err); } @@ -181,12 +180,6 @@ function lookupInPath(exec: string): boolean { return candidates.some(isFile); } -function isFile(suspectPath: string): boolean { - // It is not mentionned in docs, but `statSync()` throws an error when - // the path doesn't exist - try { - return fs.statSync(suspectPath).isFile(); - } catch { - return false; - } +async function isFile(path: string): Promise<boolean> { + return ((await vscode.workspace.fs.stat(vscode.Uri.file(path))).type & vscode.FileType.File) != 0; } |
