@@ -33,14 +33,32 @@ namespace ts {
3333 Diagnostics . Found_0_errors_Watching_for_file_changes . code
3434 ] ;
3535
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 {
3740 if ( system . clearScreen &&
3841 ! options . preserveWatchOutput &&
3942 ! options . extendedDiagnostics &&
4043 ! options . diagnostics &&
4144 ! contains ( nonClearingMessageCodes , diagnostic . code ) ) {
4245 system . clearScreen ( ) ;
46+ return true ;
4347 }
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 ;
4462 }
4563
4664 /**
@@ -51,13 +69,19 @@ namespace ts {
5169 ( diagnostic , newLine , options ) => {
5270 clearScreenIfNotWatchingForFileChanges ( system , diagnostic , options ) ;
5371 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 } ` ;
5573 system . write ( output ) ;
5674 } :
5775 ( 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+
6185 system . write ( output ) ;
6286 } ;
6387 }
0 commit comments