Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to exclude file or directory watching #36035

Closed
slanden opened this issue Jan 3, 2020 · 8 comments · Fixed by #39243
Closed

Add a way to exclude file or directory watching #36035

slanden opened this issue Jan 3, 2020 · 8 comments · Fixed by #39243
Assignees
Labels
Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript

Comments

@slanden
Copy link

slanden commented Jan 3, 2020

Template info added by @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:

  1. Clone the following test repo with only one npm dependency in it: https://github.com/slanden/vscode-watcher-test.git
  2. Run npm i
  3. Download this GitHub user's script that shows the currently registered watchers
  4. Open the empty project in VS Code
  5. Run the script to see that there should not be any VS Code file paths taking more than ~80 or so watchers
  6. 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.
  7. 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.

@bpasero bpasero assigned mjbvz and unassigned bpasero Jan 4, 2020
@bpasero
Copy link
Member

bpasero commented Jan 4, 2020

This looks like the typescript extension watching all files and folders.

@bpasero bpasero changed the title file.watcherExclude setting not excluding VS Code node_modules TS extensions is causing high amount of inotify watcher count Jan 4, 2020
@bpasero
Copy link
Member

bpasero commented Jan 4, 2020

Maybe #33338

@bpasero
Copy link
Member

bpasero commented Jan 4, 2020

@slanden btw thanks for that script to track the watchers, very useful 👍

@slanden
Copy link
Author

slanden commented Jan 5, 2020

@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-extensions

And also, I can't take credit for that script, thanks all go to @fatso83. Very useful indeed.

@bpasero
Copy link
Member

bpasero commented Jan 5, 2020

Yes, we bundle it.

@mjbvz mjbvz transferred this issue from microsoft/vscode Jan 6, 2020
@mjbvz mjbvz removed their assignment Jan 6, 2020
@mjbvz mjbvz changed the title TS extensions is causing high amount of inotify watcher count TS Server high number of inotify watchers Jan 6, 2020
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jan 13, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.1 milestone Jan 13, 2020
@sheetalkamat
Copy link
Member

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_modules for 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.

@sheetalkamat sheetalkamat changed the title TS Server high number of inotify watchers Add a way to exclude file or directory watching Jan 29, 2020
@sheetalkamat sheetalkamat added feature-request A request for a new feature Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature and removed Needs Investigation This issue needs a team member to investigate its status. feature-request A request for a new feature labels Jan 29, 2020
@sheetalkamat sheetalkamat removed this from the TypeScript 3.8.1 milestone Jan 29, 2020
@sheetalkamat sheetalkamat added Fix Available A PR has been opened for this issue and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Jun 24, 2020
@sheetalkamat sheetalkamat linked a pull request Jun 25, 2020 that will close this issue
@sheetalkamat sheetalkamat added this to the TypeScript 4.1 milestone Jul 10, 2020
@DanTup
Copy link

DanTup commented Aug 25, 2020

@sheetalkamat

But #35615 enables us to add option to exclude directory/file watching certain things

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 tsc directly (test code). Right now, the tsc --watch for the tests will intermittently see when the webpack output is written to out/dist and then hang:

DirectoryWatcher:: Triggered with /users/danny/dev/dart-code/out/dist/extension.js.map :: WatchInfo: /users/danny/dev/dart-code 1 undefined Wild card directory
Project: /Users/danny/Dev/Dart-Code/tsconfig.json Detected file add/remove of non supported extension: /users/danny/dev/dart-code/out/dist/extension.js.map
Elapsed:: 0ms DirectoryWatcher:: Triggered with /users/danny/dev/dart-code/out/dist/extension.js.map :: WatchInfo: /users/danny/dev/dart-code 1 undefined Wild card directory
[16:03:33] File change detected. Starting incremental compilation...

Reloading new file names and options
Synchronizing program

I've no idea why it's hanging, but I'd like to exclude the out folder from its watching (it's already listed in exclude in tsconfig.json but that doesn't change anything).

@Whalesoft19
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants