-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(vscode): Implements readFile/writeFile for workspace.fs #6980
Conversation
@benoitf sorry i could not attend the meeting yesterday, it should be fine to add required metadata to FileStat, @kittaakos ? |
@akosyakov about adding stuff about FileStat during the meeting we agreed to add stuff and deprecate other some methods (shouldn't be a problem) A wider problem to me is that today we have FileSystem and ResourceProvider/ResourceResolver but then, to use createDir, getFileStat, copy/remove and all other methods of workspace.fs we won't be able to use |
Did you mean
|
@kittaakos yes ctime, mtime, etc but also to have FileType instead of just |
Nice. I would leave the |
@kittaakos yes add new stuff + keep it with deprecation |
yes, I think in the plugin system to implement I wonder where else we should hook file system providers. Could they contribute somehow to the navigator or VS Code extension supposed to provide own tree views? |
a77bc49
to
b45f8c9
Compare
PR updated |
async readFile(uri: UriComponents): Promise<Uint8Array> { | ||
try { | ||
const val = await this.proxy.$readFile(uri); | ||
return new TextEncoder().encode(val); |
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'm worried about this line: will it provide the exact byte contents of the file in every case? Reading the file as a string will use a certain text encoding. How can we be sure we're using the same encoding on this line?
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.
@tsmaeder because it is using utf-8 ?
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.
But you don't know that: resources are a point of extension. Say a resource reads a file in EBDIC and translates that correctly to a string. When you encode that using utf-8, you will not have the original byte contents in your byte array.
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.
yes, it was like temporary issue (for non utf-8 resources) until being able to use filesystem from workspace.fs
(and then hook FileStat etc in theia core)
For now we only have resources
allowing the file access + custom FileSystemResourceProvider
I think this is correct: Resource is the interface between the editor and content: FileSystem is the interface between storage and content. |
Also, I was wondering why we need this now. Is there an issue this fixes or a particular VS Code extension it enables? |
@tsmaeder Could you finish the review please? |
I don't think we should merge this PR in the current form. The architectural problem that files are implemented in terms of resources leads to potential problems with encoding. I would agree to this workaround if there was a clear business reason to do it, but not to enable an example plugin (that's why I asked what it's for). Let's do this right! I might be swayed if there is a clear commitment to fix the issues soon. |
well, I would argue that there are other extensions using that and from what I've seen, they're all using UTF-8. but well, it's up to reviewers. |
I'm all for it, but let's do it right. Would it be so hard to fix the resource/file issue? |
I just wanted to proceed by steps
but of course we can omit step 1, just that it was easy to provide it like this without any changes yet in theia core. |
Why don't you open an issue for this so we can track it? Also, is there a way to test this in real life? |
what are you calling 'real life' ? Also it has been discussed during theia dev meeting a couple of weeks ago |
Is there a plugin I can install and exercise the code? |
@tsmaeder so by looking at my github search link [1] it turns out that markdown language server is using the API [2] And this extension is provided by default in Eclipse Theia. [1] https://github.com/search?q=%22vscode.workspace.fs.readFile%22&type=Code |
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 think we can accept it, some small extension would be helpful to drop and verify? Or how you check it?
How to check with callhierachy sample: (I haven't looked at how markdown LS is using readFile api) start Theia with pre-build vsix on a gist from $ THEIA_PLUGINS=https://gist.github.com/benoitf/234f32b79ce621b7a6a2f6b2c13ddd24/raw/c796ba66654d3bdb86f70ff7d420e495e83314f2/call-hierarchy-sample-0.0.1.vsix node src-gen/backend/main.js Then create a dummy foo.txt file (to trigger actionEvent on the sample) |
Change-Id: I1626547e72b8230bbc0a1832f682ebc18f2b22dc Signed-off-by: Florent Benoit <fbenoit@redhat.com>
b45f8c9
to
cc5de52
Compare
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.
it works nicely for me
@tsmaeder could we merge it for now?
Regarding steps It is a bit unclear to me why do we need to hook plugin fs providers in core filesystem. Sorry i did not research how these providers should be used. But if they are need only for VS Code compatibility I think we can leave core filesystem as is and build something on top like a facade to core filesystem and plugin fs providers. |
@benoitf When I follow your testing instructions with with the call-hierarchy sample, a breakpoint in languages-main.ts#readFile is not hit. |
Stupid old me is using the "fixed" version you provided for the call hieararchy PR 🤦♂ |
Hmh...still can't hit that breakpoint. I guess you have @akosyakov's approval, so you don't need mine. |
ok, I will merge today if no objections |
What it does
Implements
workspace.fs
for readFile and writeFileHow to test
readFile
writeFile
For other methods like stat, etc, need to revise Theia core stuff as Theia is not providing enough stats info for example
Review checklist
Reminder for reviewers
Change-Id: I1626547e72b8230bbc0a1832f682ebc18f2b22dc
Signed-off-by: Florent Benoit fbenoit@redhat.com