Skip to content

Added --clearWatchOutput flag #22248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ namespace ts {
category: Diagnostics.Command_line_Options,
description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental
},
{
name: "clearWatchOutput",
type: "boolean",
showInSimplifiedHelpView: false,
category: Diagnostics.Command_line_Options,
description: Diagnostics.Whether_to_clear_the_console_in_watch_mode_on_new_results,
},
{
name: "watch",
shortName: "w",
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3472,6 +3472,10 @@
"category": "Message",
"code": 6190
},
"Whether to clear the console in watch mode on new results": {
"category": "Message",
"code": 6191
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4048,6 +4048,7 @@ namespace ts {
baseUrl?: string;
charset?: string;
checkJs?: boolean;
/* @internal */ clearWatchOutput?: boolean;
/* @internal */ configFilePath?: string;
/** configFile is set as non enumerable property so as to avoid checking of json source files */
/* @internal */ readonly configFile?: JsonSourceFile;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace ts {

function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) {
if (system.clearScreen &&
options.clearWatchOutput &&
diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code &&
!options.extendedDiagnostics &&
!options.diagnostics) {
Expand Down
26 changes: 19 additions & 7 deletions src/harness/unittests/tscWatchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,9 @@ declare module "fs" {
});
});


describe("tsc-watch console clearing", () => {
function checkConsoleClearing(diagnostics: boolean, extendedDiagnostics: boolean) {
function checkConsoleClearing(options: CompilerOptions = {}) {
const file = {
path: "f.ts",
content: ""
Expand All @@ -2172,7 +2173,7 @@ declare module "fs" {
let clearCount: number | undefined;
checkConsoleClears();

createWatchOfFilesAndCompilerOptions([file.path], host, { diagnostics, extendedDiagnostics });
createWatchOfFilesAndCompilerOptions([file.path], host, options);
checkConsoleClears();

file.content = "//";
Expand All @@ -2182,10 +2183,10 @@ declare module "fs" {
checkConsoleClears();

function checkConsoleClears() {
if (clearCount === undefined) {
if (clearCount === undefined || !options.clearWatchOutput) {
clearCount = 0;
}
else if (!diagnostics && !extendedDiagnostics) {
else if (!options.diagnostics && !options.extendedDiagnostics) {
clearCount++;
}
host.checkScreenClears(clearCount);
Expand All @@ -2194,13 +2195,24 @@ declare module "fs" {
}

it("without --diagnostics or --extendedDiagnostics", () => {
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ false);
checkConsoleClearing({
clearWatchOutput: true,
});
});
it("with --diagnostics", () => {
checkConsoleClearing(/*diagnostics*/ true, /*extendedDiagnostics*/ false);
checkConsoleClearing({
clearWatchOutput: true,
diagnostics: true,
});
});
it("with --extendedDiagnostics", () => {
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ true);
checkConsoleClearing({
clearWatchOutput: true,
extendedDiagnostics: true,
});
});
it("without --clearWatchOutput", () => {
checkConsoleClearing();
});
});
}