Skip to content

Commit 2826bc7

Browse files
authored
Merge pull request microsoft#23470 from JoshuaKGoldberg/standardized-non-pretty-newlines
Adjusted newlines in non-pretty output for consistency
2 parents 18c3f5f + 7812e51 commit 2826bc7

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/compiler/watch.ts

+29-5
Original file line numberDiff line numberDiff line change
@@ -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
}

src/harness/unittests/tscWatchMode.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ namespace ts.tscWatch {
124124
}
125125

126126
function getWatchDiagnosticWithoutDate(diagnostic: Diagnostic) {
127-
return ` - ${flattenDiagnosticMessageText(diagnostic.messageText, host.newLine)}${host.newLine + host.newLine + host.newLine}`;
127+
const newLines = contains(screenStartingMessageCodes, diagnostic.code)
128+
? `${host.newLine}${host.newLine}`
129+
: host.newLine;
130+
return ` - ${flattenDiagnosticMessageText(diagnostic.messageText, host.newLine)}${newLines}`;
128131
}
129132
}
130133

0 commit comments

Comments
 (0)