Skip to content

Commit 24d3035

Browse files
Josh Goldbergmhegazy
Josh Goldberg
authored andcommitted
Added --preserveWatchOutput flag (microsoft#21303)
Description: "Whether to keep outdated console output in watch mode instead of clearing the screen." Since the `pretty?` compiler options flag is marked as `@internal`, made this one too.
1 parent cd4c518 commit 24d3035

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/compiler/commandLineParser.ts

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ namespace ts {
6262
category: Diagnostics.Command_line_Options,
6363
description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental
6464
},
65+
{
66+
name: "preserveWatchOutput",
67+
type: "boolean",
68+
showInSimplifiedHelpView: false,
69+
category: Diagnostics.Command_line_Options,
70+
description: Diagnostics.Whether_to_keep_outdated_console_output_in_watch_mode_instead_of_clearing_the_screen,
71+
},
6572
{
6673
name: "watch",
6774
shortName: "w",

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -3472,6 +3472,10 @@
34723472
"category": "Message",
34733473
"code": 6190
34743474
},
3475+
"Whether to keep outdated console output in watch mode instead of clearing the screen.": {
3476+
"category": "Message",
3477+
"code": 6191
3478+
},
34753479
"Variable '{0}' implicitly has an '{1}' type.": {
34763480
"category": "Error",
34773481
"code": 7005

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4100,6 +4100,7 @@ namespace ts {
41004100
/*@internal*/ plugins?: PluginImport[];
41014101
preserveConstEnums?: boolean;
41024102
preserveSymlinks?: boolean;
4103+
/* @internal */ preserveWatchOutput?: boolean;
41034104
project?: string;
41044105
/* @internal */ pretty?: DiagnosticStyle;
41054106
reactNamespace?: string;

src/compiler/watch.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace ts {
3333

3434
function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) {
3535
if (system.clearScreen &&
36+
!options.preserveWatchOutput &&
3637
diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code &&
3738
!options.extendedDiagnostics &&
3839
!options.diagnostics) {

src/harness/unittests/tscWatchMode.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,7 @@ declare module "fs" {
21622162
});
21632163

21642164
describe("tsc-watch console clearing", () => {
2165-
function checkConsoleClearing(diagnostics: boolean, extendedDiagnostics: boolean) {
2165+
function checkConsoleClearing(options: CompilerOptions = {}) {
21662166
const file = {
21672167
path: "f.ts",
21682168
content: ""
@@ -2172,7 +2172,7 @@ declare module "fs" {
21722172
let clearCount: number | undefined;
21732173
checkConsoleClears();
21742174

2175-
createWatchOfFilesAndCompilerOptions([file.path], host, { diagnostics, extendedDiagnostics });
2175+
createWatchOfFilesAndCompilerOptions([file.path], host, options);
21762176
checkConsoleClears();
21772177

21782178
file.content = "//";
@@ -2182,10 +2182,10 @@ declare module "fs" {
21822182
checkConsoleClears();
21832183

21842184
function checkConsoleClears() {
2185-
if (clearCount === undefined) {
2185+
if (clearCount === undefined || options.preserveWatchOutput) {
21862186
clearCount = 0;
21872187
}
2188-
else if (!diagnostics && !extendedDiagnostics) {
2188+
else if (!options.diagnostics && !options.extendedDiagnostics) {
21892189
clearCount++;
21902190
}
21912191
host.checkScreenClears(clearCount);
@@ -2194,13 +2194,22 @@ declare module "fs" {
21942194
}
21952195

21962196
it("without --diagnostics or --extendedDiagnostics", () => {
2197-
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ false);
2197+
checkConsoleClearing();
21982198
});
21992199
it("with --diagnostics", () => {
2200-
checkConsoleClearing(/*diagnostics*/ true, /*extendedDiagnostics*/ false);
2200+
checkConsoleClearing({
2201+
diagnostics: true,
2202+
});
22012203
});
22022204
it("with --extendedDiagnostics", () => {
2203-
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ true);
2205+
checkConsoleClearing({
2206+
extendedDiagnostics: true,
2207+
});
2208+
});
2209+
it("with --preserveWatchOutput", () => {
2210+
checkConsoleClearing({
2211+
preserveWatchOutput: true,
2212+
});
22042213
});
22052214
});
22062215
}

0 commit comments

Comments
 (0)