diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go index 708307c455..431eb7b04a 100644 --- a/internal/compiler/fileloader.go +++ b/internal/compiler/fileloader.go @@ -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 { @@ -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 { @@ -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) @@ -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 }) @@ -201,6 +224,7 @@ func processAllProgramFiles( unsupportedExtensions: unsupportedExtensions, sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules, libFiles: libFileSet, + fileLoadDiagnostics: fileLoadDiagnostics, } } @@ -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, diff --git a/internal/compiler/parsetask.go b/internal/compiler/parsetask.go index ebb6fdcce3..9d7045bfc4 100644 --- a/internal/compiler/parsetask.go +++ b/internal/compiler/parsetask.go @@ -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 diff --git a/internal/compiler/program.go b/internal/compiler/program.go index 7dbd620a6e..f1369c3c07 100644 --- a/internal/compiler/program.go +++ b/internal/compiler/program.go @@ -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) diff --git a/internal/execute/tsc.go b/internal/execute/tsc.go index f680ff880a..c2fefa12bd 100644 --- a/internal/execute/tsc.go +++ b/internal/execute/tsc.go @@ -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), diff --git a/internal/module/resolver.go b/internal/module/resolver.go index d054c1846d..7630b78eea 100644 --- a/internal/module/resolver.go +++ b/internal/module/resolver.go @@ -54,7 +54,7 @@ type resolutionState struct { resolvedPackageDirectory bool failedLookupLocations []string affectingLocations []string - diagnostics []ast.Diagnostic + diagnostics []*ast.Diagnostic } func newResolutionState( diff --git a/internal/module/types.go b/internal/module/types.go index d0acc036da..f3c78cc715 100644 --- a/internal/module/types.go +++ b/internal/module/types.go @@ -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 { diff --git a/internal/testutil/harnessutil/harnessutil.go b/internal/testutil/harnessutil/harnessutil.go index 9c2c324ef7..043bfa27cb 100644 --- a/internal/testutil/harnessutil/harnessutil.go +++ b/internal/testutil/harnessutil/harnessutil.go @@ -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)...)