Repository navigation
Add a way to exclude file or directory watching #36035
Description
Template info added by Matt Bierner (@mjbvz)
TypeScript Version: 3.7.3
Search terms:
- watcher
- linux
- tsserver
- VSCode Version: 1.41.1 AND 1.42.0-insider
- OS Version: Linux x64 5.0.0-37-generic (Ubuntu 18.04.3 LTS)
Steps to Reproduce:
- Clone the following test repo with only one npm dependency in it: https://github.com/slanden/vscode-watcher-test.git
- Run npm i
- Download this GitHub user's script that shows the currently registered watchers
- Open the empty project in VS Code
- Run the script to see that there should not be any VS Code file paths taking more than ~80 or so watchers
- In VS Code, add a subdirectory (beside node_modules) and in it put an index.js file
- I tried a file without a file extension and it did not cause issues.
- Run the script again to see that two VS Code file paths now take ~2,600+ watchers
The script results show these two two Code paths if using regular VS Code:
| INOTIFY WATCHER COUNT | PID | CMD |
|---|---|---|
| 2836 | 29232 | /usr/share/code/code --max-old-space-size=3072 /usr/share/code/resources/app/extensions/node_modules/typescript/lib/tsse |
| 2642 | 29250 | /usr/share/code/code /usr/share/code/resources/app/extensions/node_modules/typescript/lib/typingsInstaller.js --globalTy |
OR for VS Code Insiders, the files would be:
| INOTIFY WATCHER COUNT | PID | CMD |
|---|---|---|
| 2836 | 31167 | /usr/share/code-insiders/code-insiders --max-old-space-size=3072 /usr/share/code-insiders/resources/app/extensions/node_ |
| 2642 | 31184 | /usr/share/code-insiders/code-insiders /usr/share/code-insiders/resources/app/extensions/node_modules/typescript/lib/typ |
Does this issue occur when all extensions are disabled?: Yes
What is expected?
node_modules/ should be excluded from being watched, whether by the VS Code default Watcher Exclude patterns or by setting them explicitly in settings.json.
My Settings
My VS Code Watcher Exclude settings have the following ignore patterns by default.
**/.git/objects/**
**/.git/subtree-cache/**
**/node_modules/**
Adding them explicitly to settings.json with
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true
}
ultimately doesn't work. I say "ultimately" because I noticed when I first added it, the two VS Code watcher paths and their watchers were removed for that session. But, upon restarting VS Code they were back and I was hitting the "watcher limit reached" error again.
I have found other GitHub issues that were similar, but not the same. Issue microsoft/vscode#59679 is the closest to what I'm experiencing but it was closed as a duplicate to microsoft/vscode#40898. This is not a duplicate issue to microsoft/vscode#40898 as this is for a single-root workspace.
Activity
bpasero commentedon Jan 4, 2020
This looks like the typescript extension watching all files and folders.
[-]file.watcherExclude setting not excluding VS Code node_modules[/-][+]TS extensions is causing high amount of inotify watcher count[/+]bpasero commentedon Jan 4, 2020
Maybe #33338
bpasero commentedon Jan 4, 2020
Shelby Landen (@slanden) btw thanks for that script to track the watchers, very useful 👍
slanden commentedon Jan 5, 2020
Benjamin Pasero (@bpasero) I assume the typescript extension is built into VS Code? To clarify, I haven't installed any typescript extension myself and I ran both versions of VS Code with
--disable-extensionsAnd also, I can't take credit for that script, thanks all go to Carl-Erik Kopseng (@fatso83). Very useful indeed.
bpasero commentedon Jan 5, 2020
Yes, we bundle it.
[-]TS extensions is causing high amount of inotify watcher count[/-][+]TS Server high number of inotify watchers[/+]sheetalkamat commentedon Jan 29, 2020
We do not use vs code exclude settings for watches.. But #35615 enables us to add option to exclude directory/file watching certain things. Its not as simple as that though since we watch
node_modulesfor script infos that are also shared across the project so they don't use projects setting but use global watching strategy.. Many times we watch project folder instead of say watching node_modules folders and we need to consider what happens in those scenarios.. So this is definitely not an easy thing to add but we have paved a path to enable this in future.[-]TS Server high number of inotify watchers[/-][+]Add a way to exclude file or directory watching[/+]DanTup commentedon Aug 25, 2020
Sheetal Nandi (@sheetalkamat)
Is this something we can do today, or just work towards it? I have two build tasks - one using webpack (for my VS Code extension) and one using
tscdirectly (test code). Right now, thetsc --watchfor the tests will intermittently see when the webpack output is written toout/distand then hang:I've no idea why it's hanging, but I'd like to exclude the
outfolder from its watching (it's already listed inexcludeintsconfig.jsonbut that doesn't change anything).Whalesoft19 commentedon Dec 17, 2023
Open your tsconfig.json file: This file is usually located at the root of your TypeScript project.
Add an exclude field: If the exclude field is not already present, you need to add it. This field specifies an array of file paths or patterns that the TypeScript compiler should ignore.