microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.93k stars 29.18k forks source link

File watcher ignoring excludes #232665

Open pgcamus opened 1 day ago

pgcamus commented 1 day ago

Type: Bug

Here is my files.watcherExclude:

        "files.watcherExclude": {
                "**/bazel-bando/**": true,
                "**/bazel-bin/**": true,
                "**/bazel-out/**": true,
                "**/bazel-testlogs/**": true,
                "/**/.cache/**": true
        },

Despite this configuration, I'm seeing log lines like the following after enabling remote logging for File Watcher

2024-10-30 20:43:38.135 [trace] [File Watcher ('parcel')] Request to start watching: /home/builder/.cache/bazel/_bazel_builder/111d6a28ddfe7cb2f314c9d3cd6a7751/execroot/ritta/bazel-out/aarch64-dbg/bin (excludes: **/.git/objects/**,**/.git/subtree-cache/**,**/.hg/store/**,**/bazel-bando/**,**/bazel-bin/**,**/bazel-out/**,**/bazel-testlogs/**,/**/.cache/**,/home/builder/.vscode-server/extensions/**, includes: <all>, filter: <none>, correlationId: <none>),/home/builder/.cache/bazel/_bazel_builder/111d6a28ddfe7cb2f314c9d3cd6a7751/external/python3_10_aarch64-unknown-linux-gnu/lib/python3.10 (excludes: **/.git/objects/**,**/.git/subtree-cache/**,**/.hg/store/**,**/bazel-bando/**,**/bazel-bin/**,**/bazel-out/**,**/bazel-testlogs/**,/**/.cache/**,/home/builder/.vscode-server/extensions/**, includes: <all>, filter: <none>, correlationId: <none>),/usr/lib/python3/dist-packages (excludes: **/.git/objects/**,**/.git/subtree-cache/**,**/.hg/store/**,**/bazel-bando/**,**/bazel-bin/**,**/bazel-out/**,**/bazel-testlogs/**,/**/.cache/**,/home/builder/.vscode-server/extensions/**, includes: <all>, filter: <none>, correlationId: <none>),/usr/lib/python3.10 (excludes: **/.git/objects/**,**/.git/subtree-cache/**,**/.hg/store/**,**/bazel-bando/**,**/bazel-bin/**,**/bazel-out/**,**/bazel-testlogs/**,/**/.cache/**,/home/builder/.vscode-server/extensions/**, includes: <all>, filter: <none>, correlationId: <none>),/usr/local/lib/python3.10/dist-packages (excludes: **/.git/objects/**,**/.git/subtree-cache/**,**/.hg/store/**,**/bazel-bando/**,**/bazel-bin/**,**/bazel-out/**,**/bazel-testlogs/**,/**/.cache/**,/home/builder/.vscode-server/extensions/**, includes: <all>, filter: <none>, correlationId: <none>)

I've tried this with both absolute ignore rules like /**/.cache/** as well as relative like **/.cache/**. Nothing seems to match enough to catch this.

I /think/ VS Code is finding this path because of the following symlink in my workspace root

$  ls -al bazel-*
lrwxr-xr-x 1 builder dialout  89 Sep 19 21:22 bazel-bando -> /home/builder/.cache/bazel/_bazel_builder/111d6a28ddfe7cb2f314c9d3cd6a7751/execroot/ritta/
lrwxr-xr-x 1 builder dialout 115 Oct 29 19:19 bazel-bin -> /home/builder/.cache/bazel/_bazel_builder/111d6a28ddfe7cb2f314c9d3cd6a7751/execroot/ritta/bazel-out/aarch64-dbg/bin/
lrwxr-xr-x 1 builder dialout  99 Sep 19 21:22 bazel-out -> /home/builder/.cache/bazel/_bazel_builder/111d6a28ddfe7cb2f314c9d3cd6a7751/execroot/ritta/bazel-out/
lrwxr-xr-x 1 builder dialout 120 Oct 29 19:19 bazel-testlogs -> /home/builder/.cache/bazel/_bazel_builder/111d6a28ddfe7cb2f314c9d3cd6a7751/execroot/ritta/bazel-out/aarch64-dbg/testlogs/

... but again the existing exclude rules should have caught the symlink source.

VS Code version: Code 1.95.0 (912bb683695358a54ae0c670461738984cbb5b95, 2024-10-28T20:16:24.561Z) OS version: Darwin arm64 23.6.0 Modes: Remote OS version: Linux arm64 6.10.4-linuxkit

System Info |Item|Value| |---|---| |CPUs|Apple M1 Pro (10 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|4, 8, 9| |Memory (System)|16.00GB (0.03GB free)| |Process Argv|--crash-reporter-id 8b9e2792-5ee0-48ef-a561-5f6b02100b14| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|SSH: localdev| |OS|Linux arm64 6.10.4-linuxkit| |CPUs|unknown (10 x 0)| |Memory (System)|7.66GB (5.79GB free)| |VM|0%|
Extensions (10) Extension|Author (truncated)|Version ---|---|--- remote-ssh|ms-|0.116.2024100715 remote-ssh-edit|ms-|0.87.0 remote-explorer|ms-|0.4.3 vim|vsc|1.28.1 vscode-bazel|Baz|0.10.0 gitlens|eam|15.6.2 black-formatter|ms-|2024.4.0 debugpy|ms-|2024.12.0 python|ms-|2024.16.1 vscode-pylance|ms-|2024.10.1 (1 theme extensions excluded)
bpasero commented 18 hours ago

Excludes are actually applied on the file watcher library (via options) and so the message you see does not necessarily mean that the file watcher is also applied on disk. You can assume that the path is not watched given your glob pattern.

bpasero commented 11 hours ago

I think my answer needs further clarification: files.watcherExclude behaves differently depending on your platform and also whether a glob pattern is used vs. a path.

glob pattern vs path The setting already explains this: glob patterns are actually only matched on the relative path portion relative to the watched root. So if you are watching a path of /Users/bpasero/Desktop/test-ts, a glob pattern of **/bpasero/** would not match that path.

A path on the other hand is taken as is and matched against the absolute path of the watcher.

platform differences The files.watcherExclude setting was mainly introduced for Linux to workaround platform limitations when watching large folders and running out of file handles: Only on Linux, a folder is watched recursively by installing file watchers on each folder that is found beginning from the root. files.watcherExclude is applied while traversing the folders making it easy to reduce the file handle overhead by reducing large folders (such as output).

Windows and macOS on the other hand have very efficient recursive folder watchers built in: here you cannot really disable watching a folder that VS Code wants to watch unless you disable all file watching (by putting ** into the files.watcherExclude setting).

tl;dr; files.watcherExclude will not prevent a folder from being watched that VS Code wants to watch recursively, but helps a lot on Linux to reduce the overhead. In all cases, files.watcherExclude will also be applied on resulting file events to filter them out from being dispatched to VS Code, so this setting still helps reducing CPU overhead of processing the events.

I hope this clarifies?