Reputation: 91
I have a large codebase opened in Visual Studio Code ( about 60k files ). I get the Unable to watch for file changes ... whenever i do. To get rid of the message, i have the files.watcherExclude
setting set up, leaving only about 1000 files on watch. My watcher limit is the typical 8192 files. But with these settings on, the Unable to watch... pops up. I suspect my files.watcherExclude
pattern. Is there a way to see the list of files Visual Studio Code is watching ? I can improve my watcherExclude pattern if i can see which files are still being watched.
Upvotes: 9
Views: 4818
Reputation: 341
I know I'm a bit late to the party, but this question shows up when one searches for info on showing the file watchers employed by vscode and so I thought I'd provide some assistance for those having trouble finding the watched files on a remote host.
In my experience, VS-Code is a bastard when it comes to watching files. The assumption is made that nobody cares about a few hundred thousand file watchers, so nothing is done to make it apparent why the limit is being hit on those systems that have a limited number of watchers.
You can see the watchers in the output tab** if you select the correct option from the dropdown menu on the right. For remote ssh dev, choose Remote Server
and then search for watcher
in the resulting log output. You should find the culprit in there.
I've had vs-code trying to watch my entire dev directory a few times due to symlinks that it creates itself, so I've excluded (settings > files: Watcher Exclude):
** By default, your VS-Code install should provide enough logging info to see the watchers created. If not, you can try running it in verbose mode vscode --verbose
or changing the log level (ctrl + shift + p
then look for log level
).
Upvotes: 4
Reputation: 1103
On Linux, we can use the strace command to find the list of files being watched by a process. So invoking vscode from command line like below:
strace -fe inotify_add_watch code .
will dump some debug information, specifically pertaining to inotify_add_watch
event, which is what is invoked when a new file is added to watch list. (Note that you must exit other instances of vscode before calling the above command from terminal - else it will just bring the other instance into focus and you will not see list of watches being added).
Original information obtained from this blog post: http://hassansin.github.io/Finding-out-Which-Files-Are-Watched-by-Webpack-Using-Strace
Additional Information & Notes
Using strace, I was able to optimize my webpack and vscode watches. (My webpack configuration made it watch files in node_modules folder and vscode was actually watching files in .git folder as well (both should ideally be ignored)). Something like the below works in vscode settings:
"files.watcherExclude": {
"**/*{.jpg,.png,.gif,.webp,.jpeg}": true,
"**/.git/**": true,
"**/node_modules/**": true,
"**/custom-uploads-folder-path-etc-to-exclude/**" : true
}
Upvotes: 7