Added an errors summary for --pretty --watch results#22254
Conversation
Reports a "Found X error(s) across Y file(s)." message on each recompile if in both pretty and watch modes. This commit intentionally doesn't include tests as I have a few questions about implementation details. Will ask in PR first.
|
I'll take that signoff as approval :) and write tests & resolve conflicts soon. |
sheetalkamat
left a comment
There was a problem hiding this comment.
I dont think this is great implementation.. I would rather modify existing emitFilesAndReportErrors to take additional parameter to summaryReporter which could either be undefined | reporter and if provided you write the summary using that reporter.
| } | ||
|
|
||
| function summarizeDiagnosticsAcrossFiles(diagnostics: Diagnostic[], reporter: WatchStatusReporter, newLine: string, compilerOptions: CompilerOptions): void { | ||
| if (diagnostics.length === 1) { |
There was a problem hiding this comment.
This is incorrect too.. This could be just compiler diagnostics or something.. Need not be in 1 file.
There was a problem hiding this comment.
I'm tempted to say simplify and don't even bother with pluralization based on count. Other languages don't necessarily pluralize the same way.
There was a problem hiding this comment.
could just be compiler diagnostics
How should it count the numbers of errors from diagnostics? diagnostic.category === DiagnosticCategory.Error, ignoring warnings & below?
simplify and don't even bother with pluralization
If a language doesn't pluralize for counts, then they would just have three localized messages with the same text. Is that bad? Seems fine to allow redundancy for nicer phrasing in most languages?
There was a problem hiding this comment.
I think the multiple diagnostic messages are the correct approach here. the other one is to use error(s) instead, but i would rather we add the extra line and make it look pretty.
As for knowing which is which, you can filter the diagnostics on d.category === DiagnosticCategory.Error.
One thing we can simplify is removing the number of files altogether. since diagnostics can be global and not attached to any file. this will reduce the number of message also by one, and will simplify this function.
|
I wounder if we should show this all the time as well.. like not just |
…hCompilerHost Instead of modifying the logic in both `tsc.ts`to `watch.ts` by splitting `emitFilesAndReportErrors` in two, this adds an optional function parameter to report them. Removes file counting for diagnostic messages, as they might not be coming from files. Next commit will include tests.
# Conflicts: # src/compiler/diagnosticMessages.json # src/compiler/watch.ts
|
Moved all the logic to @sheetalkamat I don't see any existing tests that include the "Compilation complete." string. Am I missing them, or do you want me to add them in this PR? |
| emit(): EmitResult; | ||
| } | ||
|
|
||
| /** @internal */ |
There was a problem hiding this comment.
No need to have this internal since the namespace itself is internal
| } | ||
| } | ||
|
|
||
| if (reportSummary) { |
There was a problem hiding this comment.
i agree with @mhegazy 's #22254 (comment) that we should just report this all the time
There was a problem hiding this comment.
I'm hesitant to change the behavior for non-pretty non-watch users. What if those users have builds that rely on tsc not having any non-whitespace output? This would break their workflow.
If these changes are acceptable for watch mode, can we discuss enabling for them in a separate issue?
There was a problem hiding this comment.
But that can be done through checking if (program.getCompilerOptions().pretty)
|
Ah, now the tests are failing. Will update... |
| const compilerOptions = builderProgram.getCompilerOptions(); | ||
| const reportSummary = (errorCount: number) => { | ||
| if (errorCount === 1) { | ||
| onWatchStatusChange(createCompilerDiagnostic(Diagnostics.Found_1_error, errorCount), sys.newLine, compilerOptions); |
There was a problem hiding this comment.
The new line character here used is incorrect, You dont want to use newline from sys but it should depend on compiler options and host.getNewLine()
|
@JoshuaKGoldberg #22570 should be fixed now, can we update this PR. |
771a73d to
d268279
Compare
| errors, | ||
| disableConsoleClears, | ||
| errors.length === 1 | ||
| ? createCompilerDiagnostic(Diagnostics.Found_1_error) |
There was a problem hiding this comment.
Instead of doing this here, can you add the move this to https://github.com/Microsoft/TypeScript/pull/22254/files#diff-09ed66c9ac499e7fd991780ed486d800R96 and check if (postErrorsWatchDiagnostics.length) and do this there so that its in one place.
There was a problem hiding this comment.
I don't think I can. If there's an exit that shouldn't display the "found X error(s)" message, namely checkOutputErrorsIncrementalWithExit, then the test should know not to expect the message:
1) tsc-watch program updates
config file is deleted:
AssertionError: ["13:14:33 - File change detected. Starting incremental compilation...\n\n\n","error TS6053: File '/a/b/tsconfig.json' not found.\n"]: expected 2 to equal 3
+ expected - actual
...but +1 to DRY. Moved the creation into a small helper function; is that enough?
| * Helper that emit files, report diagnostics and lists emitted and/or source files depending on compiler options | ||
| */ | ||
| export function emitFilesAndReportErrors(program: ProgramToEmitFilesAndReportErrors, reportDiagnostic: DiagnosticReporter, writeFileName?: (s: string) => void) { | ||
| export function emitFilesAndReportErrors(program: ProgramToEmitFilesAndReportErrors, reportDiagnostic: DiagnosticReporter, reportSummary?: ReportEmitErrorSummary, writeFileName?: (s: string) => void) { |
There was a problem hiding this comment.
I think you want to change the definition to
export function emitFilesAndReportErrors(program: ProgramToEmitFilesAndReportErrors, reportDiagnostic: DiagnosticReporter, writeFileName: (s: string) => void, reportSummary?: ReportEmitErrorSummary) currently tsc.ts's use of emitFilesAndReportErrors is broken ()
|
thanks @JoshuaKGoldberg ! |
Reports a "Found X error(s) across Y file(s)." message on each recompile if in both pretty and watch modes.
I ended up cutting & pasting
emitFilesAndReportErrorsup into three functions:getProgramDiagnosticsAndEmit: Retrieves diagnostics output and emit results from the program.reportDiagnosticErrors: Outputs the traditional error reporting that already existed.summarizeDiagnosticsAcrossFiles: Outputs the new summary message.This commit intentionally doesn't include tests yet as I have a few questions about implementation details:
Compilation complete." one. I would prefer to have one message with a descriptor of the errors or lack thereof, followed by "Waiting for file changes.". Would that break anything? Nothing comes to mind.emitFilesAndReportErrorsexist inwatch.tsbut get used intsc.ts? If it's part of logic not exclusive to logic, should it be moved totsc.ts?clearScreenIfNotWatchingForFileChangesis hardcoded to not clear the screen for one specific diagnostic method. I changed it to also allow the new messages. Is there a less hardcoded way I should use instead?Commit 1 output in cmder:

Fixes #22124.