Visual Studio Code: Auto-refresh file changes

Visual Studio-Code

Visual Studio-Code Problem Overview


Working with Visual Studio Code I have noticed if a file you are working with change, whenever that file get focused in a code panel it will be reloaded from the disk (if you don't have changes in the file through VSCode).

However, if you are on that file there is no alert to warning you about file changes.

I've been reviewing the settings and I cannot find anything like the visual studio option:

> Detect when file is changed outside the environment

So my question: Is there any hidden setting or some hack to make that warning happen.

Update

Solved in version 0.3.0 of Visual Studio Code.

  1. The file will be updated from disk if there is no changes through the editor. (very useful to read log files during a process execution)
  2. If there are changes on both sides (from disk and through the editor) when ever you try to save the file using VSCode, the editor will warn you about that situation (i.e. "dirty writes") and a file comparison will allow you to decide what to do.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

VSCode will never refresh the file if you have changes in that file that are not saved to disk. However, if the file is open and does not have changes, it will replace with the changes on disk, that is true.

There is currently no way to disable this behaviour.

Solution 2 - Visual Studio-Code

{
    "files.useExperimentalFileWatcher" : true
}

in Code -> Preferences -> Settings

Tested with Visual Studio Code Version 1.26.1 on mac and win

Solution 3 - Visual Studio-Code

SUPER-SHIFT-p > File: Revert File is the only way

(where SUPER is Command on Mac and Ctrl on PC)

Solution 4 - Visual Studio-Code

In version 1.57.1 (June 2021) there is still no setting like Detect when file is changed outside the environment. But if the file was accidentally changed outside, you can easily revert the changes with just the Undo (Ctrl+Z) command

Solution 5 - Visual Studio-Code

On Ubuntu, after creating a new file using vscode, it doesn't show up until I refresh the explorer manually. It's really frustrating. There was a key I changed in settings.json and everything worked fine after that:

"files.legacyWatcher": "on",

save, restart the vscode and be safe :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJuan M. EloseguiView Question on Stackoverflow
Solution 1 - Visual Studio-CodeBenjamin PaseroView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeWon Jun BaeView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeDavid 天宇 WongView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeelshevView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeAli AskariView Answer on Stackoverflow