Skip to content

Incremental watch host fixes #1453 #1457

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

Closed
wants to merge 2 commits into from

Conversation

joshcartme
Copy link
Contributor

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 24, 2025 23:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issues with the incremental watch host functionality by refactoring how the compiler host is shared across different compilation modes. The changes ensure that the same compiler host instance is used consistently for watch mode, incremental compilation, and regular compilation, preventing potential issues with inconsistent state.

Key changes:

  • Moved compiler host creation up to the main compilation function to ensure consistent host usage
  • Updated function signatures to accept the host as a parameter instead of creating separate instances
  • Added a test case for watch mode with incremental compilation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/execute/tsc.go Refactored to create a single compiler host instance and pass it to all compilation functions
internal/execute/watcher.go Updated createWatcher function to accept compiler host as parameter
internal/execute/tscwatch_test.go Added test case for watch with tsconfig and incremental compilation
testdata/baselines/reference/tscWatch/commandLineWatch/watch-with-tsconfig-and-incremental.js New baseline file for the added test case

@jakebailey
Copy link
Member

#1457 was supposed to fix the issue; is this PR still needed?

Copy link
Member

@sheetalkamat sheetalkamat left a comment

Choose a reason for hiding this comment

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

This is fixed by #1455

@joshcartme
Copy link
Contributor Author

Oh, yeah #1455 did fix it (I haven't tried it, but it looks about the same)!

My fix is a little different in that instead of creating host in the three functions that can return here,

if configForCompilation.CompilerOptions().Watch.IsTrue() {
watcher := createWatcher(sys, configForCompilation, reportDiagnostic, testing)
watcher.start()
return CommandLineResult{Status: ExitStatusSuccess, Watcher: watcher}
} else if configForCompilation.CompilerOptions().IsIncremental() {
return performIncrementalCompilation(
sys,
configForCompilation,
reportDiagnostic,
&extendedConfigCache,
configTime,
testing,
)
}
return performCompilation(
sys,
configForCompilation,
reportDiagnostic,
&extendedConfigCache,
configTime,
)

it's created before the if/else and then passed in, so it's a little DRYer.

I don't understand the implications of setting ExtendedConfigCacheEntry to nil here:

w.host = compiler.NewCompilerHost(w.sys.GetCurrentDirectory(), w.sys.FS(), w.sys.DefaultLibraryPath(), nil)

That is different than the other places that create host around there and in this PR I didn't and instead just created host like I saw in the other two places.

Totally happy to close this!

@jakebailey
Copy link
Member

nil is okay, just means "make a fresh cache for yourself".

@joshcartme
Copy link
Contributor Author

Ok got it, closing. Thanks!

@joshcartme joshcartme closed this Jul 24, 2025
@tmm1
Copy link
Contributor

tmm1 commented Jul 24, 2025

You'll find that --watch still eats a ton of cpu /cc #1317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants