@@ -1604,6 +1604,15 @@ namespace FourSlash {
16041604 assertFn ( actualCount , expectedCount , this . messageAtLastKnownMarker ( "Type definitions Count" ) ) ;
16051605 }
16061606
1607+ public verifyImplementationsCount ( negative : boolean , expectedCount : number ) {
1608+ const assertFn = negative ? assert . notEqual : assert . equal ;
1609+
1610+ const implementations = this . languageService . getImplementationAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1611+ const actualCount = implementations && implementations . length || 0 ;
1612+
1613+ assertFn ( actualCount , expectedCount , this . messageAtLastKnownMarker ( "Implementations Count" ) ) ;
1614+ }
1615+
16071616 public verifyDefinitionsName ( negative : boolean , expectedName : string , expectedContainerName : string ) {
16081617 const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
16091618 const actualDefinitionName = definitions && definitions . length ? definitions [ 0 ] . name : "" ;
@@ -1618,6 +1627,47 @@ namespace FourSlash {
16181627 }
16191628 }
16201629
1630+ public goToImplementation ( implIndex : number ) {
1631+ const implementations = this . languageService . getImplementationAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1632+ if ( ! implementations || ! implementations . length ) {
1633+ this . raiseError ( "goToImplementation failed - expected to at least one implementation location but got 0" ) ;
1634+ }
1635+
1636+ if ( implIndex >= implementations . length ) {
1637+ this . raiseError ( `goToImplementation failed - implIndex value (${ implIndex } ) exceeds implementation list size (${ implementations . length } )` ) ;
1638+ }
1639+
1640+ const implementation = implementations [ implIndex ] ;
1641+ this . openFile ( implementation . fileName ) ;
1642+ this . currentCaretPosition = implementation . textSpan . start ;
1643+ }
1644+
1645+ public verifyRangesInImplementationList ( ) {
1646+ const implementations = this . languageService . getImplementationAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1647+ if ( ! implementations || ! implementations . length ) {
1648+ this . raiseError ( "verifyRangesInImplementationList failed - expected to at least one implementation location but got 0" ) ;
1649+ }
1650+
1651+ const ranges = this . getRanges ( ) ;
1652+
1653+ if ( ! ranges || ! ranges . length ) {
1654+ this . raiseError ( "verifyRangesInImplementationList failed - expected to at least one range in test source" ) ;
1655+ }
1656+
1657+ for ( const range of ranges ) {
1658+ let rangeIsPresent = false ;
1659+ const length = range . end - range . start ;
1660+ for ( const impl of implementations ) {
1661+ if ( range . fileName === impl . fileName && range . start === impl . textSpan . start && length === impl . textSpan . length ) {
1662+ rangeIsPresent = true ;
1663+ break ;
1664+ }
1665+ }
1666+ assert . isTrue ( rangeIsPresent , `No implementation found for range ${ range . start } , ${ range . end } in ${ range . fileName } : ${ this . rangeText ( range ) } ` ) ;
1667+ }
1668+ assert . equal ( implementations . length , ranges . length , `Different number of implementations (${ implementations . length } ) and ranges (${ ranges . length } )` ) ;
1669+ }
1670+
16211671 public getMarkers ( ) : Marker [ ] {
16221672 // Return a copy of the list
16231673 return this . testData . markers . slice ( 0 ) ;
@@ -2768,6 +2818,10 @@ namespace FourSlashInterface {
27682818 this . state . goToTypeDefinition ( definitionIndex ) ;
27692819 }
27702820
2821+ public implementation ( implementationIndex = 0 ) {
2822+ this . state . goToImplementation ( implementationIndex ) ;
2823+ }
2824+
27712825 public position ( position : number , fileIndex ?: number ) : void ;
27722826 public position ( position : number , fileName ?: string ) : void ;
27732827 public position ( position : number , fileNameOrIndex ?: any ) : void {
@@ -2876,6 +2930,10 @@ namespace FourSlashInterface {
28762930 this . state . verifyTypeDefinitionsCount ( this . negative , expectedCount ) ;
28772931 }
28782932
2933+ public implementationCountIs ( expectedCount : number ) {
2934+ this . state . verifyImplementationsCount ( this . negative , expectedCount ) ;
2935+ }
2936+
28792937 public definitionLocationExists ( ) {
28802938 this . state . verifyDefinitionLocationExists ( this . negative ) ;
28812939 }
@@ -3113,6 +3171,10 @@ namespace FourSlashInterface {
31133171 public ProjectInfo ( expected : string [ ] ) {
31143172 this . state . verifyProjectInfo ( expected ) ;
31153173 }
3174+
3175+ public allRangesAppearInImplementationList ( ) {
3176+ this . state . verifyRangesInImplementationList ( ) ;
3177+ }
31163178 }
31173179
31183180 export class Edit {
0 commit comments