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
bulk file edits: make sure to use textFileService when creating files #114039
Conversation
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.
The changes in text file land are fine to me. What I don't really understand is the need for converting a VSBuffer
into a string
via toString
. That imho is dangerous because if the user picked a non UTF-8 encoding to create a file, toString
is not safe to use. It needs to be the VSBuffer
so that the encoding is preserved.
@bpasero thanks for the review. Edit: ok not so easy, since the @jrieken let me know if you have ideas, and if it might be ok to use the |
To clarify: If we need to preserve the actual string in the bulk edit service, e.g. for undo/redo, then this needs to be the original value before it was passed to Also keep in mind how efficient it is to use |
Discussed with @jrieken, looked a bit more into the issue, and took a step back. Some findings:
Due to the above I propose the following solution:
Since only for empty files we have to read the actual encoding. Non empty files the bits coming in already have an encoding and we can go directly to the I have updated the PR to use this strategy. I have verified this fixes the issue. |
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, I think this is an elegant solution. If you or Jo feel that the direct use of ITextFileService.createFile
is not nice inside bulkEdit
, I am also open to make getEncodedReadable
public so that you can create the right VSBufferReadable
when the file is empty.
@bpasero thanks for the review. That would also be an option. |
@bpasero I am still curious how you store/remember the encoding for an empty file. Is the file not empty in that case but uses some bytes to store the encoding? |
@jrieken this is only required for encodings that use a byte order mark, which means: only UTF8 (with BOM), UTF-16LE and UTF-16BE. Those files, when empty, contain the BOM. |
Ah, thanks for clarifying.
I believe that's nice. Ideally, WorkspaceFileEditOptions get's a new, optional property that carries a VSBuffer with the contents of the file. The explorer uses then some mechanics to create that buffer. |
@bpasero let me know if you plan to make |
Please go ahead and make it public as part of this PR because you also will need to adopt it. |
@bpasero I have updated the PR, check it out and let me know what you think? I can now change the |
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.
👍
Thanks for the reviews and help. Merging in. |
This PR fixes #112377
This PR adds an option to pass multiple
resources
tocreate
in thetextFileService
.A bit ugly part is that now only the
create
method in thetextFileService
accepts multiple resoruces and undo and cancellation arguments.I have tested this out and these changes indeed fix the issue.
Note that I am converting a
VSBuffer
to astring
via thetoString
method for eachedit
.@bpasero let me know what you think
@jrieken fyi