@@ -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,10 @@ 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 ) for ( const relErr of error . relatedInformation ) {
1355
+ outputError ( /*isRelatedError*/ true , relErr ) ;
1356
+ }
1360
1357
errorsReported ++ ;
1361
1358
1362
1359
// do not count errors from lib.d.ts here, they are computed separately as numLibraryDiagnostics
@@ -1369,6 +1366,23 @@ namespace Harness {
1369
1366
}
1370
1367
}
1371
1368
1369
+ function outputError ( isRelatedError : boolean , error : ts . Diagnostic ) {
1370
+ const message = ts . flattenDiagnosticMessageText ( error . messageText , IO . newLine ( ) ) ;
1371
+ let suffix = "!!! " ;
1372
+ if ( isRelatedError ) {
1373
+ const file = ts . Debug . assertDefined ( error . file ) ;
1374
+ const { line, character } = ts . getLineAndCharacterOfPosition ( file , error . start ! ) ;
1375
+ const fileName = utils . removeTestPathPrefixes ( file . fileName ) ;
1376
+ suffix += `(i) ${ fileName } (${ line + 1 } ,${ character + 1 } ): ` ;
1377
+ }
1378
+ const errLines = utils . removeTestPathPrefixes ( message )
1379
+ . split ( "\n" )
1380
+ . map ( s => s . length > 0 && s . charAt ( s . length - 1 ) === "\r" ? s . substr ( 0 , s . length - 1 ) : s )
1381
+ . filter ( s => s . length > 0 )
1382
+ . map ( s => suffix + ts . diagnosticCategoryName ( error ) + " TS" + error . code + ": " + s ) ;
1383
+ errLines . forEach ( e => outputLines += ( newLine ( ) + e ) ) ;
1384
+ }
1385
+
1372
1386
yield [ diagnosticSummaryMarker , utils . removeTestPathPrefixes ( minimalDiagnosticsToString ( diagnostics , options && options . pretty ) ) + IO . newLine ( ) + IO . newLine ( ) , diagnostics . length ] ;
1373
1387
1374
1388
// Report global errors
@@ -1419,8 +1433,7 @@ namespace Harness {
1419
1433
}
1420
1434
// Emit this line from the original file
1421
1435
outputLines += ( newLine ( ) + " " + line ) ;
1422
- fileErrors . forEach ( errDiagnostic => {
1423
- const err = errDiagnostic as ts . TextSpan ; // TODO: GH#18217
1436
+ fileErrors . forEach ( err => {
1424
1437
// Does any error start or continue on to this line? Emit squiggles
1425
1438
const end = ts . textSpanEnd ( err ) ;
1426
1439
if ( ( end >= thisLineStart ) && ( ( err . start < nextLineStart ) || ( lineIndex === lines . length - 1 ) ) ) {
@@ -1438,7 +1451,7 @@ namespace Harness {
1438
1451
// Just like above, we need to do a split on a string instead of on a regex
1439
1452
// because the JS engine does regexes wrong
1440
1453
1441
- outputErrorText ( errDiagnostic ) ;
1454
+ outputErrorText ( err ) ;
1442
1455
markedErrorCount ++ ;
1443
1456
}
1444
1457
}
0 commit comments