mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
Merge pull request #21537 from Microsoft/donotClearScreenWithDiagnostics
Do not clear console in watch mode if --diagnostics or --extendedDiagnostics is specified
This commit is contained in:
commit
1fb3593e61
@ -31,8 +31,11 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic) {
|
||||
if (system.clearScreen && diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code) {
|
||||
function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) {
|
||||
if (system.clearScreen &&
|
||||
diagnostic.code !== Diagnostics.Compilation_complete_Watching_for_file_changes.code &&
|
||||
!options.extendedDiagnostics &&
|
||||
!options.diagnostics) {
|
||||
system.clearScreen();
|
||||
}
|
||||
}
|
||||
@ -42,18 +45,18 @@ namespace ts {
|
||||
*/
|
||||
export function createWatchStatusReporter(system: System, pretty?: boolean): WatchStatusReporter {
|
||||
return pretty ?
|
||||
(diagnostic: Diagnostic, newLine: string) => {
|
||||
clearScreenIfNotWatchingForFileChanges(system, diagnostic);
|
||||
let output = `[${ formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey) }] `;
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
|
||||
system.write(output);
|
||||
} :
|
||||
(diagnostic: Diagnostic, newLine: string) => {
|
||||
clearScreenIfNotWatchingForFileChanges(system, diagnostic);
|
||||
let output = new Date().toLocaleTimeString() + " - ";
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
|
||||
system.write(output);
|
||||
};
|
||||
(diagnostic, newLine, options) => {
|
||||
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
|
||||
let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `;
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${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}`;
|
||||
system.write(output);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,7 +257,7 @@ namespace ts {
|
||||
|
||||
namespace ts {
|
||||
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
|
||||
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string) => void;
|
||||
export type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
|
||||
export type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: T) => T;
|
||||
export interface WatchCompilerHost<T extends BuilderProgram> {
|
||||
/**
|
||||
@ -264,7 +267,7 @@ namespace ts {
|
||||
/** If provided, callback to invoke after every new program creation */
|
||||
afterProgramCreate?(program: T): void;
|
||||
/** If provided, called with Diagnostic message that informs about change in watch status */
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string): void;
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
|
||||
|
||||
// Only for testing
|
||||
/*@internal*/
|
||||
@ -725,7 +728,7 @@ namespace ts {
|
||||
|
||||
function reportWatchDiagnostic(message: DiagnosticMessage) {
|
||||
if (host.onWatchStatusChange) {
|
||||
host.onWatchStatusChange(createCompilerDiagnostic(message), newLine);
|
||||
host.onWatchStatusChange(createCompilerDiagnostic(message), newLine, compilerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2102,35 +2102,45 @@ declare module "fs" {
|
||||
});
|
||||
|
||||
describe("tsc-watch console clearing", () => {
|
||||
it("clears the console when it starts", () => {
|
||||
function checkConsoleClearing(diagnostics: boolean, extendedDiagnostics: boolean) {
|
||||
const file = {
|
||||
path: "f.ts",
|
||||
content: ""
|
||||
};
|
||||
const host = createWatchedSystem([file]);
|
||||
const files = [file];
|
||||
const host = createWatchedSystem(files);
|
||||
let clearCount: number | undefined;
|
||||
checkConsoleClears();
|
||||
|
||||
createWatchOfFilesAndCompilerOptions([file.path], host);
|
||||
createWatchOfFilesAndCompilerOptions([file.path], host, { diagnostics, extendedDiagnostics });
|
||||
checkConsoleClears();
|
||||
|
||||
file.content = "//";
|
||||
host.reloadFS(files);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
host.checkScreenClears(1);
|
||||
checkConsoleClears();
|
||||
|
||||
function checkConsoleClears() {
|
||||
if (clearCount === undefined) {
|
||||
clearCount = 0;
|
||||
}
|
||||
else if (!diagnostics && !extendedDiagnostics) {
|
||||
clearCount++;
|
||||
}
|
||||
host.checkScreenClears(clearCount);
|
||||
return clearCount;
|
||||
}
|
||||
}
|
||||
|
||||
it("without --diagnostics or --extendedDiagnostics", () => {
|
||||
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ false);
|
||||
});
|
||||
|
||||
it("clears the console on recompile", () => {
|
||||
const file = {
|
||||
path: "f.ts",
|
||||
content: ""
|
||||
};
|
||||
const host = createWatchedSystem([file]);
|
||||
createWatchOfFilesAndCompilerOptions([file.path], host);
|
||||
|
||||
const modifiedFile = {
|
||||
...file,
|
||||
content: "//"
|
||||
};
|
||||
host.reloadFS([modifiedFile]);
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
host.checkScreenClears(2);
|
||||
it("with --diagnostics", () => {
|
||||
checkConsoleClearing(/*diagnostics*/ true, /*extendedDiagnostics*/ false);
|
||||
});
|
||||
it("with --extendedDiagnostics", () => {
|
||||
checkConsoleClearing(/*diagnostics*/ false, /*extendedDiagnostics*/ true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -3978,7 +3978,7 @@ declare namespace ts {
|
||||
}
|
||||
declare namespace ts {
|
||||
type DiagnosticReporter = (diagnostic: Diagnostic) => void;
|
||||
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string) => void;
|
||||
type WatchStatusReporter = (diagnostic: Diagnostic, newLine: string, options: CompilerOptions) => void;
|
||||
type CreateProgram<T extends BuilderProgram> = (rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: T) => T;
|
||||
interface WatchCompilerHost<T extends BuilderProgram> {
|
||||
/**
|
||||
@ -3988,7 +3988,7 @@ declare namespace ts {
|
||||
/** If provided, callback to invoke after every new program creation */
|
||||
afterProgramCreate?(program: T): void;
|
||||
/** If provided, called with Diagnostic message that informs about change in watch status */
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string): void;
|
||||
onWatchStatusChange?(diagnostic: Diagnostic, newLine: string, options: CompilerOptions): void;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
getNewLine(): string;
|
||||
getCurrentDirectory(): string;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user