Configure VSCode to ask to save modified files on exit - visual-studio-code

I'd like to configure VS code to work the same as pretty much every editor I've ever used which is to save only when I tell it to and to ask to save modified files if I try to quit.
I've set Auto Save to "off"
I've set Hot Exit to "off"
As it is if I have modified files and I choose quit it just exits immediately, losing all my changes. I could have sworn this used to work.
version 1.41.1

At least, VSCode 1.51 (Oct. 2020) mitigates that situation with:
Prevent accidental close
A new setting window.confirmBeforeClose was added to show a confirmation dialog before closing or leaving the workbench.
Possible values are:
keyboardOnly: The confirmation will only be shown when you use a keybinding to close (for example Ctrl+W or Cmd+W). (default)
always: The confirmation dialog will always be shown, even if you close from a mouse gesture.
never: The confirmation will never be shown.
But, that was only for Web.
VSCode 1.66 (Apr. 2022) will propose the same for the desktop app.
See issue 14710 and PR 147242

The issue was if you're in extension develop mode it just exits. If I pass in --extensionDevelopmentPath some/path then the save options are ignored. Without that it works as it's supposed to.
Apparently that's by design
https://github.com/microsoft/vscode/issues/71405

Related

Latex Workshop does not autobuild in VSCode

I'm trying to switch to Latex Workshop for VSCode, however I cannot get it to build after change.
I have it enabled in the settings, however it does not autobuild. After building manually the log says
Auto Build Run is temporarily disabled during a second.
at some point. I also made sure that Polling is active.
What is that supposed to mean and what is the fix?
I tried to set up Latex Workshop to autobuild, but it does not.
I think this is a bug. The way that I got auto build working was to enable autosave, because the "build on change" setting does seem to work and so the auto save triggers an auto build. Some instructions to enable autosave can be found e.g. in an answer here (in conjunction with the settings you mention).

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.

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.

vscode: Automatically save all on build

In Visual Studio when I trigger a build it automatically saves all files first. I want the same behavior in vscode, but couldn't find a way to do it short of writing my own extension. Is there any simple method I'm missing?
It's not exactly what you're asking, but will also accomplish what you want: you could enable the auto-save feature:
"files.autoSave": "afterDelay"
After using IntelliJ for a while, I managed to get rid of my habit of pressing Ctrl+S after every second typed-out word, for the most part (since it has auto-save by default). I was happy to find out that VSCode support this somewhat less stressful workflow too.
Other than that, there's also a Files: Save All command you've probably already found.
I'm actually not sure you can do this with the extension API right now - you can definitely trigger the "save all" command easily, but you'd need to be notified of when a build occurs, and I couldn't find any events for this. I think it will definitely be possible after #15179 is resolved though, which should allow extensions to participate in builds.