Skip to content

Watch extended configs if present - #41493

Merged
Sheetal Nandi (sheetalkamat) merged 10 commits into
microsoft:masterfrom
bloomberg:watch-tsconfig-extends
Dec 11, 2020
Merged

Watch extended configs if present#41493
Sheetal Nandi (sheetalkamat) merged 10 commits into
microsoft:masterfrom
bloomberg:watch-tsconfig-extends

Conversation

@molisani

@molisaniMichael Molisani (molisani) commented Nov 11, 2020

Copy link
Copy Markdown
Contributor

Fixes#17753

Inspects extendedSourceFiles from configFile in CompilerOptions and starts a watcher for each file. Watch callback invokes scheduleProgramReload just like the watcher for the main config file. Watcher pattern modelled after watcher map for missing files. Also provides shared watcher map for situations where multiple projects are open at once (tsbuild/tsserver).

Added new test cases, including chain of extended configs and ones copied from watchEnvironment/watchOptions with extended configs to verify they are being watched.

Comment threadsrc/compiler/watchPublic.ts Outdated
Comment threadsrc/compiler/watchPublic.ts Outdated
Comment threadsrc/compiler/watchUtilities.ts Outdated
Comment threadsrc/testRunner/unittests/tscWatch/watchEnvironment.ts Outdated
Comment threadsrc/testRunner/unittests/tscWatch/watchEnvironment.ts Outdated
Comment threadsrc/testRunner/unittests/tscWatch/watchEnvironment.ts Outdated
Comment threadsrc/compiler/watchPublic.ts Outdated
Comment threadsrc/server/editorServices.ts
Comment threadsrc/server/editorServices.ts
Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/project.ts Outdated
Comment threadsrc/testRunner/unittests/tsserver/configuredProjects.ts Outdated
Comment threadsrc/testRunner/unittests/tsserver/configuredProjects.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated
@molisani

Michael Molisani (molisani) commented Nov 19, 2020

Copy link
Copy Markdown
ContributorAuthor

I've rebased onto master, but I'm now getting some (seemingly) unrelated errors with some jsx baselines. Here are my local copies of the two failing baseline tests: jsFileCompilationTypeArgumentSyntaxOfCall.errors.txt and jsxCheckJsxNoTypeArgumentsAllowed.errors.txt. I'm going to do some more investigating, but wanted to report my local copies here on the PR if anyone could advise in this situation. This appears to be a known issue that is being fixed by #41602

Comment threadsrc/compiler/watchUtilities.ts Outdated
Comment threadsrc/compiler/watchUtilities.ts Outdated
) {
const extendedSourceFiles = configFile.extendedSourceFiles || emptyArray;
// TODO(rbuckton): Should be a `Set` but that requires changing the below code that uses `mutateMap`
const newExtendedConfigFilesMap = arrayToMap(extendedSourceFiles, identity, returnTrue);

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.

Key needs to be Path, value needs to be file name to watch

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 doesnot create the key with Path

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Ah, I missed the meaning of this the first time around. I'll pass something to allow converting from string to Path.

Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated
Comment threadsrc/server/editorServices.ts Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will update to correctly account for removals, and add new tests. Had a few questions about latest review.

Comment threadsrc/compiler/watchUtilities.ts Outdated
@molisani

Copy link
Copy Markdown
ContributorAuthor

While creating a test case for removing projects, I noticed that I had not considered the builder's watch logic. I'll replicate the "shared" watcher pattern from the server here as well.

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 have some more feedback but i am going to try fixing some of those myself as that might be easier

Comment threadsrc/compiler/tsbuildPublic.ts Outdated
Comment threadsrc/compiler/tsbuildPublic.ts Outdated
Comment threadsrc/compiler/tsbuildPublic.ts Outdated
Comment threadsrc/compiler/tsbuildPublic.ts Outdated
Comment threadsrc/compiler/tsbuildPublic.ts Outdated
Comment threadsrc/compiler/watchPublic.ts Outdated
Comment threadsrc/compiler/watchUtilities.ts Outdated
) {
const extendedSourceFiles = configFile.extendedSourceFiles || emptyArray;
// TODO(rbuckton): Should be a `Set` but that requires changing the below code that uses `mutateMap`
const newExtendedConfigFilesMap = arrayToMap(extendedSourceFiles, identity, returnTrue);

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 doesnot create the key with Path

@molisani

Copy link
Copy Markdown
ContributorAuthor

I have some more feedback but i am going to try fixing some of those myself as that might be easier

Thank you very much for those suggestions. I merged all of them and then applied the toPath conversion.

@sheetalkamat

Copy link
Copy Markdown
Member

Please cherry pick e2d178f as i dont have permission to update your fork.

Added new `WatchType` for extended config files. Refactored watch map
update to separate function, relocated call sites. Removed unnecessary
test cases and relocated with new tests in programUpdates.
Update `updateExtendedConfigFilesWatch` to read from a
`TsConfigSourceFile` to get `extendedSourceFiles`. Add watcher map to
`ConfiguredProject` in the server. New test cases to verify correct
events triggered and extended files are being watched properly.
Removes unnecessary actions in extended config watcher callback
function. Updates tests to match.
New shared watcher map in ProjectService that stores callbacks per
project to be invoked when the file watcher is triggered. The
FileWatcher is created with the watch options of the first Project to
watch the extended config.
Remove all server-related utility functions/types from
watchUtilities. Store config-project mapping and config file watchers
inside ProjectService with new private methods to add or remove
projects.
Creates SharedExtendedConfigFileWatcher in both editorServices
(tsserver) and tsbuildPublic. The file watcher is responsible for
triggering a full project reload for the contained projects. Upon
reload, any configs that are no longer related to a project have their
watchers updated to match. New test cases to confirm that the file
watchers for extended configs are closed when the project is closed.
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
@molisani

Copy link
Copy Markdown
ContributorAuthor

Please cherry pick e2d178f as i dont have permission to update your fork.

The unified SharedExtendedConfigFileWatcher makes a lot more sense now that it's being used by tsbuild and tsserver. I also had to rebase due to a merge conflict in src/server/project.ts but it was a small one. Thanks again for your help.

@sheetalkamat
Sheetal Nandi (sheetalkamat) merged commit 716b167 into microsoft:masterDec 11, 2020
@molisani
Michael Molisani (molisani) deleted the watch-tsconfig-extends branch December 11, 2020 15:31
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone BugPRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Apart from watching config file for the project updates, we probably should also watch extended config file

4 participants

@molisani@sheetalkamat@sandersn@typescript-bot