@@ -616,19 +616,23 @@ namespace FourSlash {
616
616
}
617
617
618
618
public verifyGoToDefinition ( arg0 : any , endMarkerNames ?: string | string [ ] ) {
619
- this . verifyGoToX ( arg0 , endMarkerNames , ( ) => this . getGoToDefinition ( ) ) ;
619
+ this . verifyGoToX ( arg0 , endMarkerNames , ( ) => this . getGoToDefinitionAndBoundSpan ( ) ) ;
620
620
}
621
621
622
622
private getGoToDefinition ( ) : ts . DefinitionInfo [ ] {
623
623
return this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
624
624
}
625
625
626
+ private getGoToDefinitionAndBoundSpan ( ) : ts . DefinitionInfoAndBoundSpan {
627
+ return this . languageService . getDefinitionAndBoundSpan ( this . activeFile . fileName , this . currentCaretPosition ) ;
628
+ }
629
+
626
630
public verifyGoToType ( arg0 : any , endMarkerNames ?: string | string [ ] ) {
627
631
this . verifyGoToX ( arg0 , endMarkerNames , ( ) =>
628
632
this . languageService . getTypeDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ) ;
629
633
}
630
634
631
- private verifyGoToX ( arg0 : any , endMarkerNames : string | string [ ] | undefined , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
635
+ private verifyGoToX ( arg0 : any , endMarkerNames : string | string [ ] | undefined , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
632
636
if ( endMarkerNames ) {
633
637
this . verifyGoToXPlain ( arg0 , endMarkerNames , getDefs ) ;
634
638
}
@@ -648,7 +652,7 @@ namespace FourSlash {
648
652
}
649
653
}
650
654
651
- private verifyGoToXPlain ( startMarkerNames : string | string [ ] , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
655
+ private verifyGoToXPlain ( startMarkerNames : string | string [ ] , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
652
656
for ( const start of toArray ( startMarkerNames ) ) {
653
657
this . verifyGoToXSingle ( start , endMarkerNames , getDefs ) ;
654
658
}
@@ -660,26 +664,57 @@ namespace FourSlash {
660
664
}
661
665
}
662
666
663
- private verifyGoToXSingle ( startMarkerName : string , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
667
+ private verifyGoToXSingle ( startMarkerName : string , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
664
668
this . goToMarker ( startMarkerName ) ;
665
- this . verifyGoToXWorker ( toArray ( endMarkerNames ) , getDefs ) ;
669
+ this . verifyGoToXWorker ( toArray ( endMarkerNames ) , getDefs , startMarkerName ) ;
666
670
}
667
671
668
- private verifyGoToXWorker ( endMarkers : string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
669
- const definitions = getDefs ( ) || [ ] ;
672
+ private verifyGoToXWorker ( endMarkers : string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined , startMarkerName ?: string ) {
673
+ const defs = getDefs ( ) ;
674
+ let definitions : ts . DefinitionInfo [ ] | ReadonlyArray < ts . DefinitionInfo > ;
675
+ let testName : string ;
676
+
677
+ if ( ! defs || Array . isArray ( defs ) ) {
678
+ definitions = defs as ts . DefinitionInfo [ ] || [ ] ;
679
+ testName = "goToDefinitions" ;
680
+ }
681
+ else {
682
+ this . verifyDefinitionTextSpan ( defs , startMarkerName ) ;
683
+
684
+ definitions = defs . definitions ;
685
+ testName = "goToDefinitionsAndBoundSpan" ;
686
+ }
670
687
671
688
if ( endMarkers . length !== definitions . length ) {
672
- this . raiseError ( `goToDefinitions failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
689
+ this . raiseError ( `${ testName } failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
673
690
}
674
691
675
692
ts . zipWith ( endMarkers , definitions , ( endMarker , definition , i ) => {
676
693
const marker = this . getMarkerByName ( endMarker ) ;
677
694
if ( marker . fileName !== definition . fileName || marker . position !== definition . textSpan . start ) {
678
- this . raiseError ( `goToDefinition failed for definition ${ endMarker } (${ i } ): expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } ` ) ;
695
+ this . raiseError ( `${ testName } failed for definition ${ endMarker } (${ i } ): expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } ` ) ;
679
696
}
680
697
} ) ;
681
698
}
682
699
700
+ private verifyDefinitionTextSpan ( defs : ts . DefinitionInfoAndBoundSpan , startMarkerName : string ) {
701
+ const range = this . testData . ranges . find ( range => this . markerName ( range . marker ) === startMarkerName ) ;
702
+
703
+ if ( ! range && ! defs . textSpan ) {
704
+ return ;
705
+ }
706
+
707
+ if ( ! range ) {
708
+ this . raiseError ( `goToDefinitionsAndBoundSpan failed - found a TextSpan ${ JSON . stringify ( defs . textSpan ) } when it wasn't expected.` ) ;
709
+ }
710
+ else if ( defs . textSpan . start !== range . start || defs . textSpan . length !== range . end - range . start ) {
711
+ const expected : ts . TextSpan = {
712
+ start : range . start , length : range . end - range . start
713
+ } ;
714
+ this . raiseError ( `goToDefinitionsAndBoundSpan failed - expected to find TextSpan ${ JSON . stringify ( expected ) } but got ${ JSON . stringify ( defs . textSpan ) } ` ) ;
715
+ }
716
+ }
717
+
683
718
public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
684
719
const emit = this . languageService . getEmitOutput ( this . activeFile . fileName ) ;
685
720
if ( emit . outputFiles . length !== 1 ) {
@@ -3933,6 +3968,7 @@ namespace FourSlashInterface {
3933
3968
}
3934
3969
3935
3970
public goToDefinition ( startMarkerName : string | string [ ] , endMarkerName : string | string [ ] ) : void ;
3971
+ public goToDefinition ( startMarkerName : string | string [ ] , endMarkerName : string | string [ ] , range : FourSlash . Range ) : void ;
3936
3972
public goToDefinition ( startsAndEnds : [ string | string [ ] , string | string [ ] ] [ ] ) : void ;
3937
3973
public goToDefinition ( startsAndEnds : { [ startMarkerName : string ] : string | string [ ] } ) : void ;
3938
3974
public goToDefinition ( arg0 : any , endMarkerName ?: string | string [ ] ) {
0 commit comments