@@ -33,14 +33,32 @@ namespace ts {
33
33
Diagnostics . Found_0_errors_Watching_for_file_changes . code
34
34
] ;
35
35
36
- function clearScreenIfNotWatchingForFileChanges ( system : System , diagnostic : Diagnostic , options : CompilerOptions ) {
36
+ /**
37
+ * @returns Whether the screen was cleared.
38
+ */
39
+ function clearScreenIfNotWatchingForFileChanges ( system : System , diagnostic : Diagnostic , options : CompilerOptions ) : boolean {
37
40
if ( system . clearScreen &&
38
41
! options . preserveWatchOutput &&
39
42
! options . extendedDiagnostics &&
40
43
! options . diagnostics &&
41
44
! contains ( nonClearingMessageCodes , diagnostic . code ) ) {
42
45
system . clearScreen ( ) ;
46
+ return true ;
43
47
}
48
+
49
+ return false ;
50
+ }
51
+
52
+ /** @internal */
53
+ export const screenStartingMessageCodes : number [ ] = [
54
+ Diagnostics . Starting_compilation_in_watch_mode . code ,
55
+ Diagnostics . File_change_detected_Starting_incremental_compilation . code ,
56
+ ] ;
57
+
58
+ function getPlainDiagnosticFollowingNewLines ( diagnostic : Diagnostic , newLine : string ) : string {
59
+ return contains ( screenStartingMessageCodes , diagnostic . code )
60
+ ? newLine + newLine
61
+ : newLine ;
44
62
}
45
63
46
64
/**
@@ -51,13 +69,19 @@ namespace ts {
51
69
( diagnostic , newLine , options ) => {
52
70
clearScreenIfNotWatchingForFileChanges ( system , diagnostic , options ) ;
53
71
let output = `[${ formatColorAndReset ( new Date ( ) . toLocaleTimeString ( ) , ForegroundColorEscapeSequences . Grey ) } ] ` ;
54
- output += `${ flattenDiagnosticMessageText ( diagnostic . messageText , system . newLine ) } ${ newLine + newLine + newLine } ` ;
72
+ output += `${ flattenDiagnosticMessageText ( diagnostic . messageText , system . newLine ) } ${ newLine + newLine } ` ;
55
73
system . write ( output ) ;
56
74
} :
57
75
( diagnostic , newLine , options ) => {
58
- clearScreenIfNotWatchingForFileChanges ( system , diagnostic , options ) ;
59
- let output = new Date ( ) . toLocaleTimeString ( ) + " - " ;
60
- output += `${ flattenDiagnosticMessageText ( diagnostic . messageText , system . newLine ) } ${ newLine + newLine + newLine } ` ;
76
+ let output = "" ;
77
+
78
+ if ( ! clearScreenIfNotWatchingForFileChanges ( system , diagnostic , options ) ) {
79
+ output += newLine ;
80
+ }
81
+
82
+ output += `${ new Date ( ) . toLocaleTimeString ( ) } - ` ;
83
+ output += `${ flattenDiagnosticMessageText ( diagnostic . messageText , system . newLine ) } ${ getPlainDiagnosticFollowingNewLines ( diagnostic , newLine ) } ` ;
84
+
61
85
system . write ( output ) ;
62
86
} ;
63
87
}
0 commit comments