Skip to content

Project references in a program #1078

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

Merged
merged 11 commits into from
Jun 10, 2025
Merged

Project references in a program #1078

merged 11 commits into from
Jun 10, 2025

Conversation

sheetalkamat
Copy link
Member

@sheetalkamat sheetalkamat commented Jun 6, 2025

Adds support to parse project reference configs, redirect to either output or source depending on options

TODOs as next PR:

  • Finding right default project
  • Combining results from multiple projects for FAR
  • Verifying project references and its options

@sheetalkamat sheetalkamat force-pushed the references branch 12 times, most recently from 36a4391 to 41e38d3 Compare June 10, 2025 05:23
@sheetalkamat sheetalkamat marked this pull request as ready for review June 10, 2025 15:54
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

Adds support for parsing and applying project reference configurations, enabling conditional redirection between source files and generated declaration outputs.

  • Replace a simple map with a thread-safe SyncMap for extended config caching and update performCompilation accordingly.
  • Introduce core helpers to resolve project reference paths and compute common source directories.
  • Extend the file loader, program, and checker to generate parse tasks for project references and redirect module resolution based on options.

Reviewed Changes

Copilot reviewed 56 out of 56 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/execute/tsc.go Swap out map-based cache for SyncMap and update performCompilation API
internal/core/projectreference.go Add functions to resolve project reference config file paths
internal/core/commonsourcedirectory.go Implement logic to compute common source directory for a set of files
internal/compiler/fileloader.go Hook in project reference parse tasks and initialize the reference mapper
internal/checker/utilities.go Extend SkipTypeChecking to skip files originating from project references
Comments suppressed due to low confidence (4)

internal/core/commonsourcedirectory.go:1

  • [nitpick] New functions like computeCommonSourceDirectoryOfFilenames lack unit tests; consider adding tests for various path layouts and edge cases.
package core

internal/core/projectreference.go:11

  • [nitpick] Add unit tests for ResolveProjectReferencePath (and its helper) to verify correct handling of JSON vs directory inputs.
func ResolveProjectReferencePath(ref *ProjectReference) string {

internal/core/commonsourcedirectory.go:20

  • The helper 'min' is undefined; compute the minimum explicitly (e.g., if a < b { n = a } else { n = b }) or import a valid utility.
n := min(len(commonPathComponents), len(sourcePathComponents))

internal/core/commonsourcedirectory.go:21

  • Cannot range over an integer; replace with a classic for loop: for i := 0; i < n; i++ { ... }.
for i := range n {

@@ -115,8 +116,8 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars

if configFileName != "" {
configStart := sys.Now()
extendedConfigCache := map[tspath.Path]*tsoptions.ExtendedConfigCacheEntry{}
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(configFileName, compilerOptionsFromCommandLine, sys, extendedConfigCache)
extendedConfigCache := collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry]{}
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually do this concurrently enough to require a SyncMap?

Copy link
Member Author

Choose a reason for hiding this comment

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

we will with project references - many projects could be using same extends cache and parsing at the same time.

@sheetalkamat sheetalkamat requested a review from jakebailey June 10, 2025 20:23
return w.collectWorker(loader, tasks, iterate, collections.Set[K]{})
}

func (w *fileLoaderWorker[K]) collectWorker(loader *fileLoader, tasks []K, iterate func(K, []tspath.Path), seen collections.Set[K]) []tspath.Path {
Copy link
Member

Choose a reason for hiding this comment

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

I am suspicious of collections.Set[K] just because it's an auto-initializing struct containing a map, which means passing it by value will cause separate call chains to not actually share that underlying map. Perhaps a pointer is warranted here?

Copy link
Member

Choose a reason for hiding this comment

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

I guess this probably works out because the first thing it does is add the task, so any recursive calls will have preinitialized the map.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. which is why i didnt make it address but i can if thats more clear

Copy link
Member

Choose a reason for hiding this comment

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

I guess it's fine for now. I'll probably noCopy these in the future to make the bug impossible, but there's technically no bug here.

@sheetalkamat sheetalkamat added this pull request to the merge queue Jun 10, 2025
Merged via the queue into main with commit 90a49a3 Jun 10, 2025
22 checks passed
@sheetalkamat sheetalkamat deleted the references branch June 10, 2025 21:29
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.

3 participants