In the Stable Build v1.79 is the ability to detect and/or mark files as read-only thanks significantly to @jackpunt.
There are four new commands and some new settings implementing this.
These commands and settings DO NOT actually change the file permissions in the filesystem - they just prevent the file from being written/pasted to, etc. in a vscode editor.
Commands:
File: Set Active Editor Writeable in Session
workbench.action.files.setActiveEditorWriteableInSession
File: Set Active Editor Readonly in Session
workbench.action.files.setActiveEditorReadonlyInSession
File: Toggle Active Editor Readonly in Session
workbench.action.files.toggleActiveEditorReadonlyInSession
Files: Reset Active Editor Readonly in Session // or may be named 'Clear...'
workbench.action.files.resetActiveEditorReadonlyInSession
Settings:
Files: Readonly From Permissions // in the Settings UI, default is disabled
"files.readonlyFromPermissions": true, // in settings.json, default is disabled
> Marks files as readonly when their file permissions indicate as such.
> This can be overridden via Files: Readonly Include and Files: Readonly
> Exclude settings.
Files: Readonly Include // in the Settings UI
"files.readonlyInclude": { // in your user/workspace settings.json
"dist/*.min.js": true
}
> Configure path or glob patterns to mark as read-only. You can
> exclude matching paths via the Files: Readonly Exclude setting. Files
> from readonly system providers will always be read-only independent of
> this setting.
Files: Readonly Exclude
"files.readonlyExclude": { // in your user/workspace settings.json
"dist/dontExclude.min.js": true
}
> Configure path or glob patterns to exclude from being marked as
> read-only if they match as a result of the Files: Readonly Include
> setting. Files from readonly system providers will always be read-only
> independent of this setting.
Also see vnext release notes v1.79: Readonly mode
Readonly mode
In some cases it can be helpful to explicitly mark some of the
workspace folders or files as readonly for example when their contents
is being managed by a different process (such as the node_modules
folder that is managed by node.js package manager).
For this scenario new settings have been added to mark file paths as
readonly in the explorer and in text and notebook editors:
files.readonlyInclude
: paths or glob patterns that will make a file be readonly if matching
files.readonlyExclude
: paths or glob patterns that will skip files from being readonly when they match files.readonlyInclude
files.readonlyFromPermissions
: whether a file that has no write-permissions on disk should be readonly
According to the rules of the settings, if a path is considered to be
readonly, you cannot modify it from the explorer (e.g. delete it) and
you will see a readonly text or notebook editor.
For more ad-hoc toggling of the readonly mode, new commands have been added that allow to change the mode for the current session only, overruling what the settings configure::
Set Active Editor Readonly in Session
: mark active editor readonly
Set Active Editor Writeable in Session
: mark active editor writeable
Toggle Active Editor Readonly in Session
: toggle between readonly and writeable
Clear Active Editor Readonly in Session
: reset the session state