@@ -1122,83 +1122,18 @@ namespace FourSlash {
11221122 }
11231123 }
11241124
1125- private verifyDocumentHighlightsRespectFilesList ( files : readonly string [ ] ) : void {
1126- const startFile = this . activeFile . fileName ;
1127- for ( const fileName of files ) {
1128- const searchFileNames = startFile === fileName ? [ startFile ] : [ startFile , fileName ] ;
1129- const highlights = this . getDocumentHighlightsAtCurrentPosition ( searchFileNames ) ;
1130- if ( highlights && ! highlights . every ( dh => ts . contains ( searchFileNames , dh . fileName ) ) ) {
1131- this . raiseError ( `When asking for document highlights only in files ${ searchFileNames } , got document highlights in ${ unique ( highlights , dh => dh . fileName ) } ` ) ;
1132- }
1133- }
1125+ public verifyBaselineFindAllReferences ( ...markerNames : string [ ] ) {
1126+ ts . Debug . assert ( markerNames . length > 0 , "Must pass at least one marker name to `verifyBaselineFindAllReferences()`" ) ;
1127+ this . verifyBaselineFindAllReferencesWorker ( "" , markerNames ) ;
11341128 }
11351129
1136- public verifyReferenceGroups ( starts : ArrayOrSingle < string > | ArrayOrSingle < Range > , parts : readonly FourSlashInterface . ReferenceGroup [ ] ) : void {
1137- interface ReferenceGroupJson {
1138- definition : string | { text : string , range : ts . TextSpan } ;
1139- references : ts . ReferenceEntry [ ] ;
1140- }
1141- interface RangeMarkerData {
1142- id ?: string ;
1143- isWriteAccess ?: boolean ,
1144- isDefinition ?: boolean ,
1145- isInString ?: true ,
1146- contextRangeIndex ?: number ,
1147- contextRangeDelta ?: number ,
1148- contextRangeId ?: string
1149- }
1150- const fullExpected = ts . map < FourSlashInterface . ReferenceGroup , ReferenceGroupJson > ( parts , ( { definition, ranges } ) => ( {
1151- definition : typeof definition === "string" ? definition : { ...definition , range : ts . createTextSpanFromRange ( definition . range ) } ,
1152- references : ranges . map < ts . ReferenceEntry > ( r => {
1153- const { isWriteAccess = false , isDefinition = false , isInString, contextRangeIndex, contextRangeDelta, contextRangeId } = ( r . marker && r . marker . data || { } ) as RangeMarkerData ;
1154- let contextSpan : ts . TextSpan | undefined ;
1155- if ( contextRangeDelta !== undefined ) {
1156- const allRanges = this . getRanges ( ) ;
1157- const index = allRanges . indexOf ( r ) ;
1158- if ( index !== - 1 ) {
1159- contextSpan = ts . createTextSpanFromRange ( allRanges [ index + contextRangeDelta ] ) ;
1160- }
1161- }
1162- else if ( contextRangeId !== undefined ) {
1163- const allRanges = this . getRanges ( ) ;
1164- const contextRange = ts . find ( allRanges , range => ( range . marker ?. data as RangeMarkerData ) ?. id === contextRangeId ) ;
1165- if ( contextRange ) {
1166- contextSpan = ts . createTextSpanFromRange ( contextRange ) ;
1167- }
1168- }
1169- else if ( contextRangeIndex !== undefined ) {
1170- contextSpan = ts . createTextSpanFromRange ( this . getRanges ( ) [ contextRangeIndex ] ) ;
1171- }
1172- return {
1173- textSpan : ts . createTextSpanFromRange ( r ) ,
1174- fileName : r . fileName ,
1175- ...( contextSpan ? { contextSpan } : undefined ) ,
1176- isWriteAccess,
1177- isDefinition,
1178- ...( isInString ? { isInString : true } : undefined ) ,
1179- } ;
1180- } ) ,
1181- } ) ) ;
1182-
1183- for ( const start of toArray < string | Range > ( starts ) ) {
1184- this . goToMarkerOrRange ( start ) ;
1185- const fullActual = ts . map < ts . ReferencedSymbol , ReferenceGroupJson > ( this . findReferencesAtCaret ( ) , ( { definition, references } , i ) => {
1186- const text = definition . displayParts . map ( d => d . text ) . join ( "" ) ;
1187- return {
1188- definition : fullExpected . length > i && typeof fullExpected [ i ] . definition === "string" ? text : { text, range : definition . textSpan } ,
1189- references,
1190- } ;
1191- } ) ;
1192- this . assertObjectsEqual ( fullActual , fullExpected ) ;
1193-
1194- if ( parts ) {
1195- this . verifyDocumentHighlightsRespectFilesList ( unique ( ts . flatMap ( parts , p => p . ranges ) , r => r . fileName ) ) ;
1196- }
1197- }
1130+ // Used when a single test needs to produce multiple baselines
1131+ public verifyBaselineFindAllReferencesMulti ( seq : number , ...markerNames : string [ ] ) {
1132+ ts . Debug . assert ( markerNames . length > 0 , "Must pass at least one marker name to `baselineFindAllReferences()`" ) ;
1133+ this . verifyBaselineFindAllReferencesWorker ( `.${ seq } ` , markerNames ) ;
11981134 }
11991135
1200- public verifyBaselineFindAllReferences ( ...markerNames : string [ ] ) {
1201- ts . Debug . assert ( markerNames . length > 0 , "Must pass at least one marker name to `baselineFindAllReferences()`" ) ;
1136+ private verifyBaselineFindAllReferencesWorker ( suffix : string , markerNames : string [ ] ) {
12021137 const baseline = markerNames . map ( markerName => {
12031138 this . goToMarker ( markerName ) ;
12041139 const marker = this . getMarkerByName ( markerName ) ;
@@ -1213,7 +1148,7 @@ namespace FourSlash {
12131148 // Write response JSON
12141149 return baselineContent + JSON . stringify ( references , undefined , 2 ) ;
12151150 } ) . join ( "\n\n" ) ;
1216- Harness . Baseline . runBaseline ( this . getBaselineFileNameForContainingTestFile ( " .baseline.jsonc" ) , baseline ) ;
1151+ Harness . Baseline . runBaseline ( this . getBaselineFileNameForContainingTestFile ( ` ${ suffix } .baseline.jsonc` ) , baseline ) ;
12171152 }
12181153
12191154 public verifyBaselineGetFileReferences ( fileName : string ) {
@@ -1280,11 +1215,6 @@ namespace FourSlash {
12801215 }
12811216 }
12821217
1283- public verifySingleReferenceGroup ( definition : FourSlashInterface . ReferenceGroupDefinition , ranges ?: Range [ ] | string ) {
1284- ranges = ts . isString ( ranges ) ? this . rangesByText ( ) . get ( ranges ) ! : ranges || this . getRanges ( ) ;
1285- this . verifyReferenceGroups ( ranges , [ { definition, ranges } ] ) ;
1286- }
1287-
12881218 private assertObjectsEqual < T > ( fullActual : T , fullExpected : T , msgPrefix = "" ) : void {
12891219 const recur = < U > ( actual : U , expected : U , path : string ) => {
12901220 const fail = ( msg : string ) => {
@@ -2403,15 +2333,6 @@ namespace FourSlash {
24032333 this . goToPosition ( len ) ;
24042334 }
24052335
2406- private goToMarkerOrRange ( markerOrRange : string | Range ) {
2407- if ( typeof markerOrRange === "string" ) {
2408- this . goToMarker ( markerOrRange ) ;
2409- }
2410- else {
2411- this . goToRangeStart ( markerOrRange ) ;
2412- }
2413- }
2414-
24152336 public goToRangeStart ( { fileName, pos } : Range ) {
24162337 this . openFile ( fileName ) ;
24172338 this . goToPosition ( pos ) ;
0 commit comments