@@ -1084,6 +1084,43 @@ namespace FourSlash {
10841084 }
10851085 }
10861086
1087+ public verifyBaselineFindAllReferences ( markerName : string ) {
1088+ const marker = this . getMarkerByName ( markerName ) ;
1089+ const references = this . languageService . findReferences ( marker . fileName , marker . position ) ;
1090+ const refsByFile = references
1091+ ? ts . group ( ts . sort ( ts . flatMap ( references , r => r . references ) , ( a , b ) => a . textSpan . start - b . textSpan . start ) , ref => ref . fileName )
1092+ : ts . emptyArray ;
1093+
1094+ // Write input files
1095+ let baselineContent = "" ;
1096+ for ( const group of refsByFile ) {
1097+ baselineContent += getBaselineContentForFile ( group [ 0 ] . fileName , this . getFileContent ( group [ 0 ] . fileName ) ) ;
1098+ baselineContent += "\n\n" ;
1099+ }
1100+
1101+ // Write response JSON
1102+ baselineContent += JSON . stringify ( references , undefined , 2 ) ;
1103+ Harness . Baseline . runBaseline ( this . getBaselineFileNameForContainingTestFile ( ".baseline.jsonc" ) , baselineContent ) ;
1104+
1105+ function getBaselineContentForFile ( fileName : string , content : string ) {
1106+ let newContent = `=== ${ fileName } ===\n` ;
1107+ let pos = 0 ;
1108+ for ( const { textSpan } of refsByFile . find ( refs => refs [ 0 ] . fileName === fileName ) ?? ts . emptyArray ) {
1109+ if ( fileName === marker . fileName && ts . textSpanContainsPosition ( textSpan , marker . position ) ) {
1110+ newContent += "/*FIND ALL REFS*/" ;
1111+ }
1112+ const end = textSpan . start + textSpan . length ;
1113+ newContent += content . slice ( pos , textSpan . start ) ;
1114+ newContent += "[|" ;
1115+ newContent += content . slice ( textSpan . start , end ) ;
1116+ newContent += "|]" ;
1117+ pos = end ;
1118+ }
1119+ newContent += content . slice ( pos ) ;
1120+ return newContent . split ( / \r ? \n / ) . map ( l => "// " + l ) . join ( "\n" ) ;
1121+ }
1122+ }
1123+
10871124 public verifyNoReferences ( markerNameOrRange ?: string | Range ) {
10881125 if ( markerNameOrRange !== undefined ) this . goToMarkerOrRange ( markerNameOrRange ) ;
10891126 const refs = this . getReferencesAtCaret ( ) ;
0 commit comments