VS Code lets me edit read-only files, how can I disable this? - visual-studio-code

I use SVN, but SVN extension is not support "lock-modify-unlock".
VS Code lets me edit files that are not locked (and thus read-only) and will only ask for confirmation when saving.
I want VS Code to stop me from editing so that I remember to lock the file before changing anything.

Related

How to prevent auto save when executing code in Visual Studio

When I run my code in Visual Studio, it auto saves my code -without prompting (!)- even though I have auto-save set to off. Is there a way to prevent this?
I've made sure auto-save is off in preferences. I haven't seen any setting that applies specifically to "on execute"
As an example of how this made me lose some hair, I opened a file that had some unknown characters (which opened just fine in Powershell ISE) and I didn't know until the code failed when I executed it. And since it auto-saved on execute, it wrote the bad characters to the file, corrupting it for all eternity. Not to mention, if I modify a few characters to test something, I don't want it to auto-save for me.
Search for autosave under File-> Preferences - Settings and turn it off

How to temporarily disable "preventing dirty writes" feature in Visual Studio Code

In my project, I've used some build/linting tools so they can automate force change my code based on some convention code styles but when I was running those scripts, vs code showed an error message:
Failed to save "<file-name>": The content on disk is newer. Please compare your version with the one on disk.and continue to open the "Resolve to save conflict" tab.
It seems to be annoying and not convenient for me.
So can you tell me how to disable this feature of VScode for a temporarily time?
v1.42 is modifying this functionality including adding a setting so that the dirty file/save conflict notification can be disabled. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_42.md#ignore-save-conflicts
Ignore save conflicts
VS Code has a built-in mechanism to show an error when you try to save
a dirty file that has been changed outside of VS Code or by another
program (for example Git):
The motivation is to inform you that saving will overwrite the
contents on disk even though the file was changed after the file
became dirty. Clicking the Compare button lets you review your change
along with the version on disk and either overwrite or revert the
file.
In cases where you know that the changes on disk can be overwritten,
there is now an Overwrite button directly on the notification. You can
also configure files.saveConflictResolution globally or per workspace or
file type to disable the notification altogether. The options are askUser (default) or overwriteFileOnDisk.

Auto-saving files upon changes with Visual Studio Code

I have used WebStorm from JetBrains for almost four years now. It's a fantastic IDE for many reasons, but one of the best features is that it saves versions of files outside of version control. So if you accidentally delete files or lose files before they are saved by your version control system, WebStorm has a copy of them and there are visual diff tools to use. This feature has saved me on more than one occasion.
For Visual Studio Code, is there some feature/plugin that will auto-save copies of files as they change? Will Visual Studio Code save the files to some central location, or perhaps in the .vscode folder in the local workspace?
The feature in WebStorm is available from Local History → Show History from a folder or file. Here is an article about it:
Using Local History for code changes tracking
The view looks like:
You can go to menu File and choose Auto Save.
You can enable auto save with these methods:
Check the Auto Save item in the File menu
Go to Settings, search for auto save, and select the auto save option (afterDelay)
Auto save description in Visual Studio Code documentation
Yes, Visual Studio Code can auto-save changes on files as you make changes. It also allows you set a delay for how long to wait before saving the file.
Here's a link that should help you with that.
Or a shortcut you can simply navigate to your Visual Studio Code settings, and add the following to your settings.json file.
{
...
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
...
}
This will instruct your editor to autosave after a 1000 ms delay. You can set the autosave option to onFocusChange to autosave whenever you move your cursor away from the current text area.
There's a package called Local History that can be used to save a backup of your files outside version control.
You should check that out.
As of March 2022 (version 1.66), Visual Studio Code has a built-in feature called Local History that automatically creates commit-like versions of your files on every save.
It is enabled by default, but you can double check the setting workbench.localHistory.enabled to make sure it is enabled in your project.
From the reference:
Each local history entry contains the full contents of the file at the time the entry was created and in certain cases, can provide more semantic information (for example, indicate a refactoring).
From an entry you can:
Compare the changes to the local file or previous entry.
Restore the contents.
Delete or rename the entry.
The saved local versions are accessible from the Timeline section in the File Explorer tab.
Also, ensure you add .history to your .gitignore file, so Visual Studio Code doesn't track every change made to a single file as changes made to multiple files. This can be a problem and make your files changed so large even though it's a single file or a few files you made edits to.

How to refresh content of opened files in VS Code?

I'm looking for a way to refresh the content of a file opened in editor after it was changed by other tool.
For instance I'm using angular command line which makes changes to files but VS Code doesn't refresh the content after that and I can't see any of that. What's worse when I try to save the file, VS Code by default tries to save the old content upon the newer (asks before of course, but still its not what I'm looking for).
I didn't find any keybindings for refresh the editor's content. Maybe there are any extensions?
Thank you.
It should reload itself automatically, but I had a machine that stopped auto-refreshing. I'd change the file externally (with vim or whatever), and the file I had in the editor wouldn't pop and refresh itself, which it used to do. It turned out to be a git-related extension. I disabled it, and autorefresh returned. If you haven't already, try it with extensions off.

Mixed WaveMaker/Java project - how to do it?

WaveMaker is a RAD tool that generates Java and Javascript code - so:
Which files should be checked in to version control, and which files
should be ignored?
What happens if I want to customise the generated code? Will my customisations be silently overwritten?
Can customised code be round-tripped back into WaveMaker?
What about database changes made outside WaveMaker - can they be round-tripped?
If I make changes to generated code, will this change the answer to question 1?
Or, should direct customisation of generated code be avoided? If so, what should be done instead?
Here are answers to your questions:
Q1. Which files should be checked in to version control, and which files should be ignored?
A1. See the documentation on Software Configuration Management with WaveMaker, w
hich outlines which files should be checked-in. All others can be ignored.
Q2. What happens if I want to customise the generated code? Will my customisations be silently overwritten?
A2. WaveMaker Studio executes the code within Studio so your changes are reflected during development and, of course, are executed in your running application. You can further edit within WaveMaker as well.
Q3. Can customised code be round-tripped back into WaveMaker?
A3. Yes, most editors within WaveMaker have a "Refresh from Server" button so if you make changes outside of WaveMaker Studio you can force WaveMaker to re-read the file and load your most recent code. If there is no "Refresh from Server" button you can always close the project and re-open, which will force WaveMaker to re-read your code.
Q4. What about database changes made outside WaveMaker - can they be round-tripped?
A4. See A3.
Q5. If I make changes to generated code, will this change the answer to question 1?
Or, should direct customisation of generated code be avoided? If so, what should be done instead?
A5. I would recommend against editing the widgets.js file that is created for each page in your application. If you edit make sure you re-open the project after editing.