@@ -584,18 +584,23 @@ namespace FourSlash {
584584
585585 public verifyGoToDefinition ( arg0 : any , endMarkerNames ?: string | string [ ] ) {
586586 this . verifyGoToX ( arg0 , endMarkerNames , ( ) => this . getGoToDefinition ( ) ) ;
587+ this . verifyGoToX ( arg0 , endMarkerNames , ( ) => this . getGoToDefinitionAndBoundSpan ( ) ) ;
587588 }
588589
589590 private getGoToDefinition ( ) : ts . DefinitionInfo [ ] {
590591 return this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
591592 }
592593
594+ private getGoToDefinitionAndBoundSpan ( ) : ts . DefinitionInfoAndBoundSpan {
595+ return this . languageService . getDefinitionAndBoundSpan ( this . activeFile . fileName , this . currentCaretPosition ) ;
596+ }
597+
593598 public verifyGoToType ( arg0 : any , endMarkerNames ?: string | string [ ] ) {
594599 this . verifyGoToX ( arg0 , endMarkerNames , ( ) =>
595600 this . languageService . getTypeDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ) ;
596601 }
597602
598- private verifyGoToX ( arg0 : any , endMarkerNames : string | string [ ] | undefined , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
603+ private verifyGoToX ( arg0 : any , endMarkerNames : string | string [ ] | undefined , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
599604 if ( endMarkerNames ) {
600605 this . verifyGoToXPlain ( arg0 , endMarkerNames , getDefs ) ;
601606 }
@@ -615,7 +620,7 @@ namespace FourSlash {
615620 }
616621 }
617622
618- private verifyGoToXPlain ( startMarkerNames : string | string [ ] , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
623+ private verifyGoToXPlain ( startMarkerNames : string | string [ ] , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
619624 for ( const start of toArray ( startMarkerNames ) ) {
620625 this . verifyGoToXSingle ( start , endMarkerNames , getDefs ) ;
621626 }
@@ -627,26 +632,60 @@ namespace FourSlash {
627632 }
628633 }
629634
630- private verifyGoToXSingle ( startMarkerName : string , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
635+ private verifyGoToXSingle ( startMarkerName : string , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
631636 this . goToMarker ( startMarkerName ) ;
632- this . verifyGoToXWorker ( toArray ( endMarkerNames ) , getDefs ) ;
637+ this . verifyGoToXWorker ( toArray ( endMarkerNames ) , getDefs , startMarkerName ) ;
633638 }
634639
635- private verifyGoToXWorker ( endMarkers : string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
636- const definitions = getDefs ( ) || [ ] ;
640+ private verifyGoToXWorker ( endMarkers : string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined , startMarkerName ?: string ) {
641+ const defs = getDefs ( ) ;
642+ let definitions : ts . DefinitionInfo [ ] | ReadonlyArray < ts . DefinitionInfo > ;
643+ let testName : string ;
644+ if ( this . isDefinitionInfoAndBoundSpan ( defs ) ) {
645+ this . verifyDefinitionTextSpan ( defs , startMarkerName ) ;
646+
647+ definitions = defs . definitions ;
648+ testName = "goToDefinitionsAndBoundSpan" ;
649+ }
650+ else {
651+ definitions = defs || [ ] ;
652+ testName = "goToDefinitions" ;
653+ }
637654
638655 if ( endMarkers . length !== definitions . length ) {
639- this . raiseError ( `goToDefinitions failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
656+ this . raiseError ( `${ testName } failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
640657 }
641658
642659 ts . zipWith ( endMarkers , definitions , ( endMarker , definition , i ) => {
643660 const marker = this . getMarkerByName ( endMarker ) ;
644661 if ( marker . fileName !== definition . fileName || marker . position !== definition . textSpan . start ) {
645- this . raiseError ( `goToDefinition failed for definition ${ endMarker } (${ i } ): expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } ` ) ;
662+ this . raiseError ( `${ testName } failed for definition ${ endMarker } (${ i } ): expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } ` ) ;
646663 }
647664 } ) ;
648665 }
649666
667+ private verifyDefinitionTextSpan ( defs : ts . DefinitionInfoAndBoundSpan , startMarkerName : string ) {
668+ const range = this . testData . ranges . find ( range => this . markerName ( range . marker ) === startMarkerName ) ;
669+
670+ if ( ! range && ! defs . textSpan ) {
671+ return ;
672+ }
673+
674+ if ( ! range ) {
675+ this . raiseError ( `goToDefinitionsAndBoundSpan failed - found a TextSpan ${ JSON . stringify ( defs . textSpan ) } when it wasn't expected.` ) ;
676+ }
677+ else if ( defs . textSpan . start !== range . start || defs . textSpan . length !== range . end - range . start ) {
678+ const expected : ts . TextSpan = {
679+ start : range . start , length : range . end - range . start
680+ } ;
681+ this . raiseError ( `goToDefinitionsAndBoundSpan failed - expected to find TextSpan ${ JSON . stringify ( expected ) } but got ${ JSON . stringify ( defs . textSpan ) } ` ) ;
682+ }
683+ }
684+
685+ private isDefinitionInfoAndBoundSpan ( definition : ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) : definition is ts . DefinitionInfoAndBoundSpan {
686+ return definition && ( < ts . DefinitionInfoAndBoundSpan > definition ) . definitions !== undefined ;
687+ }
688+
650689 public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
651690 const emit = this . languageService . getEmitOutput ( this . activeFile . fileName ) ;
652691 if ( emit . outputFiles . length !== 1 ) {
@@ -3828,6 +3867,7 @@ namespace FourSlashInterface {
38283867 }
38293868
38303869 public goToDefinition ( startMarkerName : string | string [ ] , endMarkerName : string | string [ ] ) : void ;
3870+ public goToDefinition ( startMarkerName : string | string [ ] , endMarkerName : string | string [ ] , range : FourSlash . Range ) : void ;
38313871 public goToDefinition ( startsAndEnds : [ string | string [ ] , string | string [ ] ] [ ] ) : void ;
38323872 public goToDefinition ( startsAndEnds : { [ startMarkerName : string ] : string | string [ ] } ) : void ;
38333873 public goToDefinition ( arg0 : any , endMarkerName ?: string | string [ ] ) {
0 commit comments