@@ -2985,7 +2985,7 @@ Actual: ${stringify(fullActual)}`);
2985
2985
}
2986
2986
2987
2987
public verifyApplicableRefactorAvailableAtMarker ( negative : boolean , markerName : string ) {
2988
- const isAvailable = this . getApplicableRefactors ( this . getMarkerByName ( markerName ) . position ) . length > 0 ;
2988
+ const isAvailable = this . getApplicableRefactors ( this . getMarkerByName ( markerName ) ) . length > 0 ;
2989
2989
if ( negative && isAvailable ) {
2990
2990
this . raiseError ( `verifyApplicableRefactorAvailableAtMarker failed - expected no refactor at marker ${ markerName } but found some.` ) ;
2991
2991
}
@@ -3002,7 +3002,7 @@ Actual: ${stringify(fullActual)}`);
3002
3002
}
3003
3003
3004
3004
public verifyRefactorAvailable ( negative : boolean , name : string , actionName ?: string ) {
3005
- let refactors = this . getApplicableRefactors ( this . getSelection ( ) ) ;
3005
+ let refactors = this . getApplicableRefactorsAtSelection ( ) ;
3006
3006
refactors = refactors . filter ( r => r . name === name && ( actionName === undefined || r . actions . some ( a => a . name === actionName ) ) ) ;
3007
3007
const isAvailable = refactors . length > 0 ;
3008
3008
@@ -3022,11 +3022,11 @@ Actual: ${stringify(fullActual)}`);
3022
3022
}
3023
3023
3024
3024
public verifyRefactorsAvailable ( names : ReadonlyArray < string > ) : void {
3025
- assert . deepEqual ( unique ( this . getApplicableRefactors ( this . getSelection ( ) ) , r => r . name ) , names ) ;
3025
+ assert . deepEqual ( unique ( this . getApplicableRefactorsAtSelection ( ) , r => r . name ) , names ) ;
3026
3026
}
3027
3027
3028
3028
public verifyRefactor ( { name, actionName, refactors } : FourSlashInterface . VerifyRefactorOptions ) {
3029
- const actualRefactors = this . getApplicableRefactors ( this . getSelection ( ) ) . filter ( r => r . name === name && r . actions . some ( a => a . name === actionName ) ) ;
3029
+ const actualRefactors = this . getApplicableRefactorsAtSelection ( ) . filter ( r => r . name === name && r . actions . some ( a => a . name === actionName ) ) ;
3030
3030
this . assertObjectsEqual ( actualRefactors , refactors ) ;
3031
3031
}
3032
3032
@@ -3047,7 +3047,7 @@ Actual: ${stringify(fullActual)}`);
3047
3047
3048
3048
public applyRefactor ( { refactorName, actionName, actionDescription, newContent : newContentWithRenameMarker } : FourSlashInterface . ApplyRefactorOptions ) {
3049
3049
const range = this . getSelection ( ) ;
3050
- const refactors = this . getApplicableRefactors ( range ) ;
3050
+ const refactors = this . getApplicableRefactorsAtSelection ( ) ;
3051
3051
const refactorsWithName = refactors . filter ( r => r . name === refactorName ) ;
3052
3052
if ( refactorsWithName . length === 0 ) {
3053
3053
this . raiseError ( `The expected refactor: ${ refactorName } is not available at the marker location.\nAvailable refactors: ${ refactors . map ( r => r . name ) } ` ) ;
@@ -3125,7 +3125,7 @@ Actual: ${stringify(fullActual)}`);
3125
3125
const action = ts . first ( refactor . actions ) ;
3126
3126
assert ( action . name === "Move to a new file" && action . description === "Move to a new file" ) ;
3127
3127
3128
- const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactor . name , action . name , options . preferences || ts . emptyOptions ) ! ;
3128
+ const editInfo = this . languageService . getEditsForRefactor ( range . fileName , this . formatCodeSettings , range , refactor . name , action . name , options . preferences || ts . emptyOptions ) ! ;
3129
3129
this . testNewFileContents ( editInfo . edits , options . newFileContents , "move to new file" ) ;
3130
3130
}
3131
3131
@@ -3165,21 +3165,21 @@ Actual: ${stringify(fullActual)}`);
3165
3165
formattingOptions ?: ts . FormatCodeSettings ) {
3166
3166
3167
3167
formattingOptions = formattingOptions || this . formatCodeSettings ;
3168
- const markerPos = this . getMarkerByName ( markerName ) . position ;
3168
+ const marker = this . getMarkerByName ( markerName ) ;
3169
3169
3170
- const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , markerPos , ts . emptyOptions ) ;
3170
+ const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , marker . position , ts . emptyOptions ) ;
3171
3171
const applicableRefactorToApply = ts . find ( applicableRefactors , refactor => refactor . name === refactorNameToApply ) ;
3172
3172
3173
3173
if ( ! applicableRefactorToApply ) {
3174
3174
this . raiseError ( `The expected refactor: ${ refactorNameToApply } is not available at the marker location.` ) ;
3175
3175
}
3176
3176
3177
- const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , formattingOptions , markerPos , refactorNameToApply , actionName , ts . emptyOptions ) ! ;
3177
+ const editInfo = this . languageService . getEditsForRefactor ( marker . fileName , formattingOptions , marker . position , refactorNameToApply , actionName , ts . emptyOptions ) ! ;
3178
3178
3179
3179
for ( const edit of editInfo . edits ) {
3180
3180
this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
3181
3181
}
3182
- const actualContent = this . getFileContent ( this . activeFile . fileName ) ;
3182
+ const actualContent = this . getFileContent ( marker . fileName ) ;
3183
3183
3184
3184
if ( actualContent !== expectedContent ) {
3185
3185
this . raiseError ( `verifyFileAfterApplyingRefactors failed:\n${ showTextDiff ( expectedContent , actualContent ) } ` ) ;
@@ -3381,8 +3381,14 @@ Actual: ${stringify(fullActual)}`);
3381
3381
test ( renameKeys ( newFileContents , key => pathUpdater ( key ) || key ) , "with file moved" ) ;
3382
3382
}
3383
3383
3384
- private getApplicableRefactors ( positionOrRange : number | ts . TextRange , preferences = ts . emptyOptions ) : ReadonlyArray < ts . ApplicableRefactorInfo > {
3385
- return this . languageService . getApplicableRefactors ( this . activeFile . fileName , positionOrRange , preferences ) || ts . emptyArray ;
3384
+ private getApplicableRefactorsAtSelection ( ) {
3385
+ return this . getApplicableRefactorsWorker ( this . getSelection ( ) , this . activeFile . fileName ) ;
3386
+ }
3387
+ private getApplicableRefactors ( rangeOrMarker : Range | Marker , preferences = ts . emptyOptions ) : ReadonlyArray < ts . ApplicableRefactorInfo > {
3388
+ return this . getApplicableRefactorsWorker ( "position" in rangeOrMarker ? rangeOrMarker . position : rangeOrMarker , rangeOrMarker . fileName , preferences ) ;
3389
+ }
3390
+ private getApplicableRefactorsWorker ( positionOrRange : number | ts . TextRange , fileName : string , preferences = ts . emptyOptions ) : ReadonlyArray < ts . ApplicableRefactorInfo > {
3391
+ return this . languageService . getApplicableRefactors ( fileName , positionOrRange , preferences ) || ts . emptyArray ;
3386
3392
}
3387
3393
}
3388
3394
0 commit comments