Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Project references in a program - #1078

Merged
Sheetal Nandi (sheetalkamat) merged 11 commits into
mainfrom
references
Jun 10, 2025
Merged

Sheetal Nandi (sheetalkamat) merged 11 commits into
mainfrom
references

Conversation

@sheetalkamat

@sheetalkamat Sheetal Nandi (sheetalkamat) commented Jun 6, 2025 •

Copy link
Copy Markdown
Member

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
Sheetal Nandi (sheetalkamat) force-pushed the references branch 12 times, most recently from 36a4391 to 41e38d3 Compare June 10, 2025 05:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 {

Comment thread internal/core/projectreference.go Resolved
Comment thread internal/compiler/fileloader.go Resolved
Comment thread internal/ast/utilities.go Resolved
Comment thread internal/checker/utilities.go Resolved
Comment thread internal/compiler/fileloader.go Resolved
Comment thread internal/compiler/fileloader.go Resolved
Comment thread internal/compiler/host.go Resolved
Comment thread internal/core/commonsourcedirectory.go Resolved
Comment thread internal/core/projectreference.go Resolved
Comment thread internal/execute/tsc.go
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
Copy Markdown
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
Copy Markdown
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.

Comment thread internal/module/resolver.go Resolved
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants