@@ -456,7 +456,11 @@ func (p *Program) GetBindDiagnostics(ctx context.Context, sourceFile *ast.Source
456456}
457457
458458func (p * Program ) GetSemanticDiagnostics (ctx context.Context , sourceFile * ast.SourceFile ) []* ast.Diagnostic {
459- return p .collectDiagnostics (ctx , sourceFile , true /*concurrent*/ , p .getSemanticDiagnosticsForFile )
459+ diags := p .collectDiagnostics (ctx , sourceFile , true /*concurrent*/ , p .getSemanticDiagnosticsForFile )
460+ if sourceFile == nil {
461+ diags = core .Concatenate (diags , p .getGlobalDiagnostics ())
462+ }
463+ return SortAndDeduplicateDiagnostics (diags )
460464}
461465
462466func (p * Program ) GetSemanticDiagnosticsWithoutNoEmitFiltering (ctx context.Context , sourceFiles []* ast.SourceFile ) map [* ast.SourceFile ][]* ast.Diagnostic {
@@ -1026,7 +1030,7 @@ func emitModuleKindIsNonNodeESM(moduleKind core.ModuleKind) bool {
10261030 return moduleKind >= core .ModuleKindES2015 && moduleKind <= core .ModuleKindESNext
10271031}
10281032
1029- func (p * Program ) GetGlobalDiagnostics ( ctx context. Context ) []* ast.Diagnostic {
1033+ func (p * Program ) getGlobalDiagnostics ( ) []* ast.Diagnostic {
10301034 if len (p .files ) == 0 {
10311035 return nil
10321036 }
@@ -1041,7 +1045,7 @@ func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic {
10411045 globalDiagnostics [idx ] = checker .GetGlobalDiagnostics ()
10421046 })
10431047
1044- return SortAndDeduplicateDiagnostics ( slices .Concat (globalDiagnostics ... ) )
1048+ return slices .Concat (globalDiagnostics ... )
10451049}
10461050
10471051func (p * Program ) GetDeclarationDiagnostics (ctx context.Context , sourceFile * ast.SourceFile ) []* ast.Diagnostic {
@@ -1438,7 +1442,6 @@ type ProgramLike interface {
14381442 GetSyntacticDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic
14391443 GetBindDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic
14401444 GetProgramDiagnostics () []* ast.Diagnostic
1441- GetGlobalDiagnostics (ctx context.Context ) []* ast.Diagnostic
14421445 GetSemanticDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic
14431446 GetDeclarationDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic
14441447 GetSuggestionDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic
@@ -1489,15 +1492,11 @@ func GetDiagnosticsOfAnyProgram(
14891492 getBindDiagnostics (ctx , file )
14901493
14911494 if program .Options ().ListFilesOnly .IsFalseOrUnknown () {
1492- allDiagnostics = append (allDiagnostics , program .GetGlobalDiagnostics (ctx )... )
1493-
14941495 if len (allDiagnostics ) == configFileParsingDiagnosticsLength {
14951496 allDiagnostics = append (allDiagnostics , getSemanticDiagnostics (ctx , file )... )
1496- // Ask for the global diagnostics again (they were empty above); we may have found new during checking, e.g. missing globals.
1497- allDiagnostics = append (allDiagnostics , program .GetGlobalDiagnostics (ctx )... )
14981497 }
14991498
1500- if ( skipNoEmitCheckForDtsDiagnostics || program .Options ().NoEmit .IsTrue ()) && program .Options ().GetEmitDeclarations () && len ( allDiagnostics ) == configFileParsingDiagnosticsLength {
1499+ if len ( allDiagnostics ) == configFileParsingDiagnosticsLength && ( skipNoEmitCheckForDtsDiagnostics || program .Options ().NoEmit .IsTrue ()) && program .Options ().GetEmitDeclarations () {
15011500 allDiagnostics = append (allDiagnostics , program .GetDeclarationDiagnostics (ctx , file )... )
15021501 }
15031502 }
0 commit comments