From bc9ad90a81fc30424d3c2bc211ac17ff15e256ae Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 17 Apr 2018 08:28:12 -0700 Subject: [PATCH 1/6] Adjusted newlines in non-pretty output for consistency Fixes #23469 --- src/compiler/watch.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 7f3d078b790..f125fab5a5e 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -44,6 +44,24 @@ namespace ts { } } + /** @internal */ + const screenStartingMessageCodes: number[] = [ + Diagnostics.Starting_compilation_in_watch_mode.code, + Diagnostics.File_change_detected_Starting_incremental_compilation.code, + ]; + + function getPlainDiagnosticPrecedingNewLines(diagnostic: Diagnostic, newLine: string): string { + return contains(screenStartingMessageCodes, diagnostic.code) + ? "" + : newLine; + } + + function getPlainDiagnosticFollowingNewLines(diagnostic: Diagnostic, newLine: string): string { + return contains(screenStartingMessageCodes, diagnostic.code) + ? newLine + newLine + : newLine; + } + /** * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic */ @@ -52,13 +70,13 @@ namespace ts { (diagnostic, newLine, options) => { clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `; - output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`; + output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine}`; system.write(output); } : (diagnostic, newLine, options) => { clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); - let output = new Date().toLocaleTimeString() + " - "; - output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`; + let output = `${getPlainDiagnosticPrecedingNewLines(diagnostic, newLine)}${new Date().toLocaleTimeString()} - `; + output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`; system.write(output); }; } From c974b2ced7b284557577b5a8a477f3376723cd70 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 17 Apr 2018 08:57:05 -0700 Subject: [PATCH 2/6] Helps to check in the test changes, too --- src/compiler/watch.ts | 2 +- src/harness/unittests/tscWatchMode.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index f125fab5a5e..330aeaaa840 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -45,7 +45,7 @@ namespace ts { } /** @internal */ - const screenStartingMessageCodes: number[] = [ + export const screenStartingMessageCodes: number[] = [ Diagnostics.Starting_compilation_in_watch_mode.code, Diagnostics.File_change_detected_Starting_incremental_compilation.code, ]; diff --git a/src/harness/unittests/tscWatchMode.ts b/src/harness/unittests/tscWatchMode.ts index 99bad3e3091..d57a8e9b6d0 100644 --- a/src/harness/unittests/tscWatchMode.ts +++ b/src/harness/unittests/tscWatchMode.ts @@ -124,7 +124,10 @@ namespace ts.tscWatch { } function getWatchDiagnosticWithoutDate(diagnostic: Diagnostic) { - return ` - ${flattenDiagnosticMessageText(diagnostic.messageText, host.newLine)}${host.newLine + host.newLine + host.newLine}`; + const newLines = contains(screenStartingMessageCodes, diagnostic.code) + ? `${host.newLine}${host.newLine}` + : host.newLine; + return ` - ${flattenDiagnosticMessageText(diagnostic.messageText, host.newLine)}${newLines}`; } } From d1b044b72fecb7303336f17efafaba8b70416959 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 18 Apr 2018 17:08:43 -0700 Subject: [PATCH 3/6] Standardized for --preserveWatchOutput too --- src/compiler/watch.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 330aeaaa840..3140d975a3d 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -50,8 +50,8 @@ namespace ts { Diagnostics.File_change_detected_Starting_incremental_compilation.code, ]; - function getPlainDiagnosticPrecedingNewLines(diagnostic: Diagnostic, newLine: string): string { - return contains(screenStartingMessageCodes, diagnostic.code) + function getPlainDiagnosticPrecedingNewLines(diagnostic: Diagnostic, newLine: string, preserveWatchOutput?: boolean): string { + return !preserveWatchOutput && contains(screenStartingMessageCodes, diagnostic.code) ? "" : newLine; } @@ -75,7 +75,7 @@ namespace ts { } : (diagnostic, newLine, options) => { clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); - let output = `${getPlainDiagnosticPrecedingNewLines(diagnostic, newLine)}${new Date().toLocaleTimeString()} - `; + let output = `${getPlainDiagnosticPrecedingNewLines(diagnostic, newLine, options.preserveWatchOutput)}${new Date().toLocaleTimeString()} - `; output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`; system.write(output); }; From 8d6c2bc1b1e902d452b02f167c611bbde9b30cb7 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 19 Apr 2018 21:53:01 -0700 Subject: [PATCH 4/6] Used return value from clearScreenIfNotWatchingForFiles --- src/compiler/watch.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 3140d975a3d..0dfe3968826 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -34,14 +34,20 @@ namespace ts { Diagnostics.Found_0_errors.code ]; - function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) { + /** + * @returns Whether the screen was cleared. + */ + function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions): boolean { if (system.clearScreen && !options.preserveWatchOutput && !options.extendedDiagnostics && !options.diagnostics && !contains(nonClearingMessageCodes, diagnostic.code)) { system.clearScreen(); + return true; } + + return false; } /** @internal */ @@ -50,12 +56,6 @@ namespace ts { Diagnostics.File_change_detected_Starting_incremental_compilation.code, ]; - function getPlainDiagnosticPrecedingNewLines(diagnostic: Diagnostic, newLine: string, preserveWatchOutput?: boolean): string { - return !preserveWatchOutput && contains(screenStartingMessageCodes, diagnostic.code) - ? "" - : newLine; - } - function getPlainDiagnosticFollowingNewLines(diagnostic: Diagnostic, newLine: string): string { return contains(screenStartingMessageCodes, diagnostic.code) ? newLine + newLine @@ -74,8 +74,10 @@ namespace ts { system.write(output); } : (diagnostic, newLine, options) => { - clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); - let output = `${getPlainDiagnosticPrecedingNewLines(diagnostic, newLine, options.preserveWatchOutput)}${new Date().toLocaleTimeString()} - `; + if (!clearScreenIfNotWatchingForFileChanges(system, diagnostic, options)) { + system.write(newLine); + } + let output = `${new Date().toLocaleTimeString()} - `; output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`; system.write(output); }; From 351251193ddca4f03ed5676c2dde862734cc5aee Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 19 Apr 2018 21:54:08 -0700 Subject: [PATCH 5/6] Simplified to one output line --- src/compiler/watch.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 0dfe3968826..1b79e71efb8 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -74,11 +74,15 @@ namespace ts { system.write(output); } : (diagnostic, newLine, options) => { + let output = ""; + if (!clearScreenIfNotWatchingForFileChanges(system, diagnostic, options)) { - system.write(newLine); + output += newLine; } - let output = `${new Date().toLocaleTimeString()} - `; + + output += `${new Date().toLocaleTimeString()} - `; output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`; + system.write(output); }; } From 7812e5180f2ba5facd2bb4e0232fb34e4d30dab0 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 19 Apr 2018 22:01:08 -0700 Subject: [PATCH 6/6] Trailing whitespace, oh no! --- src/compiler/watch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 1b79e71efb8..2f240300aba 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -35,7 +35,7 @@ namespace ts { ]; /** - * @returns Whether the screen was cleared. + * @returns Whether the screen was cleared. */ function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions): boolean { if (system.clearScreen &&