-
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
Conversation
yeah, ideally we should never use bare fs are there other places we might want to adjust this? |
Well, it looks like I guess the question at this point is which API is more stable and if the VS Code one has drawbacks I'm not aware of. I admit I'm not very familiar with Node/TypeScript, so please correct me if I'm mistaken on anything :) |
I replaced some cases of low-hanging fruit using
|
The root cause is that in 95c51d8 - this.globalStoragePath = ctx.globalStoragePath;
+ this.globalStoragePath = ctx.globalStorageUri.path;
The correct property should be I'm not familiar with new APIs like |
Thanks for clarifying, @yume-chan. As I was exploring the VS Code API I noticed that deprecation, but I didn't realize what exactly the cause for the path error was. At the end of the day, the simplest solution would be to rollback my commits and replace |
I thought However when reading the documentation more carefully, I found this:
So maybe Code expects extensions to use |
Personally, I think
I didn't previously consider your comment about virtual file systems, but seeing as |
I've pushed a fix to just use fsPath, which fixed the immediate issue. However, switching from fs to vscode.fs is something we need to do as well, so it's best to rebase this PR on master! Thanks a bunch for figuring this all out @wxb1ank and @yume-chan, it was instrumental in preparing the quick fix for todays release! |
I found a vscode-python issue that documents their transition from Node's |
Sorry it took me a bit. Coming back to this, it looks like only I've linted and rebased, and I think this is ready for review again. *We also need a way to store non-gunzipped (gzipped?) streams. |
bors r+ Let's see if this breaks anything :D |
|
||
if (isFile(standardPath)) return standardPath; | ||
if (isFile(standardPath.path)) return standardPath.path; |
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 an Uri
. And I'm not sure what happens if the path doesn't exist -- is there a way to require("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.
is there a way to require("vscode") in the Developer Tools?
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?
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
If I had to guess... it throws. (Note: that's for FileSystemProvider
, not FileSystem
, but I'm assuming the latter is a wrapper over the former?) This should definitely be wrapped in a try/catch block ASAP.
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 Uri
) so that it could be reused in lookupInPath()
.
Looking at it now, I think it would be best to separate isFile()
into two functions: one that takes a string path, and one that takes a Uri
. The former should be a simple wrapper over the latter, translating the string into a Uri
with Uri.file(path)
.
This PR has already been merged, so tomorrow (later today?) I can try and clean this up in a new one.
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]>
I encountered an error where
bootstrap()
attempts to create a directory with the pathC:\C:\...
. I couldn't find this reported anywhere else. Using thevscode.FileSystem
API instead of thefs
one works here. I assume the latter automatically prependsC:\
to paths whereas the former does not. I don't know if this suggestsvscode.FileSystem
should be used in more places for consistency.