Visual Studio代码:自动刷新文件更改

时间:2022-11-06 20:21:00

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).

使用Visual Studio代码我注意到,如果您正在使用的文件发生更改,只要该文件集中在代码面板中,它就会从磁盘重新加载(如果您没有通过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:

我一直在审查设置,我找不到像visual studio选项:

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.

在Visual Studio Code 0.3.0版中解决。

  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. 如果编辑器没有更改,则将从磁盘更新该文件。 (在流程执行期间读取日志文件非常有用)

  3. 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.
  4. 如果您尝试使用VSCode保存文件时双方(从磁盘和编辑器)都有更改,编辑器将警告您这种情况(即“脏写”),文件比较将允许您决定该怎么办。

2 个解决方案

#1


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.

如果该文件中的更改未保存到磁盘,VSCode将永远不会刷新该文件。但是,如果文件是打开的并且没有更改,则它将替换为磁盘上的更改,这是真的。

There is currently no way to disable this behaviour.

目前无法禁用此行为。

#2


{
    "files.useExperimentalFileWatcher" : true
}

in Code -> Preferences -> Settings

在代码 - >首选项 - >设置

Tested with Visual Studio Code Version 1.26.1 on mac and win

在mac和win上使用Visual Studio Code Version 1.26.1进行测试

#1


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.

如果该文件中的更改未保存到磁盘,VSCode将永远不会刷新该文件。但是,如果文件是打开的并且没有更改,则它将替换为磁盘上的更改,这是真的。

There is currently no way to disable this behaviour.

目前无法禁用此行为。

#2


{
    "files.useExperimentalFileWatcher" : true
}

in Code -> Preferences -> Settings

在代码 - >首选项 - >设置

Tested with Visual Studio Code Version 1.26.1 on mac and win

在mac和win上使用Visual Studio Code Version 1.26.1进行测试