@@ -206,6 +206,24 @@ namespace FourSlash {
206206
207207 private inputFiles = ts . createMap < string > ( ) ; // Map between inputFile's fileName and its content for easily looking up when resolving references
208208
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+
209227 // Add input file which has matched file name with the given reference-file path.
210228 // This is necessary when resolveReference flag is specified
211229 private addMatchedInputFile ( referenceFilePath : string , extensions : string [ ] ) {
@@ -777,6 +795,20 @@ namespace FourSlash {
777795 ts . forEachProperty ( this . rangesByText ( ) , ranges => this . verifyRangesReferenceEachOther ( ranges ) ) ;
778796 }
779797
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+
780812 private verifyReferencesWorker ( references : ts . ReferenceEntry [ ] , fileName : string , start : number , end : number , isWriteAccess ?: boolean , isDefinition ?: boolean ) {
781813 for ( let i = 0 ; i < references . length ; i ++ ) {
782814 const reference = references [ i ] ;
@@ -811,6 +843,10 @@ namespace FourSlash {
811843 return this . languageService . getReferencesAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
812844 }
813845
846+ private findReferencesAtCaret ( ) {
847+ return this . languageService . findReferences ( this . activeFile . fileName , this . currentCaretPosition ) ;
848+ }
849+
814850 public getSyntacticDiagnostics ( expected : string ) {
815851 const diagnostics = this . languageService . getSyntacticDiagnostics ( this . activeFile . fileName ) ;
816852 this . testDiagnostics ( expected , diagnostics ) ;
@@ -856,30 +892,12 @@ namespace FourSlash {
856892 displayParts : ts . SymbolDisplayPart [ ] ,
857893 documentation : ts . SymbolDisplayPart [ ] ) {
858894
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-
877895 const actualQuickInfo = this . languageService . getQuickInfoAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
878896 assert . equal ( actualQuickInfo . kind , kind , this . messageAtLastKnownMarker ( "QuickInfo kind" ) ) ;
879897 assert . equal ( actualQuickInfo . kindModifiers , kindModifiers , this . messageAtLastKnownMarker ( "QuickInfo kindModifiers" ) ) ;
880898 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" ) ) ;
883901 }
884902
885903 public verifyRenameLocations ( findInStrings : boolean , findInComments : boolean , ranges ?: Range [ ] ) {
@@ -1546,7 +1564,7 @@ namespace FourSlash {
15461564 public goToDefinition ( definitionIndex : number ) {
15471565 const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
15481566 if ( ! definitions || ! definitions . length ) {
1549- this . raiseError ( "goToDefinition failed - expected to at least one definition location but got 0" ) ;
1567+ this . raiseError ( "goToDefinition failed - expected to find at least one definition location but got 0" ) ;
15501568 }
15511569
15521570 if ( definitionIndex >= definitions . length ) {
@@ -1561,7 +1579,7 @@ namespace FourSlash {
15611579 public goToTypeDefinition ( definitionIndex : number ) {
15621580 const definitions = this . languageService . getTypeDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
15631581 if ( ! definitions || ! definitions . length ) {
1564- this . raiseError ( "goToTypeDefinition failed - expected to at least one definition location but got 0" ) ;
1582+ this . raiseError ( "goToTypeDefinition failed - expected to find at least one definition location but got 0" ) ;
15651583 }
15661584
15671585 if ( definitionIndex >= definitions . length ) {
@@ -1582,7 +1600,7 @@ namespace FourSlash {
15821600 this . raiseError ( `goToDefinition - expected to 0 definition locations but got ${ definitions . length } ` ) ;
15831601 }
15841602 else if ( ! foundDefinitions && ! negative ) {
1585- this . raiseError ( "goToDefinition - expected to at least one definition location but got 0" ) ;
1603+ this . raiseError ( "goToDefinition - expected to find at least one definition location but got 0" ) ;
15861604 }
15871605 }
15881606
@@ -2947,6 +2965,10 @@ namespace FourSlashInterface {
29472965 this . state . verifyRangesReferenceEachOther ( ranges ) ;
29482966 }
29492967
2968+ public findReferencesDefinitionDisplayPartsAtCaretAre ( expected : ts . SymbolDisplayPart [ ] ) {
2969+ this . state . verifyDisplayPartsOfReferencedSymbol ( expected ) ;
2970+ }
2971+
29502972 public rangesWithSameTextReferenceEachOther ( ) {
29512973 this . state . verifyRangesWithSameTextReferenceEachOther ( ) ;
29522974 }
0 commit comments