Skip to content

Added an errors summary for --pretty --watch results#22254

Merged
mhegazy merged 8 commits into
microsoft:masterfrom
JoshuaKGoldberg:pretty-watch-error-summaries
Apr 4, 2018
Merged

Added an errors summary for --pretty --watch results#22254
mhegazy merged 8 commits into
microsoft:masterfrom
JoshuaKGoldberg:pretty-watch-error-summaries

Conversation

@JoshuaKGoldberg
Copy link
Copy Markdown
Contributor

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 emitFilesAndReportErrors up 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:

  • In the first commit, there's an added message before the constant "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.
  • Why does emitFilesAndReportErrors exist in watch.ts but get used in tsc.ts? If it's part of logic not exclusive to logic, should it be moved to tsc.ts?
  • clearScreenIfNotWatchingForFileChanges is 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:
image

Fixes #22124.

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.
@JoshuaKGoldberg
Copy link
Copy Markdown
Contributor Author

I'll take that signoff as approval :) and write tests & resolve conflicts soon.

Copy link
Copy Markdown
Member

@sheetalkamat sheetalkamat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/compiler/watch.ts Outdated
}

function summarizeDiagnosticsAcrossFiles(diagnostics: Diagnostic[], reporter: WatchStatusReporter, newLine: string, compilerOptions: CompilerOptions): void {
if (diagnostics.length === 1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect too.. This could be just compiler diagnostics or something.. Need not be in 1 file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Mar 2, 2018

I wounder if we should show this all the time as well.. like not just --watch.. nu just regular compilations.

Josh Goldberg added 3 commits March 8, 2018 20:47
…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
@JoshuaKGoldberg
Copy link
Copy Markdown
Contributor Author

Moved all the logic to watch.ts, so tsc.ts remains untouched.

@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?

Comment thread src/compiler/watch.ts Outdated
emit(): EmitResult;
}

/** @internal */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have this internal since the namespace itself is internal

Comment thread src/compiler/watch.ts
}
}

if (reportSummary) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree with @mhegazy 's #22254 (comment) that we should just report this all the time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that can be done through checking if (program.getCompilerOptions().pretty)

@JoshuaKGoldberg
Copy link
Copy Markdown
Contributor Author

Ah, now the tests are failing. Will update...

Comment thread src/compiler/watch.ts Outdated
const compilerOptions = builderProgram.getCompilerOptions();
const reportSummary = (errorCount: number) => {
if (errorCount === 1) {
onWatchStatusChange(createCompilerDiagnostic(Diagnostics.Found_1_error, errorCount), sys.newLine, compilerOptions);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Mar 29, 2018

@JoshuaKGoldberg #22570 should be fixed now, can we update this PR.

@JoshuaKGoldberg JoshuaKGoldberg force-pushed the pretty-watch-error-summaries branch from 771a73d to d268279 Compare April 2, 2018 04:45
Comment thread src/harness/unittests/tscWatchMode.ts Outdated
errors,
disableConsoleClears,
errors.length === 1
? createCompilerDiagnostic(Diagnostics.Found_1_error)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread src/compiler/watch.ts Outdated
* 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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ()

@mhegazy mhegazy merged commit e2bd282 into microsoft:master Apr 4, 2018
@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Apr 4, 2018

thanks @JoshuaKGoldberg !

@JoshuaKGoldberg JoshuaKGoldberg deleted the pretty-watch-error-summaries branch April 4, 2018 23:11
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants