@@ -1122,83 +1122,18 @@ namespace FourSlash {
1122
1122
}
1123
1123
}
1124
1124
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 ) ;
1134
1128
}
1135
1129
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 ) ;
1198
1134
}
1199
1135
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 [ ] ) {
1202
1137
const baseline = markerNames . map ( markerName => {
1203
1138
this . goToMarker ( markerName ) ;
1204
1139
const marker = this . getMarkerByName ( markerName ) ;
@@ -1213,7 +1148,7 @@ namespace FourSlash {
1213
1148
// Write response JSON
1214
1149
return baselineContent + JSON . stringify ( references , undefined , 2 ) ;
1215
1150
} ) . join ( "\n\n" ) ;
1216
- Harness . Baseline . runBaseline ( this . getBaselineFileNameForContainingTestFile ( " .baseline.jsonc" ) , baseline ) ;
1151
+ Harness . Baseline . runBaseline ( this . getBaselineFileNameForContainingTestFile ( ` ${ suffix } .baseline.jsonc` ) , baseline ) ;
1217
1152
}
1218
1153
1219
1154
public verifyBaselineGetFileReferences ( fileName : string ) {
@@ -1280,11 +1215,6 @@ namespace FourSlash {
1280
1215
}
1281
1216
}
1282
1217
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
-
1288
1218
private assertObjectsEqual < T > ( fullActual : T , fullExpected : T , msgPrefix = "" ) : void {
1289
1219
const recur = < U > ( actual : U , expected : U , path : string ) => {
1290
1220
const fail = ( msg : string ) => {
@@ -2403,15 +2333,6 @@ namespace FourSlash {
2403
2333
this . goToPosition ( len ) ;
2404
2334
}
2405
2335
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
-
2415
2336
public goToRangeStart ( { fileName, pos } : Range ) {
2416
2337
this . openFile ( fileName ) ;
2417
2338
this . goToPosition ( pos ) ;
0 commit comments