@@ -394,9 +394,9 @@ namespace ts {
394
394
let globalDependencyGraph : DependencyGraph | undefined ;
395
395
396
396
// Watch state
397
- // TODO(shkamat): this should be really be diagnostics but thats for later time
398
- const diagnostics = createFileMap < number > ( toPath ) ;
397
+ const diagnostics = createFileMap < ReadonlyArray < Diagnostic > > ( toPath ) ;
399
398
const projectPendingBuild = createFileMap < ConfigFileProgramReloadLevel > ( toPath ) ;
399
+ const projectErrorsReported = createFileMap < true > ( toPath ) ;
400
400
const invalidatedProjectQueue = [ ] as ResolvedConfigFileName [ ] ;
401
401
let nextProjectToBuild = 0 ;
402
402
let timerToBuildInvalidatedProject : any ;
@@ -438,6 +438,7 @@ namespace ts {
438
438
439
439
diagnostics . clear ( ) ;
440
440
projectPendingBuild . clear ( ) ;
441
+ projectErrorsReported . clear ( ) ;
441
442
invalidatedProjectQueue . length = 0 ;
442
443
nextProjectToBuild = 0 ;
443
444
if ( timerToBuildInvalidatedProject ) {
@@ -472,18 +473,6 @@ namespace ts {
472
473
host . reportSolutionBuilderStatus ( createCompilerDiagnostic ( message , ...args ) ) ;
473
474
}
474
475
475
- function storeErrors ( proj : ResolvedConfigFileName , diagnostics : ReadonlyArray < Diagnostic > ) {
476
- if ( options . watch ) {
477
- storeErrorSummary ( proj , diagnostics . filter ( diagnostic => diagnostic . category === DiagnosticCategory . Error ) . length ) ;
478
- }
479
- }
480
-
481
- function storeErrorSummary ( proj : ResolvedConfigFileName , errorCount : number ) {
482
- if ( options . watch ) {
483
- diagnostics . setValue ( proj , errorCount ) ;
484
- }
485
- }
486
-
487
476
function reportWatchStatus ( message : DiagnosticMessage , ...args : ( string | number | undefined ) [ ] ) {
488
477
if ( hostWithWatch . onWatchStatusChange ) {
489
478
hostWithWatch . onWatchStatusChange ( createCompilerDiagnostic ( message , ...args ) , host . getNewLine ( ) , { preserveWatchOutput : options . preserveWatchOutput } ) ;
@@ -509,14 +498,15 @@ namespace ts {
509
498
}
510
499
511
500
function watchConfigFile ( resolved : ResolvedConfigFileName ) {
512
- if ( ! allWatchedConfigFiles . hasKey ( resolved ) ) {
501
+ if ( options . watch && ! allWatchedConfigFiles . hasKey ( resolved ) ) {
513
502
allWatchedConfigFiles . setValue ( resolved , hostWithWatch . watchFile ( resolved , ( ) => {
514
503
invalidateProjectAndScheduleBuilds ( resolved , ConfigFileProgramReloadLevel . Full ) ;
515
504
} ) ) ;
516
505
}
517
506
}
518
507
519
508
function watchWildCardDirectories ( resolved : ResolvedConfigFileName , parsed : ParsedCommandLine ) {
509
+ if ( ! options . watch ) return ;
520
510
updateWatchingWildcardDirectories (
521
511
getOrCreateValueMapFromConfigFileMap ( allWatchedWildcardDirectories , resolved ) ,
522
512
createMapFromTemplate ( parsed . configFileSpecs ! . wildcardDirectories ) ,
@@ -540,6 +530,7 @@ namespace ts {
540
530
}
541
531
542
532
function watchInputFiles ( resolved : ResolvedConfigFileName , parsed : ParsedCommandLine ) {
533
+ if ( ! options . watch ) return ;
543
534
mutateMap (
544
535
getOrCreateValueMapFromConfigFileMap ( allWatchedInputFiles , resolved ) ,
545
536
arrayToMap ( parsed . fileNames , toPath ) ,
@@ -848,6 +839,7 @@ namespace ts {
848
839
timerToBuildInvalidatedProject = undefined ;
849
840
if ( reportFileChangeDetected ) {
850
841
reportFileChangeDetected = false ;
842
+ projectErrorsReported . clear ( ) ;
851
843
reportWatchStatus ( Diagnostics . File_change_detected_Starting_incremental_compilation ) ;
852
844
}
853
845
const buildProject = getNextInvalidatedProject ( ) ;
@@ -866,15 +858,19 @@ namespace ts {
866
858
867
859
function reportErrorSummary ( ) {
868
860
if ( options . watch ) {
861
+ // Report errors from the other projects
862
+ getGlobalDependencyGraph ( ) . buildQueue . forEach ( project => {
863
+ if ( ! projectErrorsReported . hasKey ( project ) ) {
864
+ reportErrors ( diagnostics . getValue ( project ) || emptyArray ) ;
865
+ }
866
+ } ) ;
869
867
let totalErrors = 0 ;
870
- diagnostics . forEach ( singleProjectErrors => totalErrors += singleProjectErrors ) ;
868
+ diagnostics . forEach ( singleProjectErrors => totalErrors += singleProjectErrors . filter ( diagnostic => diagnostic . category === DiagnosticCategory . Error ) . length ) ;
871
869
reportWatchStatus ( totalErrors === 1 ? Diagnostics . Found_1_error_Watching_for_file_changes : Diagnostics . Found_0_errors_Watching_for_file_changes , totalErrors ) ;
872
870
}
873
871
}
874
872
875
873
function buildSingleInvalidatedProject ( resolved : ResolvedConfigFileName , reloadLevel : ConfigFileProgramReloadLevel ) {
876
- // TODO:: handle this in better way later
877
-
878
874
const proj = parseConfigFile ( resolved ) ;
879
875
if ( ! proj ) {
880
876
reportParseConfigFileDiagnostic ( resolved ) ;
@@ -968,10 +964,6 @@ namespace ts {
968
964
}
969
965
}
970
966
971
- function reportParseConfigFileDiagnostic ( proj : ResolvedConfigFileName ) {
972
- host . reportDiagnostic ( configFileCache . getValue ( proj ) as Diagnostic ) ;
973
- storeErrorSummary ( proj , 1 ) ;
974
- }
975
967
976
968
function buildSingleProject ( proj : ResolvedConfigFileName ) : BuildResultFlags {
977
969
if ( options . dry ) {
@@ -1013,7 +1005,7 @@ namespace ts {
1013
1005
...program . getSyntacticDiagnostics ( ) ] ;
1014
1006
if ( syntaxDiagnostics . length ) {
1015
1007
resultFlags |= BuildResultFlags . SyntaxErrors ;
1016
- reportErrors ( proj , syntaxDiagnostics ) ;
1008
+ reportAndStoreErrors ( proj , syntaxDiagnostics ) ;
1017
1009
projectStatus . setValue ( proj , { type : UpToDateStatusType . Unbuildable , reason : "Syntactic errors" } ) ;
1018
1010
return resultFlags ;
1019
1011
}
@@ -1023,7 +1015,7 @@ namespace ts {
1023
1015
const declDiagnostics = program . getDeclarationDiagnostics ( ) ;
1024
1016
if ( declDiagnostics . length ) {
1025
1017
resultFlags |= BuildResultFlags . DeclarationEmitErrors ;
1026
- reportErrors ( proj , declDiagnostics ) ;
1018
+ reportAndStoreErrors ( proj , declDiagnostics ) ;
1027
1019
projectStatus . setValue ( proj , { type : UpToDateStatusType . Unbuildable , reason : "Declaration file errors" } ) ;
1028
1020
return resultFlags ;
1029
1021
}
@@ -1033,7 +1025,7 @@ namespace ts {
1033
1025
const semanticDiagnostics = program . getSemanticDiagnostics ( ) ;
1034
1026
if ( semanticDiagnostics . length ) {
1035
1027
resultFlags |= BuildResultFlags . TypeErrors ;
1036
- reportErrors ( proj , semanticDiagnostics ) ;
1028
+ reportAndStoreErrors ( proj , semanticDiagnostics ) ;
1037
1029
projectStatus . setValue ( proj , { type : UpToDateStatusType . Unbuildable , reason : "Semantic errors" } ) ;
1038
1030
return resultFlags ;
1039
1031
}
@@ -1154,7 +1146,7 @@ namespace ts {
1154
1146
1155
1147
const projName = proj . options . configFilePath ! ;
1156
1148
if ( status . type === UpToDateStatusType . UpToDate && ! options . force ) {
1157
- reportErrors ( next , errors ) ;
1149
+ reportAndStoreErrors ( next , errors ) ;
1158
1150
// Up to date, skip
1159
1151
if ( defaultOptions . dry ) {
1160
1152
// In a dry build, inform the user of this fact
@@ -1164,20 +1156,20 @@ namespace ts {
1164
1156
}
1165
1157
1166
1158
if ( status . type === UpToDateStatusType . UpToDateWithUpstreamTypes && ! options . force ) {
1167
- reportErrors ( next , errors ) ;
1159
+ reportAndStoreErrors ( next , errors ) ;
1168
1160
// Fake build
1169
1161
updateOutputTimestamps ( proj ) ;
1170
1162
continue ;
1171
1163
}
1172
1164
1173
1165
if ( status . type === UpToDateStatusType . UpstreamBlocked ) {
1174
- reportErrors ( next , errors ) ;
1166
+ reportAndStoreErrors ( next , errors ) ;
1175
1167
if ( options . verbose ) reportStatus ( Diagnostics . Skipping_build_of_project_0_because_its_dependency_1_has_errors , projName , status . upstreamProjectName ) ;
1176
1168
continue ;
1177
1169
}
1178
1170
1179
1171
if ( status . type === UpToDateStatusType . ContainerOnly ) {
1180
- reportErrors ( next , errors ) ;
1172
+ reportAndStoreErrors ( next , errors ) ;
1181
1173
// Do nothing
1182
1174
continue ;
1183
1175
}
@@ -1189,9 +1181,20 @@ namespace ts {
1189
1181
return anyFailed ? ExitStatus . DiagnosticsPresent_OutputsSkipped : ExitStatus . Success ;
1190
1182
}
1191
1183
1192
- function reportErrors ( proj : ResolvedConfigFileName , errors : ReadonlyArray < Diagnostic > ) {
1184
+ function reportParseConfigFileDiagnostic ( proj : ResolvedConfigFileName ) {
1185
+ reportAndStoreErrors ( proj , [ configFileCache . getValue ( proj ) as Diagnostic ] ) ;
1186
+ }
1187
+
1188
+ function reportAndStoreErrors ( proj : ResolvedConfigFileName , errors : ReadonlyArray < Diagnostic > ) {
1189
+ reportErrors ( errors ) ;
1190
+ if ( options . watch ) {
1191
+ projectErrorsReported . setValue ( proj , true ) ;
1192
+ diagnostics . setValue ( proj , errors ) ;
1193
+ }
1194
+ }
1195
+
1196
+ function reportErrors ( errors : ReadonlyArray < Diagnostic > ) {
1193
1197
errors . forEach ( err => host . reportDiagnostic ( err ) ) ;
1194
- storeErrors ( proj , errors ) ;
1195
1198
}
1196
1199
1197
1200
/**
0 commit comments