Skip to content

File loader diags #1304

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type processedFiles struct {
// List of present unsupported extensions
unsupportedExtensions []string
sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
fileLoadDiagnostics *ast.DiagnosticsCollection
}

type jsxRuntimeImportSpecifier struct {
Expand Down Expand Up @@ -132,6 +133,7 @@ func processAllProgramFiles(
var unsupportedExtensions []string
var sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
var libFileSet collections.Set[tspath.Path]
fileLoadDiagnostics := &ast.DiagnosticsCollection{}

loader.parseTasks.collect(&loader, loader.rootTasks, func(task *parseTask, _ []tspath.Path) {
if task.isRedirected {
Expand Down Expand Up @@ -159,6 +161,7 @@ func processAllProgramFiles(
resolvedModules[path] = task.resolutionsInFile
typeResolutionsInFile[path] = task.typeResolutionsInFile
sourceFileMetaDatas[path] = task.metadata

if task.jsxRuntimeImportSpecifier != nil {
if jsxRuntimeImportSpecifiers == nil {
jsxRuntimeImportSpecifiers = make(map[tspath.Path]*jsxRuntimeImportSpecifier, totalFileCount)
Expand All @@ -183,8 +186,28 @@ func processAllProgramFiles(

allFiles := append(libFiles, files...)

for _, resolutions := range resolvedModules {
for _, resolvedModule := range resolutions {
for _, diag := range resolvedModule.ResolutionDiagnostics {
fileLoadDiagnostics.Add(diag)
}
}
}
for _, typeResolutions := range typeResolutionsInFile {
for _, resolvedTypeRef := range typeResolutions {
for _, diag := range resolvedTypeRef.ResolutionDiagnostics {
fileLoadDiagnostics.Add(diag)
}
}
}

loader.pathForLibFileResolutions.Range(func(key tspath.Path, value module.ModeAwareCache[*module.ResolvedModule]) bool {
resolvedModules[key] = value
for _, resolvedModule := range value {
for _, diag := range resolvedModule.ResolutionDiagnostics {
fileLoadDiagnostics.Add(diag)
}
}
return true
})

Expand All @@ -201,6 +224,7 @@ func processAllProgramFiles(
unsupportedExtensions: unsupportedExtensions,
sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules,
libFiles: libFileSet,
fileLoadDiagnostics: fileLoadDiagnostics,
}
}

Expand Down Expand Up @@ -372,6 +396,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
resolutionMode := getModeForTypeReferenceDirectiveInFile(ref, file, meta, module.GetCompilerOptionsWithRedirect(p.opts.Config.CompilerOptions(), redirect))
resolved := p.resolver.ResolveTypeReferenceDirective(ref.FileName, file.FileName(), resolutionMode, redirect)
typeResolutionsInFile[module.ModeAwareCacheKey{Name: ref.FileName, Mode: resolutionMode}] = resolved

if resolved.IsResolved() {
t.addSubTask(resolvedRef{
fileName: resolved.ResolvedFileName,
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/parsetask.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type parseTask struct {
metadata ast.SourceFileMetaData
resolutionsInFile module.ModeAwareCache[*module.ResolvedModule]
typeResolutionsInFile module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
resolutionDiagnostics []*ast.Diagnostic
importHelpersImportSpecifier *ast.Node
jsxRuntimeImportSpecifier *jsxRuntimeImportSpecifier
increaseDepth bool
Expand Down
5 changes: 5 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ func (p *Program) GetSuggestionDiagnostics(ctx context.Context, sourceFile *ast.
return p.getDiagnosticsHelper(ctx, sourceFile, true /*ensureBound*/, true /*ensureChecked*/, p.getSuggestionDiagnosticsForFile)
}

func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic {
// !!!
return SortAndDeduplicateDiagnostics(p.fileLoadDiagnostics.GetDiagnostics())
}

func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic {
var globalDiagnostics []*ast.Diagnostic
checkers, done := p.checkerPool.GetAllCheckers(ctx)
Expand Down
1 change: 1 addition & 0 deletions internal/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func emitFilesAndReportErrors(sys System, program *compiler.Program, reportDiagn
configFileParsingDiagnosticsLength := len(allDiagnostics)

allDiagnostics = append(allDiagnostics, program.GetSyntacticDiagnostics(ctx, nil)...)
allDiagnostics = append(allDiagnostics, program.GetProgramDiagnostics()...)

if len(allDiagnostics) == configFileParsingDiagnosticsLength {
// Options diagnostics include global diagnostics (even though we collect them separately),
Expand Down
2 changes: 1 addition & 1 deletion internal/module/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type resolutionState struct {
resolvedPackageDirectory bool
failedLookupLocations []string
affectingLocations []string
diagnostics []ast.Diagnostic
diagnostics []*ast.Diagnostic
}

func newResolutionState(
Expand Down
2 changes: 1 addition & 1 deletion internal/module/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *PackageId) PackageName() string {
type LookupLocations struct {
FailedLookupLocations []string
AffectingLocations []string
ResolutionDiagnostics []ast.Diagnostic
ResolutionDiagnostics []*ast.Diagnostic
}

type ResolvedModule struct {
Expand Down
1 change: 1 addition & 0 deletions internal/testutil/harnessutil/harnessutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ func compileFilesWithHost(
ctx := context.Background()
program := createProgram(host, config)
var diagnostics []*ast.Diagnostic
diagnostics = append(diagnostics, program.GetProgramDiagnostics()...)
diagnostics = append(diagnostics, program.GetSyntacticDiagnostics(ctx, nil)...)
diagnostics = append(diagnostics, program.GetSemanticDiagnostics(ctx, nil)...)
diagnostics = append(diagnostics, program.GetGlobalDiagnostics(ctx)...)
Expand Down