-
Notifications
You must be signed in to change notification settings - Fork 30k
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
LiveShare: Improve support for dirty readonly files #53257
Comments
@isidorn I wonder if a better approach would be to mark the underlying editor model as readonly instead of making the editor readonly and then having to fight for all these corner cases. I think a readonly model is the only way to prevent this from happening. |
@bpasero I was not aware that we have readonly models. I will look into that as it makes more sense to make the model, not the editor readonly |
@isidorn we do not have this currently as far as I know, I would ping @alexandrudima to ask if this is feasable |
@isidorn @bpasero We have no readonly models, we have only readonly editors. The reason is simple: most likely you want to prevent the user from editing the model than the system. e.g. the output channel is a readonly editor with a buffer that can be modified; if we are to display a readonly file from disk, then we might want to listen to file change events and update the contents of the buffer from disk, even if we prevent the user from editing. So I believe the current abstraction where an editor can be readonly, but that concept does not exist on a text buffer is a good abstraction. |
@alexandrudima but we have a lot more places where a model is not shown in an editor but potentially still can be edited programmatically, to give some examples:
So we need to carry the notion of the model being readonly on without the need for an editor somehow. |
@bpasero that should live in the layer above the btw, it is trivial to create a readonly |
@isidorn talked with Alex, makes sense to not push this down to the code editor model. I believe we have to check all our usage patterns where we modify a model and guard against that:
For each we need to see how to react, e.g. after discussion:
|
@bpasero makes sense, I can look into this. Is there some good way to find all references of model mutating clients? I can go over all |
@isidorn clients of Search & replace is a bit different because I think we do not instantiate models for those unless already opened, but I could be wrong (@sandy081 would know). |
About extension applying changes to a document opened from a read-only file system provider, we do need that working. The issue is the behavior of save. I think saving a document should just be disabled for read-only provider. |
@IlyaBiryukov yeah good point, extensions still need to be able to make changes to the model in case it updates. We could maybe change our model in a way that a readonly model never shows up as dirty to the user. |
Which uses the TextFileService from @bpasero |
Yeah, it is rather the |
@bpasero that makes sense, however at that point we have a |
Maybe we need to put this property one level up then? |
@IlyaBiryukov can you please try this out in tomorrow's vscode insiders when you find the time and let us know if it works fine for you. Thanks a lot |
hello, |
@dakowebrex worked for me! THANKS |
@dakowebrex First got to the folder using cd and ls. |
@isidorn fyi with my latest changes around supporting custom editor save, there is also an impact here: an editor that shows up dirty but is marked readonly from the filesystem provider will no longer participate in the save. For example, the file appears as dirty but Editors can now signal back if they are readonly (
Now there is still probably quite more places where edits might end up on the document, so it is not 100% readonly from that perspective, but better. |
@IlyaBiryukov here is how latest behaves (note the dirty file that is readonly). The editor is still considered to be dirty in the workbench and that means indicators show up as usual, however Still, the user cannot close the editor in this state without deciding on reverting the file. Doing so will not result in an error because it will fail but we ignore it since the editor is closing anyway. I think this behaviour is better than before but wondering if you think it can be improved further. |
It's definitely better than before. |
Yeah, there are still things missing. Specifically:
I think we need to come up with a new kind of dirty state specifically for readonly resources. The situation got a bit better with the changes around Save & Revert commands, but not fully there yet. |
One idea would be to never show any dirty indicator for readonly documents. Assuming that the user cannot cause the dirty change of a readonly file system anyway, that would probably be an OK change to do. |
@IlyaBiryukov given issues I recently filed such as microsoft/live-share#3090, microsoft/live-share#3092 and microsoft/live-share#3093 it would probably be a good idea to find a solution that works for all these cases. My understanding is that the LiveShare extension directly modifies the editor of the guest for each keystroke the host does. As such, the guest will see a dirty indicator as soon as that happens because every change to the model will turn it dirty until it gets saved or reverted. This can happen if:
I think my suggestion in #53257 (comment) is probably not a good one because we still want to indicate to the guest that a document has not been saved yet. Even if readonly, it may be interesting to know if the document is still dirty or not. Given that, trying to find out what is missing in API today for LiveShare to handle these cases:
Does that sound reasonable? |
With d108195 I pushed a change to not mark an editor as dirty when its model changes and the editor is readonly (issue #89405). The rationale is that we have an increasing number of custom file system providers built-in that register as readonly (for example Git). I think these providers are fine to make changes to the underlying model directly as needed, but should never result in dirty indicator to the user, nor play a role in hot-exit. I tested this in todays insider build and when I join a readonly LiveShare session I am no longer seeing the dirty indicator when the host is typing. I think that is a reasonable change, but let me know otherwise. |
Thanks! Appreciate it. |
@IlyaBiryukov I tested this and it seems to work fine, with one catch: with default settings, editors in VSCode open in preview mode unless you make changes (you see an italic title). Every editor you open replaces that preview editor. Now, since the guest no longer sees the editor as dirty in readonly sessions, it stays in preview mode (it used to get "pinned" automatically when becoming dirty), even if the host sees it not in preview. As such, any other editor the host opens will replace the preview editor in the guest session. I felt this was an OK experience because it is up to the guest to e.g. double click the editor title to get it out of preview. |
Issue Type: Bug
When an extension applies edits to the documents opened from a read-only file system provider, the document becomes marked as 'dirty' but saving it always fails with an error "Failed to save 'file.ext': Insufficient permissions. Select 'Retry as Admin' to retry as administrator." Retrying as administrator does nothing and repeats the error.
VS Code version: Code - Insiders 1.25.0-insider (5d6156a, 2018-06-25T09:40:10.343Z)
OS version: Windows_NT x64 10.0.16299
System Info
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: enabled
video_encode: enabled
vpx_decode: enabled
webgl: enabled
webgl2: enabled
Extensions (3)
The text was updated successfully, but these errors were encountered: