Skip to content

Add way to exclude files and directories to watch - #39243

Merged
Sheetal Nandi (sheetalkamat) merged 23 commits into
masterfrom
watchIgnore
Nov 4, 2020
Merged

Add way to exclude files and directories to watch#39243
Sheetal Nandi (sheetalkamat) merged 23 commits into
masterfrom
watchIgnore

Conversation

@sheetalkamat

@sheetalkamat Sheetal Nandi (sheetalkamat) commented Jun 24, 2020

Copy link
Copy Markdown
Member

This allows user a way to specify directories and/or files to ignore:

  • 869abb1 Adds parsing of new watchOptions: excludeFiles and excludeDirectories in tsconfig as well as command line
  • 9cd3e93 Adds a way to create noopWatcher for files and directories that are being watched.
  • dddd906 Adds a way to exclude invoking callback for excluded things from sys itself. This means no invoke for excluded path if its invoked from recursive directory watching or not watching directories that are excluded on os that don't support recursive watching (like linux)
  • 0a8d84f handles the server host configuration and external/inferred projects watch options with ignore.
  • 496939d reloading projects, reloads project from scratch
  • cd18da8 file updates when reloading are reflected

This provides a way on systems where watching can be expensive and letting user refresh things if something changes rather than us having to poll or rely on events
Fixes #33335, #36035, #36243, #36394

@typescript-bot

Copy link
Copy Markdown
Contributor

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping Sheetal Nandi (@sheetalkamat), Andrew Casey (@amcasey), Matt Bierner (@mjbvz), Mine Starks (@minestarks) for you. Feel free to loop in other consumers/maintainers if necessary

@sheetalkamat

Copy link
Copy Markdown
Member Author

This is now ready for review

@amcasey

Copy link
Copy Markdown
Member

letting user refresh things

Remind me how the editor does this? Is there a protocol refresh to re-poll the disk?

os that don't support recursive watching (like linux)

Does that mean Windows and Mac do support recursive watching?

@sheetalkamat

Copy link
Copy Markdown
Member Author

Remind me how the editor does this? Is there a protocol refresh to re-poll the disk?

Restart tsserver from vscode.. Dont know about vs command for that

Does that mean Windows and Mac do support recursive watching?

Yes: https://github.com/microsoft/TypeScript/blob/master/src/compiler/sys.ts#L1163

@amcasey

Copy link
Copy Markdown
Member

Remind me how the editor does this? Is there a protocol refresh to re-poll the disk?

Restart tsserver from vscode.. Dont know about vs command for that

That seems like overkill. Wouldn't there be a shorter delay if we just repolled all the files and then did an updateGraph? The user scenario I have in mind is hitting refresh in the file list tool window (aka the Solution Explorer in VS).

@amcasey

Copy link
Copy Markdown
Member

cc Matt Bierner (@mjbvz) for the VS Code user experience.

@sheetalkamat

Copy link
Copy Markdown
Member Author

Andrew Casey (@amcasey) Interesting point. I think reload should definitely reload everything and makes sense to refresh but i would need to think about how to do that when server is not restarted...

@amcasey

Copy link
Copy Markdown
Member

Sheetal Nandi (@sheetalkamat) I was thinking it would be like simulating a file listener event - the server would just do whatever it does when it finds out one or more files have changed on disk (ideally, as a batch, rather than as a loop of updates).

@larose

Mathieu Larose (larose) commented Jul 6, 2020

Copy link
Copy Markdown

Thanks for this PR Sheetal Nandi (@sheetalkamat). I really look forward for this PR to be merged as VS Code/TypeScript is unfortunately too often unresponsive on Linux when I'm working on one of my project that has about 2000 packages in node_modules. Let me know if I can do anything to help you.

@controlrepo

Copy link
Copy Markdown

That'd be amazing to have this one resolved finally. It has been first reported almost 2 years ago and there's little progress.

   INOTIFY
   WATCHER
    COUNT     PID     CMD
----------------------------------------
  503994     4631  /usr/share/code/code /usr/share/code/resources/app/out/bootstrap-fork --type=watcherService
   20038     4631  /usr/share/code/code /usr/share/code/resources/app/out/bootstrap-fork --type=watcherService

That's quite extensive for a

(Fedora31, vsc 1.47.2)
(and I don't even have any node_modules folder, and tried it all to ignore everything and unignore only very few folders which disrupted my experience with ag, but to no avail. It's ridiculous).

@sheetalkamat

Copy link
Copy Markdown
Member Author

Andrew Casey (@amcasey) i have updated the PR per your suggestion so that reload projects, loads the project from scratch

@amcasey Andrew Casey (amcasey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a surprisingly large change and I'm still going through some things, but here's my first round of comments.

Comment thread src/compiler/commandLineParser.ts Outdated
Comment thread src/compiler/commandLineParser.ts
Comment thread src/compiler/commandLineParser.ts
Comment thread src/compiler/commandLineParser.ts
Comment thread src/compiler/commandLineParser.ts
Comment thread src/compiler/sys.ts
Comment thread src/compiler/sys.ts
Comment thread src/compiler/watchPublic.ts
Comment thread src/server/editorServices.ts
@amcasey

Copy link
Copy Markdown
Member

Matt Bierner (@mjbvz) Could you possibly confirm that the new project reload functionality behaves sensibly in VS Code? I don't believe VS uses it.

@sheetalkamat

Copy link
Copy Markdown
Member Author

Andrew Casey (@amcasey) Matt Bierner (@mjbvz) i would like to get this in for 4.2
Can you please review

@mjbvz Matt Bierner (mjbvz) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protocol changes look good to me.

Do you think we should add VS Code settings to control this too?

@amcasey Andrew Casey (amcasey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the concept, I have some quibbles with the implementation, and I have one remaining concern: can I disable all file watching and just hit "refresh" in the editor to trigger it when I need it?

Comment thread src/compiler/commandLineParser.ts
Comment thread src/compiler/sys.ts
Comment thread src/compiler/commandLineParser.ts Outdated
@Utsav2

Copy link
Copy Markdown

Are there any docs for this feature? Also, does this automatically take the include and exclude dirs from tsconfig.json? it seems unintuitive that the watch is set up on files ignored by tsc

@sheetalkamat

Copy link
Copy Markdown
Member Author

By default nothing is ignored. User has to opt for directories/files to ignore..
Orta Therox (@orta) i think this is not in tsconfig reference section yet.

@orta

Copy link
Copy Markdown
Contributor

Thanks sheetal - looks like I manually re-created a partial set of the watch flags back when I made the tsconfig reference, will move it to be automatic to pick these up!

@Kieran-Lynn

Kieran Lynn (Kieran-Lynn) commented Apr 17, 2021

Copy link
Copy Markdown

Orta Therox (@orta) Sheetal Nandi (@sheetalkamat) I cant seem to find any docs on this.

https://www.typescriptlang.org/tsconfig#Watch_Options_999

This has nothing about the new fields that are supposed to be added. Im trying to add

"watchOptions": { "excludeDirectories" : ["node_modules"] }

to my tsconfig but Im still getting extremely slow load times on my project when using vscode in WSL with files on the C drive

@sheetalkamat

Copy link
Copy Markdown
Member Author

@Kierchon it also needs to be set in vscode preferences but i dont find it in vscode preferences in watchOptions
Matt Bierner (@mjbvz) did we miss adding excludeDirectories and excludeFiles as watchOption in vscode preferences?

@mjbvz

Copy link
Copy Markdown

You should just be able to add them in the settings.json:

  "typescript.tsserver.watchOptions": {
    "watchFile": "useFsEvents",
    "excludeDirectories": []
  },

We pass the entire object on the TS Server

Sheetal Nandi (@sheetalkamat) Should these settings also be documented? If so, can you please share a quick blurb about what these two settings do

@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Archived in project

10 participants