Skip to content

Commit 1227142

Browse files
committed
feat(watch): show file-level error summary in watch mode
This change updates the watch mode error reporting to include a detailed summary of errors per file, similar to non-watch mode. It uses 'getErrorSummaryText' to generate the summary and introduces a new diagnostic message '_0_Watching_for_file_changes' to display it alongside the watch status. Verification: - Verified manually with reproduction case (single error and zero errors). - Ran existing 'tscWatch' tests and updated baselines for 213 scenarios. - All 454 watch mode tests passed.
1 parent 87aa917 commit 1227142

File tree

229 files changed

+2695
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+2695
-654
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,6 @@
15391539
"category": "Error",
15401540
"code": 1464
15411541
},
1542-
15431542
"The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.": {
15441543
"category": "Error",
15451544
"code": 1470
@@ -1860,7 +1859,6 @@
18601859
"category": "Message",
18611860
"code": 1549
18621861
},
1863-
18641862
"The types of '{0}' are incompatible between these types.": {
18651863
"category": "Error",
18661864
"code": 2200
@@ -1901,7 +1899,6 @@
19011899
"category": "Error",
19021900
"code": 2208
19031901
},
1904-
19051902
"The project root is ambiguous, but is required to resolve export map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate.": {
19061903
"category": "Error",
19071904
"code": 2209
@@ -1918,7 +1915,6 @@
19181915
"category": "Message",
19191916
"code": 2212
19201917
},
1921-
19221918
"Duplicate identifier '{0}'.": {
19231919
"category": "Error",
19241920
"code": 2300
@@ -2899,7 +2895,6 @@
28992895
"category": "Error",
29002896
"code": 2568
29012897
},
2902-
29032898
"Could not find name '{0}'. Did you mean '{1}'?": {
29042899
"category": "Error",
29052900
"code": 2570
@@ -3140,7 +3135,6 @@
31403135
"category": "Error",
31413136
"code": 2639
31423137
},
3143-
31443138
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
31453139
"category": "Error",
31463140
"code": 2649
@@ -4022,7 +4016,6 @@
40224016
"category": "Error",
40234017
"code": 2882
40244018
},
4025-
40264019
"Import declaration '{0}' is using private name '{1}'.": {
40274020
"category": "Error",
40284021
"code": 4000
@@ -4467,7 +4460,6 @@
44674460
"category": "Error",
44684461
"code": 4128
44694462
},
4470-
44714463
"The current host does not support the '{0}' option.": {
44724464
"category": "Error",
44734465
"code": 5001
@@ -4744,7 +4736,6 @@
47444736
"category": "Error",
47454737
"code": 5112
47464738
},
4747-
47484739
"Generates a sourcemap for each corresponding '.d.ts' file.": {
47494740
"category": "Message",
47504741
"code": 6000
@@ -5401,6 +5392,10 @@
54015392
"category": "Message",
54025393
"code": 6194
54035394
},
5395+
"{0} Watching for file changes.": {
5396+
"category": "Message",
5397+
"code": 6499
5398+
},
54045399
"Resolve 'keyof' to string valued property names only (no numbers or symbols).": {
54055400
"category": "Message",
54065401
"code": 6195
@@ -5688,7 +5683,6 @@
56885683
"category": "Error",
56895684
"code": 6266
56905685
},
5691-
56925686
"Directory '{0}' has no containing package.json scope. Imports will not resolve.": {
56935687
"category": "Message",
56945688
"code": 6270
@@ -5781,7 +5775,6 @@
57815775
"category": "Message",
57825776
"code": 6294
57835777
},
5784-
57855778
"Enable project compilation": {
57865779
"category": "Message",
57875780
"code": 6302
@@ -6064,7 +6057,6 @@
60646057
"category": "Message",
60656058
"code": 6421
60666059
},
6067-
60686060
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
60696061
"category": "Message",
60706062
"code": 6500
@@ -6593,7 +6585,6 @@
65936585
"category": "Message",
65946586
"code": 6809
65956587
},
6596-
65976588
"one of:": {
65986589
"category": "Message",
65996590
"code": 6900
@@ -6610,7 +6601,6 @@
66106601
"category": "Message",
66116602
"code": 6903
66126603
},
6613-
66146604
"`true`, unless `strict` is `false`": {
66156605
"category": "Message",
66166606
"code": 6905
@@ -6723,7 +6713,6 @@
67236713
"category": "Message",
67246714
"code": 6932
67256715
},
6726-
67276716
"Variable '{0}' implicitly has an '{1}' type.": {
67286717
"category": "Error",
67296718
"code": 7005
@@ -6946,7 +6935,6 @@
69466935
"category": "Error",
69476936
"code": 7061
69486937
},
6949-
69506938
"You cannot rename this element.": {
69516939
"category": "Error",
69526940
"code": 8000
@@ -7091,7 +7079,6 @@
70917079
"category": "Error",
70927080
"code": 8039
70937081
},
7094-
70957082
"Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit.": {
70967083
"category": "Error",
70977084
"code": 9005
@@ -7324,7 +7311,6 @@
73247311
"category": "Error",
73257312
"code": 18003
73267313
},
7327-
73287314
"File is a CommonJS module; it may be converted to an ES module.": {
73297315
"category": "Suggestion",
73307316
"code": 80001
@@ -7365,7 +7351,6 @@
73657351
"category": "Suggestion",
73667352
"code": 80010
73677353
},
7368-
73697354
"Add missing 'super()' call": {
73707355
"category": "Message",
73717356
"code": 90001
@@ -7586,7 +7571,6 @@
75867571
"category": "Message",
75877572
"code": 90071
75887573
},
7589-
75907574
"Convert function to an ES2015 class": {
75917575
"category": "Message",
75927576
"code": 95001
@@ -8355,7 +8339,6 @@
83558339
"category": "Message",
83568340
"code": 95197
83578341
},
8358-
83598342
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
83608343
"category": "Error",
83618344
"code": 18004
@@ -8552,4 +8535,4 @@
85528535
"category": "Error",
85538536
"code": 18061
85548537
}
8555-
}
8538+
}

src/compiler/watch.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ export function getWatchErrorSummaryDiagnosticMessage(errorCount: number): Diagn
263263
Diagnostics.Found_0_errors_Watching_for_file_changes;
264264
}
265265

266+
export function getWatchErrorSummaryDiagnostic(errorCount: number, filesInError: (ReportFileInError | undefined)[], newLine: string, host: HasCurrentDirectory, options: CompilerOptions): Diagnostic {
267+
if (errorCount === 0) {
268+
return createCompilerDiagnostic(Diagnostics.Found_0_errors_Watching_for_file_changes, 0);
269+
}
270+
const errorSummary = getErrorSummaryText(errorCount, filesInError, newLine, host);
271+
return createCompilerDiagnostic(Diagnostics._0_Watching_for_file_changes, errorSummary);
272+
}
273+
266274
function prettyPathForFileError(error: ReportFileInError, cwd: string) {
267275
const line = formatColorAndReset(":" + error.line, ForegroundColorEscapeSequences.Grey);
268276
if (pathIsAbsolute(error.fileName) && pathIsAbsolute(cwd)) {
@@ -293,7 +301,7 @@ export function getErrorSummaryText(
293301
else {
294302
messageAndArgs = distinctFileNamesWithLines.length === 0 ? [Diagnostics.Found_0_errors, errorCount] :
295303
distinctFileNamesWithLines.length === 1 ? [Diagnostics.Found_0_errors_in_the_same_file_starting_at_Colon_1, errorCount, firstFileReference] :
296-
[Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length];
304+
[Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length];
297305
}
298306

299307
const d = createCompilerDiagnostic(...messageAndArgs);
@@ -524,8 +532,8 @@ export function fileIncludeReasonToDiagnostics(program: Program, reason: FileInc
524532
Diagnostics.Output_from_referenced_project_0_included_because_1_specified :
525533
Diagnostics.Source_from_referenced_project_0_included_because_1_specified :
526534
isOutput ?
527-
Diagnostics.Output_from_referenced_project_0_included_because_module_is_specified_as_none :
528-
Diagnostics.Source_from_referenced_project_0_included_because_module_is_specified_as_none,
535+
Diagnostics.Output_from_referenced_project_0_included_because_module_is_specified_as_none :
536+
Diagnostics.Source_from_referenced_project_0_included_because_module_is_specified_as_none,
529537
toFileName(referencedResolvedRef.sourceFile.fileName, fileNameConvertor),
530538
options.outFile ? "--outFile" : "--out",
531539
);
@@ -535,8 +543,8 @@ export function fileIncludeReasonToDiagnostics(program: Program, reason: FileInc
535543
[Diagnostics.Entry_point_of_type_library_0_specified_in_compilerOptions_with_packageId_1, reason.typeReference, packageIdToString(reason.packageId)] :
536544
[Diagnostics.Entry_point_of_type_library_0_specified_in_compilerOptions, reason.typeReference] :
537545
reason.packageId ?
538-
[Diagnostics.Entry_point_for_implicit_type_library_0_with_packageId_1, reason.typeReference, packageIdToString(reason.packageId)] :
539-
[Diagnostics.Entry_point_for_implicit_type_library_0, reason.typeReference];
546+
[Diagnostics.Entry_point_for_implicit_type_library_0_with_packageId_1, reason.typeReference, packageIdToString(reason.packageId)] :
547+
[Diagnostics.Entry_point_for_implicit_type_library_0, reason.typeReference];
540548

541549
return chainDiagnosticMessages(/*details*/ undefined, ...messageAndArgs);
542550
}
@@ -880,9 +888,9 @@ function createWatchCompilerHost<T extends BuilderProgram = EmitAndSemanticDiagn
880888
builderProgram,
881889
reportDiagnostic,
882890
write,
883-
errorCount =>
891+
(errorCount, filesInError) =>
884892
result.onWatchStatusChange!(
885-
createCompilerDiagnostic(getWatchErrorSummaryDiagnosticMessage(errorCount), errorCount),
893+
getWatchErrorSummaryDiagnostic(errorCount, filesInError, newLine, result, compilerOptions),
886894
newLine,
887895
compilerOptions,
888896
errorCount,

tests/baselines/reference/tscWatch/emit/emit-for-configured-projects/should-always-return-the-file-itself-if-'--out'-or-'--outFile'-is-specified.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ Output::
5353
4 "outFile": "/home/src/projects/a/b/out.js"
5454
   ~~~~~~~~~
5555

56-
[HH:MM:SS AM] Found 2 errors. Watching for file changes.
56+
[HH:MM:SS AM]
57+
Found 2 errors in the same file, starting at: tsconfig.json:3
58+
59+
Watching for file changes.
5760

5861

5962

@@ -186,7 +189,10 @@ Output::
186189
4 "outFile": "/home/src/projects/a/b/out.js"
187190
   ~~~~~~~~~
188191

189-
[HH:MM:SS AM] Found 2 errors. Watching for file changes.
192+
[HH:MM:SS AM]
193+
Found 2 errors in the same file, starting at: tsconfig.json:3
194+
195+
Watching for file changes.
190196

191197

192198

tests/baselines/reference/tscWatch/emit/emit-for-configured-projects/should-be-up-to-date-with-the-reference-map-changes.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ Output::
149149
1 export let y = Foo();
150150
   ~~~
151151

152-
[HH:MM:SS AM] Found 1 error. Watching for file changes.
152+
[HH:MM:SS AM]
153+
Found 1 error in file1Consumer1.ts:1
154+
155+
Watching for file changes.
153156

154157

155158

@@ -211,7 +214,10 @@ Output::
211214
1 export let y = Foo();
212215
   ~~~
213216

214-
[HH:MM:SS AM] Found 1 error. Watching for file changes.
217+
[HH:MM:SS AM]
218+
Found 1 error in file1Consumer1.ts:1
219+
220+
Watching for file changes.
215221

216222

217223

@@ -346,7 +352,14 @@ Output::
346352
1 export let y = Foo();
347353
   ~~~
348354

349-
[HH:MM:SS AM] Found 3 errors. Watching for file changes.
355+
[HH:MM:SS AM]
356+
Found 3 errors in 3 files.
357+
358+
Errors Files
359+
1 file1Consumer1.ts:1
360+
1 file1Consumer2.ts:1
361+
1 moduleFile1.ts:1
362+
Watching for file changes.
350363

351364

352365

tests/baselines/reference/tscWatch/emit/emit-for-configured-projects/should-detect-non-existing-code-file.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ Output::
3737
2 export var x = Foo();
3838
   ~~~
3939

40-
[HH:MM:SS AM] Found 2 errors. Watching for file changes.
40+
[HH:MM:SS AM]
41+
Found 2 errors in the same file, starting at: referenceFile1.ts:1
42+
43+
Watching for file changes.
4144

4245

4346

@@ -122,7 +125,10 @@ Output::
122125
2 export var x = Foo();export var yy = Foo();
123126
   ~~~
124127

125-
[HH:MM:SS AM] Found 3 errors. Watching for file changes.
128+
[HH:MM:SS AM]
129+
Found 3 errors in the same file, starting at: referenceFile1.ts:1
130+
131+
Watching for file changes.
126132

127133

128134

@@ -199,7 +205,10 @@ Output::
199205
2 export var x = Foo();export var yy = Foo();
200206
   ~~~
201207

202-
[HH:MM:SS AM] Found 2 errors. Watching for file changes.
208+
[HH:MM:SS AM]
209+
Found 2 errors in the same file, starting at: referenceFile1.ts:2
210+
211+
Watching for file changes.
203212

204213

205214

tests/baselines/reference/tscWatch/emit/emit-for-configured-projects/should-detect-removed-code-file.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ Output::
3535
2 export var x = Foo();
3636
   ~~~
3737

38-
[HH:MM:SS AM] Found 1 error. Watching for file changes.
38+
[HH:MM:SS AM]
39+
Found 1 error in referenceFile1.ts:2
40+
41+
Watching for file changes.
3942

4043

4144

@@ -119,7 +122,10 @@ Output::
119122
2 export var x = Foo();
120123
   ~~~
121124

122-
[HH:MM:SS AM] Found 2 errors. Watching for file changes.
125+
[HH:MM:SS AM]
126+
Found 2 errors in the same file, starting at: referenceFile1.ts:1
127+
128+
Watching for file changes.
123129

124130

125131

0 commit comments

Comments
 (0)