-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Add a setting to mark file(s) readonly [nonEditable] #161716
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
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Thanks 🙏
And my PR provides something similar, through a change in settings. We could in theory change this to only operate on the current session and not having it in settings, but I would think that users most likely want VS Code to remember this choice even between restarts and settings is currently the best approach to achieve that.
Yes, currently. We have #134415 that discusses a way to configure both excludes and includes from a single glob pattern, but we are not making progress there in the near term. I think as such I will keep having 2 settings for readonly includes and excludes. |
My original implementation did that; but after seeing a dozen notations accumulating in the setting file, I changed it be self-deleting. But not a big deal either way. |
|
Still trying for a clean compile, but reading your PR/diff I see: The [original] logic was: The [new] logic appears to be semantically different from the original. Consider: In the original, the "Exclude" only applies if the files would otherwise be included. The [new] scheme would require the Excludes to re-identify each 'Include' directory... One can debate which form is easy or obvious, but I want to note that it appears to have changed semantics. |
|
[After a 'yarn' to get something of typescript updated, it compiles]
PS: it's delightful to have you awake/online/in-real-time... ! Found "Toggle Active Editor Readonly", bound it to a key: Hmm, so the command tried to work once, the first time; Update: While I'm thinking of it: my extension/Command also refused to set/toggle for files named 'settings.json' |
|
After viewing Another comment: The point being: sometimes you want a toggle or 'false' to override Likewise, The original code was like this [for my own reminder/reference]: I'll try hacking in a 'clear' value to trigger removal... |
|
About May explain some of the "Unable to change readonly state of the active editor." ?? I don't exactly what stat?.locked implies, but the doc says: The #161716 logic was like: #181708 code: |
|
The previous comment exposes another concern: To continue the original example, with workspace settings: A user will find it difficult to set or toggle '**/foo/example.ini' maybe one could scan readonlyInclude to find the 'single, absolute path' Globs, |
|
@jackpunt good stuff, I have pushed 1976534 to address your feedback. For one, the configuration is ignored for children of Furthermore, I have rethought the commands to toggle readonly state ad-hoc and made them NOT write to settings anymore. Instead, they update an in-memory set of resources that are either readonly or writeable for the duration of the session. I think you have rightfully pointed out that writing to settings and thus changing user preference is quite tricky to get right in this case here. If a user really wants to persist readonly configuration, the user has to go through settings her/himself. This change also makes sure that a readonly file as configured by I also pushed 625d0a1: turns out that toggling readonly state for a file that is readonly via Let me know if you find out more 👍 |
|
I just now saw your response! I still don't know what your I added the new setting for the Command override. now I'll go look at your update... quick peek: rename to InSession, and use a couple of Sets to track the state. Do you get the Icon to update? [[ YES! ]] Ah! now that the Command does not write the USER settings file, that check can come after the Command check. Hmm, I might still want the ClearActiveEditorReadonlyInSession command... Note: in one of my previous versions, instead of 2 Sets, I used a Map<resource,boolean> to hold the command status. |
I added a new
Yeah maybe it would be better if I tracked the in-session state in a |
|
Wow! One stylistic bit: in files.contributions you have: FILES_READONLY_EXCLUDE_CONFIG is externally defined as 'files.readonlyExclude'; |
|
Yeah the keys for Thanks for testing! |
|
I hope you are working in Seattle this week, and not burning midnight oil in Zurich... |
|
Oh! a possible semantic detail: isReadonly() currently give chmod precedence over Inc/Exc Globs: If I mostly want files to open based on the chmod permissions (so FromPermissions: true) |
|
@jackpunt that is fair. Can you actually do a PR targetting my branch in my PR so that you could just propose the change yourself and do it? |
|
Ok. on it... |
|
Before making that mod, i wonder about textFileEditorModel & storedFileWorkingCopy It appears that a chmod -w FileStat.readonly cannot be influenced by I had been working on the theory that filesConfigurationService.isReadonly() was the full arbiter... |
|
PR submitted |
|
@jackpunt thanks, I merged it in but I had to add back the check for return (this.configuredReadonlyFromPermissions && stat?.locked) ?? stat?.readonly ?? false;I think the precedence now is:
That is quite complex! I am happy with this precedence I think, but users might have other feedback. One thing I wonder though: do we need to allow the user overrides to mark a file writeable even if the file system provider is readonly overall? Currently that check is still in the working copy: vscode/src/vs/workbench/services/textfile/common/textFileEditorModel.ts Lines 1162 to 1165 in 05632b6
To be consistent, we should probably move that into the files configuration service as well. |
Sounds right :( I clearly didn't test every case... <chagrin/> I think your precedence chart is what I also arrived at. (although I didn't have the 'user data' test)
Related to your question:
I thinks it's correct that FileSystemProviderCapabilities.Readonly prevents any ability to modify. Back when ReadonlyHelper was an adjunct to SFWC & TFEM, the checks were all in one place. |
It is not: a file system provider can either signal that it is readonly entirely or that specific files are readonly and some are writeable, so there is difference, even though not visually for the user.
Yeah I like that reasoning: if the entire file system provider is declaring to be readonly, it is likely that no write operation can ever happen. But if a single file is readonly, it indicates that the user maybe able to override that. So let's leave it like that. |
|
Since #181708 landed, I will go ahead and close this PR. Thanks a ton for your reviews 🙏 . We can still continue to tweak the experience going forward, it would only be released in stable early June. I will also make sure to ask for user feedback in our nightly insiders release in the fixed issues. |

fix for: #161715 (and 98% of #4873; if we pull branch files-readonly-active with readonlyToggle then 100%)
see discussion at the bottom of that issue for why this simpler approach; also a lot of edits required)
Enable users to mark files as readonly using include/exclude globs in settings.
(independent of OS-filesystem writability)
So users can avoid accidental typing/edits into files that are OS-writeable, but semantically intended to be read-only.
For example: build/tsc.out *.js files, log files, protogen output files, etc.
Test: open a text file ('foo.any'); observe it is editable/writeable.
In settings.json, add glob
"files.readonlyInclude": { "**/foo.any": true }observe that Editor is marked readonly.In settings.json, add glob
"files.readonlyExclude": { "**/foo.any": true }observe that Editor is marked writeable.