@@ -953,6 +953,10 @@ namespace FourSlash {
953953 return this . getChecker ( ) . getSymbolsInScope ( node , ts . SymbolFlags . Value | ts . SymbolFlags . Type | ts . SymbolFlags . Namespace ) ;
954954 }
955955
956+ public setTypesRegistry ( map : ts . MapLike < void > ) : void {
957+ this . languageServiceAdapterHost . typesRegistry = ts . createMapFromTemplate ( map ) ;
958+ }
959+
956960 public verifyTypeOfSymbolAtLocation ( range : Range , symbol : ts . Symbol , expected : string ) : void {
957961 const node = this . goToAndGetNode ( range ) ;
958962 const checker = this . getChecker ( ) ;
@@ -2750,16 +2754,26 @@ Actual: ${stringify(fullActual)}`);
27502754 }
27512755 }
27522756
2753- public verifyCodeFixAvailable ( negative : boolean ) {
2754- const codeFix = this . getCodeFixActions ( this . activeFile . fileName ) ;
2757+ public verifyCodeFixAvailable ( negative : boolean , info : FourSlashInterface . VerifyCodeFixAvailableOptions [ ] | undefined ) {
2758+ const codeFixes = this . getCodeFixActions ( this . activeFile . fileName ) ;
27552759
2756- if ( negative && codeFix . length ) {
2757- this . raiseError ( `verifyCodeFixAvailable failed - expected no fixes but found one.` ) ;
2760+ if ( negative ) {
2761+ if ( codeFixes . length ) {
2762+ this . raiseError ( `verifyCodeFixAvailable failed - expected no fixes but found one.` ) ;
2763+ }
2764+ return ;
27582765 }
27592766
2760- if ( ! ( negative || codeFix . length ) ) {
2767+ if ( ! codeFixes . length ) {
27612768 this . raiseError ( `verifyCodeFixAvailable failed - expected code fixes but none found.` ) ;
27622769 }
2770+ if ( info ) {
2771+ assert . equal ( info . length , codeFixes . length ) ;
2772+ ts . zipWith ( codeFixes , info , ( fix , info ) => {
2773+ assert . equal ( fix . description , info . description ) ;
2774+ this . assertObjectsEqual ( fix . commands , info . commands ) ;
2775+ } ) ;
2776+ }
27632777 }
27642778
27652779 public verifyApplicableRefactorAvailableAtMarker ( negative : boolean , markerName : string ) {
@@ -2803,6 +2817,14 @@ Actual: ${stringify(fullActual)}`);
28032817 }
28042818 }
28052819
2820+ public verifyRefactor ( { name, actionName, refactors } : FourSlashInterface . VerifyRefactorOptions ) {
2821+ const selection = this . getSelection ( ) ;
2822+
2823+ const actualRefactors = ( this . languageService . getApplicableRefactors ( this . activeFile . fileName , selection ) || ts . emptyArray )
2824+ . filter ( r => r . name === name && r . actions . some ( a => a . name === actionName ) ) ;
2825+ this . assertObjectsEqual ( actualRefactors , refactors ) ;
2826+ }
2827+
28062828 public verifyApplicableRefactorAvailableForRange ( negative : boolean ) {
28072829 const ranges = this . getRanges ( ) ;
28082830 if ( ! ( ranges && ranges . length === 1 ) ) {
@@ -3577,6 +3599,10 @@ namespace FourSlashInterface {
35773599 public symbolsInScope ( range : FourSlash . Range ) : ts . Symbol [ ] {
35783600 return this . state . symbolsInScope ( range ) ;
35793601 }
3602+
3603+ public setTypesRegistry ( map : ts . MapLike < void > ) : void {
3604+ this . state . setTypesRegistry ( map ) ;
3605+ }
35803606 }
35813607
35823608 export class GoTo {
@@ -3752,8 +3778,8 @@ namespace FourSlashInterface {
37523778 this . state . verifyCodeFix ( options ) ;
37533779 }
37543780
3755- public codeFixAvailable ( ) {
3756- this . state . verifyCodeFixAvailable ( this . negative ) ;
3781+ public codeFixAvailable ( options ?: VerifyCodeFixAvailableOptions [ ] ) {
3782+ this . state . verifyCodeFixAvailable ( this . negative , options ) ;
37573783 }
37583784
37593785 public applicableRefactorAvailableAtMarker ( markerName : string ) {
@@ -3764,6 +3790,10 @@ namespace FourSlashInterface {
37643790 this . state . verifyApplicableRefactorAvailableForRange ( this . negative ) ;
37653791 }
37663792
3793+ public refactor ( options : VerifyRefactorOptions ) {
3794+ this . state . verifyRefactor ( options ) ;
3795+ }
3796+
37673797 public refactorAvailable ( name : string , actionName ?: string ) {
37683798 this . state . verifyRefactorAvailable ( this . negative , name , actionName ) ;
37693799 }
@@ -4404,4 +4434,15 @@ namespace FourSlashInterface {
44044434 errorCode ?: number ;
44054435 index ?: number ;
44064436 }
4437+
4438+ export interface VerifyCodeFixAvailableOptions {
4439+ description : string ;
4440+ commands ?: ts . CodeActionCommand [ ] ;
4441+ }
4442+
4443+ export interface VerifyRefactorOptions {
4444+ name : string ;
4445+ actionName : string ;
4446+ refactors : ts . ApplicableRefactorInfo [ ] ;
4447+ }
44074448}
0 commit comments