-
Notifications
You must be signed in to change notification settings - Fork 1.8k
internal: migrate to vscode.FileSystem API #8951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens here if the file doesn't exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I had to guess... it throws. (Note: that's for I'm not very proud of my implementation for this function, either; I wanted to maintain the original function signature (i.e. with a string path, not Looking at it now, I think it would be best to separate This PR has already been merged, so tomorrow (later today?) I can try and clean this up in a new one. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We convert an
Uri
to a string here, then convert it back to anUri
. And I'm not sure what happens if the path doesn't exist -- is there a way torequire("vscode")
in the Developer Tools?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect not. The developer tools run inside the chromium based part of electron. The extensions run in the node.js based part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wxb1ank I haven't looked at the code outside of the diff, but do you think this can be simplified?