@@ -206,6 +206,24 @@ namespace FourSlash {
206
206
207
207
private inputFiles = ts . createMap < string > ( ) ; // Map between inputFile's fileName and its content for easily looking up when resolving references
208
208
209
+ private static getDisplayPartsJson ( displayParts : ts . SymbolDisplayPart [ ] ) {
210
+ let result = "" ;
211
+ ts . forEach ( displayParts , part => {
212
+ if ( result ) {
213
+ result += ",\n " ;
214
+ }
215
+ else {
216
+ result = "[\n " ;
217
+ }
218
+ result += JSON . stringify ( part ) ;
219
+ } ) ;
220
+ if ( result ) {
221
+ result += "\n]" ;
222
+ }
223
+
224
+ return result ;
225
+ }
226
+
209
227
// Add input file which has matched file name with the given reference-file path.
210
228
// This is necessary when resolveReference flag is specified
211
229
private addMatchedInputFile ( referenceFilePath : string , extensions : string [ ] ) {
@@ -777,6 +795,20 @@ namespace FourSlash {
777
795
ts . forEachProperty ( this . rangesByText ( ) , ranges => this . verifyRangesReferenceEachOther ( ranges ) ) ;
778
796
}
779
797
798
+ public verifyDisplayPartsOfReferencedSymbol ( expected : ts . SymbolDisplayPart [ ] ) {
799
+ const referencedSymbols = this . findReferencesAtCaret ( ) ;
800
+
801
+ if ( referencedSymbols . length === 0 ) {
802
+ this . raiseError ( "No referenced symbols found at current caret position" ) ;
803
+ }
804
+ else if ( referencedSymbols . length > 1 ) {
805
+ this . raiseError ( "More than one referenced symbol found" ) ;
806
+ }
807
+
808
+ assert . equal ( TestState . getDisplayPartsJson ( referencedSymbols [ 0 ] . definition . displayParts ) ,
809
+ TestState . getDisplayPartsJson ( expected ) , this . messageAtLastKnownMarker ( "referenced symbol definition display parts" ) ) ;
810
+ }
811
+
780
812
private verifyReferencesWorker ( references : ts . ReferenceEntry [ ] , fileName : string , start : number , end : number , isWriteAccess ?: boolean , isDefinition ?: boolean ) {
781
813
for ( let i = 0 ; i < references . length ; i ++ ) {
782
814
const reference = references [ i ] ;
@@ -811,6 +843,10 @@ namespace FourSlash {
811
843
return this . languageService . getReferencesAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
812
844
}
813
845
846
+ private findReferencesAtCaret ( ) {
847
+ return this . languageService . findReferences ( this . activeFile . fileName , this . currentCaretPosition ) ;
848
+ }
849
+
814
850
public getSyntacticDiagnostics ( expected : string ) {
815
851
const diagnostics = this . languageService . getSyntacticDiagnostics ( this . activeFile . fileName ) ;
816
852
this . testDiagnostics ( expected , diagnostics ) ;
@@ -856,30 +892,12 @@ namespace FourSlash {
856
892
displayParts : ts . SymbolDisplayPart [ ] ,
857
893
documentation : ts . SymbolDisplayPart [ ] ) {
858
894
859
- function getDisplayPartsJson ( displayParts : ts . SymbolDisplayPart [ ] ) {
860
- let result = "" ;
861
- ts . forEach ( displayParts , part => {
862
- if ( result ) {
863
- result += ",\n " ;
864
- }
865
- else {
866
- result = "[\n " ;
867
- }
868
- result += JSON . stringify ( part ) ;
869
- } ) ;
870
- if ( result ) {
871
- result += "\n]" ;
872
- }
873
-
874
- return result ;
875
- }
876
-
877
895
const actualQuickInfo = this . languageService . getQuickInfoAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
878
896
assert . equal ( actualQuickInfo . kind , kind , this . messageAtLastKnownMarker ( "QuickInfo kind" ) ) ;
879
897
assert . equal ( actualQuickInfo . kindModifiers , kindModifiers , this . messageAtLastKnownMarker ( "QuickInfo kindModifiers" ) ) ;
880
898
assert . equal ( JSON . stringify ( actualQuickInfo . textSpan ) , JSON . stringify ( textSpan ) , this . messageAtLastKnownMarker ( "QuickInfo textSpan" ) ) ;
881
- assert . equal ( getDisplayPartsJson ( actualQuickInfo . displayParts ) , getDisplayPartsJson ( displayParts ) , this . messageAtLastKnownMarker ( "QuickInfo displayParts" ) ) ;
882
- assert . equal ( getDisplayPartsJson ( actualQuickInfo . documentation ) , getDisplayPartsJson ( documentation ) , this . messageAtLastKnownMarker ( "QuickInfo documentation" ) ) ;
899
+ assert . equal ( TestState . getDisplayPartsJson ( actualQuickInfo . displayParts ) , TestState . getDisplayPartsJson ( displayParts ) , this . messageAtLastKnownMarker ( "QuickInfo displayParts" ) ) ;
900
+ assert . equal ( TestState . getDisplayPartsJson ( actualQuickInfo . documentation ) , TestState . getDisplayPartsJson ( documentation ) , this . messageAtLastKnownMarker ( "QuickInfo documentation" ) ) ;
883
901
}
884
902
885
903
public verifyRenameLocations ( findInStrings : boolean , findInComments : boolean , ranges ?: Range [ ] ) {
@@ -2947,6 +2965,10 @@ namespace FourSlashInterface {
2947
2965
this . state . verifyRangesReferenceEachOther ( ranges ) ;
2948
2966
}
2949
2967
2968
+ public findReferencesDefinitionDisplayPartsAtCaretAre ( expected : ts . SymbolDisplayPart [ ] ) {
2969
+ this . state . verifyDisplayPartsOfReferencedSymbol ( expected ) ;
2970
+ }
2971
+
2950
2972
public rangesWithSameTextReferenceEachOther ( ) {
2951
2973
this . state . verifyRangesWithSameTextReferenceEachOther ( ) ;
2952
2974
}
0 commit comments