@@ -42,6 +42,7 @@ namespace FourSlash {
42
42
* is a range with `text in range` "selected".
43
43
*/
44
44
ranges : Range [ ] ;
45
+ rangesByText ?: ts . MultiMap < Range > ;
45
46
}
46
47
47
48
export interface Marker {
@@ -955,12 +956,15 @@ namespace FourSlash {
955
956
const fullExpected = ts . map < FourSlashInterface . ReferenceGroup , ReferenceGroupJson > ( parts , ( { definition, ranges } ) => ( {
956
957
definition : typeof definition === "string" ? definition : { ...definition , range : ts . createTextSpanFromRange ( definition . range ) } ,
957
958
references : ranges . map < ts . ReferenceEntry > ( r => {
958
- const { isWriteAccess = false , isDefinition = false , isInString } = ( r . marker && r . marker . data || { } ) as { isWriteAccess ?: boolean , isDefinition ?: boolean , isInString ?: true } ;
959
+ const { isWriteAccess = false , isDefinition = false , isInString, contextRangeIndex } = ( r . marker && r . marker . data || { } ) as { isWriteAccess ?: boolean , isDefinition ?: boolean , isInString ?: true , contextRangeIndex ?: number } ;
959
960
return {
960
961
fileName : r . fileName ,
961
962
textSpan : ts . createTextSpanFromRange ( r ) ,
962
963
isWriteAccess,
963
964
isDefinition,
965
+ ...( contextRangeIndex !== undefined ?
966
+ { contextSpan : ts . createTextSpanFromRange ( this . getRanges ( ) [ contextRangeIndex ] ) } :
967
+ undefined ) ,
964
968
...( isInString ? { isInString : true } : undefined ) ,
965
969
} ;
966
970
} ) ,
@@ -997,8 +1001,8 @@ namespace FourSlash {
997
1001
assert . deepEqual < ReadonlyArray < ts . ReferenceEntry > | undefined > ( refs , expected ) ;
998
1002
}
999
1003
1000
- public verifySingleReferenceGroup ( definition : FourSlashInterface . ReferenceGroupDefinition , ranges ?: Range [ ] ) {
1001
- ranges = ranges || this . getRanges ( ) ;
1004
+ public verifySingleReferenceGroup ( definition : FourSlashInterface . ReferenceGroupDefinition , ranges ?: Range [ ] | string ) {
1005
+ ranges = ts . isString ( ranges ) ? this . rangesByText ( ) . get ( ranges ) ! : ranges || this . getRanges ( ) ;
1002
1006
this . verifyReferenceGroups ( ranges , [ { definition, ranges } ] ) ;
1003
1007
}
1004
1008
@@ -1011,7 +1015,7 @@ Actual: ${stringify(fullActual)}`);
1011
1015
} ;
1012
1016
1013
1017
if ( ( actual === undefined ) !== ( expected === undefined ) ) {
1014
- fail ( `Expected ${ expected } , got ${ actual } ` ) ;
1018
+ fail ( `Expected ${ stringify ( expected ) } , got ${ stringify ( actual ) } ` ) ;
1015
1019
}
1016
1020
1017
1021
for ( const key in actual ) {
@@ -1021,7 +1025,7 @@ Actual: ${stringify(fullActual)}`);
1021
1025
recur ( ak , ek , path ? path + "." + key : key ) ;
1022
1026
}
1023
1027
else if ( ak !== ek ) {
1024
- fail ( `Expected '${ key } ' to be '${ ek } ', got '${ ak } '` ) ;
1028
+ fail ( `Expected '${ key } ' to be '${ stringify ( ek ) } ', got '${ stringify ( ak ) } '` ) ;
1025
1029
}
1026
1030
}
1027
1031
}
@@ -1189,7 +1193,15 @@ Actual: ${stringify(fullActual)}`);
1189
1193
locations && ts . sort ( locations , ( r1 , r2 ) => ts . compareStringsCaseSensitive ( r1 . fileName , r2 . fileName ) || r1 . textSpan . start - r2 . textSpan . start ) ;
1190
1194
assert . deepEqual ( sort ( references ) , sort ( ranges . map ( ( rangeOrOptions ) : ts . RenameLocation => {
1191
1195
const { range, ...prefixSuffixText } = "range" in rangeOrOptions ? rangeOrOptions : { range : rangeOrOptions } ;
1192
- return { fileName : range . fileName , textSpan : ts . createTextSpanFromRange ( range ) , ...prefixSuffixText } ;
1196
+ const { contextRangeIndex } = ( range . marker && range . marker . data || { } ) as { contextRangeIndex ?: number ; } ;
1197
+ return {
1198
+ fileName : range . fileName ,
1199
+ textSpan : ts . createTextSpanFromRange ( range ) ,
1200
+ ...( contextRangeIndex !== undefined ?
1201
+ { contextSpan : ts . createTextSpanFromRange ( this . getRanges ( ) [ contextRangeIndex ] ) } :
1202
+ undefined ) ,
1203
+ ...prefixSuffixText
1204
+ } ;
1193
1205
} ) ) ) ;
1194
1206
}
1195
1207
}
@@ -1844,6 +1856,7 @@ Actual: ${stringify(fullActual)}`);
1844
1856
range . end = updatePosition ( range . end , editStart , editEnd , newText ) ;
1845
1857
}
1846
1858
}
1859
+ this . testData . rangesByText = undefined ;
1847
1860
}
1848
1861
1849
1862
private removeWhitespace ( text : string ) : string {
@@ -2026,7 +2039,9 @@ Actual: ${stringify(fullActual)}`);
2026
2039
}
2027
2040
2028
2041
public rangesByText ( ) : ts . Map < Range [ ] > {
2042
+ if ( this . testData . rangesByText ) return this . testData . rangesByText ;
2029
2043
const result = ts . createMultiMap < Range > ( ) ;
2044
+ this . testData . rangesByText = result ;
2030
2045
for ( const range of this . getRanges ( ) ) {
2031
2046
const text = this . rangeText ( range ) ;
2032
2047
result . add ( text , range ) ;
@@ -2714,8 +2729,8 @@ Actual: ${stringify(fullActual)}`);
2714
2729
return this . languageService . getDocumentHighlights ( this . activeFile . fileName , this . currentCaretPosition , filesToSearch ) ;
2715
2730
}
2716
2731
2717
- public verifyRangesAreOccurrences ( isWriteAccess ?: boolean ) {
2718
- const ranges = this . getRanges ( ) ;
2732
+ public verifyRangesAreOccurrences ( isWriteAccess ?: boolean , ranges ?: Range [ ] ) {
2733
+ ranges = ranges || this . getRanges ( ) ;
2719
2734
for ( const r of ranges ) {
2720
2735
this . goToRangeStart ( r ) ;
2721
2736
this . verifyOccurrencesAtPositionListCount ( ranges . length ) ;
@@ -2725,8 +2740,13 @@ Actual: ${stringify(fullActual)}`);
2725
2740
}
2726
2741
}
2727
2742
2728
- public verifyRangesWithSameTextAreRenameLocations ( ) {
2729
- this . rangesByText ( ) . forEach ( ranges => this . verifyRangesAreRenameLocations ( ranges ) ) ;
2743
+ public verifyRangesWithSameTextAreRenameLocations ( ...texts : string [ ] ) {
2744
+ if ( texts . length ) {
2745
+ texts . forEach ( text => this . verifyRangesAreRenameLocations ( this . rangesByText ( ) . get ( text ) ! ) ) ;
2746
+ }
2747
+ else {
2748
+ this . rangesByText ( ) . forEach ( ranges => this . verifyRangesAreRenameLocations ( ranges ) ) ;
2749
+ }
2730
2750
}
2731
2751
2732
2752
public verifyRangesWithSameTextAreDocumentHighlights ( ) {
@@ -3971,7 +3991,7 @@ namespace FourSlashInterface {
3971
3991
this . state . verifyGetReferencesForServerTest ( expected ) ;
3972
3992
}
3973
3993
3974
- public singleReferenceGroup ( definition : ReferenceGroupDefinition , ranges ?: FourSlash . Range [ ] ) {
3994
+ public singleReferenceGroup ( definition : ReferenceGroupDefinition , ranges ?: FourSlash . Range [ ] | string ) {
3975
3995
this . state . verifySingleReferenceGroup ( definition , ranges ) ;
3976
3996
}
3977
3997
@@ -4093,12 +4113,12 @@ namespace FourSlashInterface {
4093
4113
this . state . verifyOccurrencesAtPositionListCount ( expectedCount ) ;
4094
4114
}
4095
4115
4096
- public rangesAreOccurrences ( isWriteAccess ?: boolean ) {
4097
- this . state . verifyRangesAreOccurrences ( isWriteAccess ) ;
4116
+ public rangesAreOccurrences ( isWriteAccess ?: boolean , ranges ?: FourSlash . Range [ ] ) {
4117
+ this . state . verifyRangesAreOccurrences ( isWriteAccess , ranges ) ;
4098
4118
}
4099
4119
4100
- public rangesWithSameTextAreRenameLocations ( ) {
4101
- this . state . verifyRangesWithSameTextAreRenameLocations ( ) ;
4120
+ public rangesWithSameTextAreRenameLocations ( ... texts : string [ ] ) {
4121
+ this . state . verifyRangesWithSameTextAreRenameLocations ( ... texts ) ;
4102
4122
}
4103
4123
4104
4124
public rangesAreRenameLocations ( options ?: FourSlash . Range [ ] | { findInStrings ?: boolean , findInComments ?: boolean , ranges ?: FourSlash . Range [ ] } ) {
0 commit comments