@@ -1113,6 +1113,8 @@ namespace Harness {
1113
1113
{ name : "fullEmitPaths" , type : "boolean" }
1114
1114
] ;
1115
1115
1116
+ const diagnosticHost = { getCanonicalFileName, getCurrentDirectory : ( ) => "" , getNewLine : ( ) => IO . newLine ( ) } ;
1117
+
1116
1118
let optionsIndex : ts . Map < ts . CommandLineOption > ;
1117
1119
function getCommandLineOption ( name : string ) : ts . CommandLineOption | undefined {
1118
1120
if ( ! optionsIndex ) {
@@ -1315,8 +1317,7 @@ namespace Harness {
1315
1317
}
1316
1318
1317
1319
export function minimalDiagnosticsToString ( diagnostics : ReadonlyArray < ts . Diagnostic > , pretty ?: boolean ) {
1318
- const host = { getCanonicalFileName, getCurrentDirectory : ( ) => "" , getNewLine : ( ) => IO . newLine ( ) } ;
1319
- return ( pretty ? ts . formatDiagnosticsWithColorAndContext : ts . formatDiagnostics ) ( diagnostics , host ) ;
1320
+ return ( pretty ? ts . formatDiagnosticsWithColorAndContext : ts . formatDiagnostics ) ( diagnostics , diagnosticHost ) ;
1320
1321
}
1321
1322
1322
1323
export function getErrorBaseline ( inputFiles : ReadonlyArray < TestFile > , diagnostics : ReadonlyArray < ts . Diagnostic > , pretty ?: boolean ) {
@@ -1349,14 +1350,12 @@ namespace Harness {
1349
1350
}
1350
1351
1351
1352
function outputErrorText ( error : ts . Diagnostic ) {
1352
- const message = ts . flattenDiagnosticMessageText ( error . messageText , IO . newLine ( ) ) ;
1353
-
1354
- const errLines = utils . removeTestPathPrefixes ( message )
1355
- . split ( "\n" )
1356
- . map ( s => s . length > 0 && s . charAt ( s . length - 1 ) === "\r" ? s . substr ( 0 , s . length - 1 ) : s )
1357
- . filter ( s => s . length > 0 )
1358
- . map ( s => "!!! " + ts . diagnosticCategoryName ( error ) + " TS" + error . code + ": " + s ) ;
1359
- errLines . forEach ( e => outputLines += ( newLine ( ) + e ) ) ;
1353
+ outputError ( /*isRelatedError*/ false , error ) ;
1354
+ if ( error . relatedInformation ) {
1355
+ for ( const relErr of error . relatedInformation ) {
1356
+ outputError ( /*isRelatedError*/ true , relErr ) ;
1357
+ }
1358
+ }
1360
1359
errorsReported ++ ;
1361
1360
1362
1361
// do not count errors from lib.d.ts here, they are computed separately as numLibraryDiagnostics
@@ -1369,6 +1368,23 @@ namespace Harness {
1369
1368
}
1370
1369
}
1371
1370
1371
+ function outputError ( isRelatedError : boolean , error : ts . Diagnostic ) {
1372
+ const message = ts . flattenDiagnosticMessageText ( error . messageText , IO . newLine ( ) ) ;
1373
+ let suffix = "!!! " ;
1374
+ if ( isRelatedError ) {
1375
+ const file = ts . Debug . assertDefined ( error . file ) ;
1376
+ const { line, character } = ts . getLineAndCharacterOfPosition ( file , error . start ! ) ;
1377
+ const fileName = utils . removeTestPathPrefixes ( file . fileName ) ;
1378
+ suffix += `(i) ${ fileName } (${ line + 1 } ,${ character + 1 } ): ` ;
1379
+ }
1380
+ const errLines = utils . removeTestPathPrefixes ( message )
1381
+ . split ( "\n" )
1382
+ . map ( s => s . length > 0 && s . charAt ( s . length - 1 ) === "\r" ? s . substr ( 0 , s . length - 1 ) : s )
1383
+ . filter ( s => s . length > 0 )
1384
+ . map ( s => suffix + ts . diagnosticCategoryName ( error ) + " TS" + error . code + ": " + s ) ;
1385
+ errLines . forEach ( e => outputLines += ( newLine ( ) + e ) ) ;
1386
+ }
1387
+
1372
1388
yield [ diagnosticSummaryMarker , utils . removeTestPathPrefixes ( minimalDiagnosticsToString ( diagnostics , options && options . pretty ) ) + IO . newLine ( ) + IO . newLine ( ) , diagnostics . length ] ;
1373
1389
1374
1390
// Report global errors
@@ -1419,8 +1435,7 @@ namespace Harness {
1419
1435
}
1420
1436
// Emit this line from the original file
1421
1437
outputLines += ( newLine ( ) + " " + line ) ;
1422
- fileErrors . forEach ( errDiagnostic => {
1423
- const err = errDiagnostic as ts . TextSpan ; // TODO: GH#18217
1438
+ fileErrors . forEach ( err => {
1424
1439
// Does any error start or continue on to this line? Emit squiggles
1425
1440
const end = ts . textSpanEnd ( err ) ;
1426
1441
if ( ( end >= thisLineStart ) && ( ( err . start < nextLineStart ) || ( lineIndex === lines . length - 1 ) ) ) {
@@ -1438,7 +1453,7 @@ namespace Harness {
1438
1453
// Just like above, we need to do a split on a string instead of on a regex
1439
1454
// because the JS engine does regexes wrong
1440
1455
1441
- outputErrorText ( errDiagnostic ) ;
1456
+ outputErrorText ( err ) ;
1442
1457
markedErrorCount ++ ;
1443
1458
}
1444
1459
}
0 commit comments