@@ -2122,15 +2122,15 @@ namespace FourSlash {
2122
2122
* Because codefixes are only applied on the working file, it is unsafe
2123
2123
* to apply this more than once (consider a refactoring across files).
2124
2124
*/
2125
- public verifyRangeAfterCodeFix ( expectedText : string , errorCode ?: number , includeWhiteSpace ?: boolean ) {
2125
+ public verifyRangeAfterCodeFix ( expectedText : string , includeWhiteSpace ?: boolean , errorCode ?: number , index ?: number ) {
2126
2126
const ranges = this . getRanges ( ) ;
2127
2127
if ( ranges . length !== 1 ) {
2128
2128
this . raiseError ( "Exactly one range should be specified in the testfile." ) ;
2129
2129
}
2130
2130
2131
2131
const fileName = this . activeFile . fileName ;
2132
2132
2133
- this . applyCodeFixActions ( fileName , this . getCodeFixActions ( fileName , errorCode ) ) ;
2133
+ this . applyCodeAction ( fileName , this . getCodeFixActions ( fileName , errorCode ) , index ) ;
2134
2134
2135
2135
const actualText = this . rangeText ( ranges [ 0 ] ) ;
2136
2136
@@ -2155,7 +2155,7 @@ namespace FourSlash {
2155
2155
public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string ) {
2156
2156
fileName = fileName ? fileName : this . activeFile . fileName ;
2157
2157
2158
- this . applyCodeFixActions ( fileName , this . getCodeFixActions ( fileName ) ) ;
2158
+ this . applyCodeAction ( fileName , this . getCodeFixActions ( fileName ) ) ;
2159
2159
2160
2160
const actualContents : string = this . getFileContent ( fileName ) ;
2161
2161
if ( this . removeWhitespace ( actualContents ) !== this . removeWhitespace ( expectedContents ) ) {
@@ -2193,12 +2193,20 @@ namespace FourSlash {
2193
2193
return actions ;
2194
2194
}
2195
2195
2196
- private applyCodeFixActions ( fileName : string , actions : ts . CodeAction [ ] ) : void {
2197
- if ( ! ( actions && actions . length === 1 ) ) {
2198
- this . raiseError ( `Should find exactly one codefix, but ${ actions ? actions . length : "none" } found.` ) ;
2196
+ private applyCodeAction ( fileName : string , actions : ts . CodeAction [ ] , index ?: number ) : void {
2197
+ if ( index === undefined ) {
2198
+ if ( ! ( actions && actions . length === 1 ) ) {
2199
+ this . raiseError ( `Should find exactly one codefix, but ${ actions ? actions . length : "none" } found.` ) ;
2200
+ }
2201
+ index = 0 ;
2202
+ }
2203
+ else {
2204
+ if ( ! ( actions && actions . length >= index + 1 ) ) {
2205
+ this . raiseError ( `Should find at least ${ index + 1 } codefix(es), but ${ actions ? actions . length : "none" } found.` ) ;
2206
+ }
2199
2207
}
2200
2208
2201
- const fileChanges = ts . find ( actions [ 0 ] . changes , change => change . fileName === fileName ) ;
2209
+ const fileChanges = ts . find ( actions [ index ] . changes , change => change . fileName === fileName ) ;
2202
2210
if ( ! fileChanges ) {
2203
2211
this . raiseError ( "The CodeFix found doesn't provide any changes in this file." ) ;
2204
2212
}
@@ -3535,8 +3543,8 @@ namespace FourSlashInterface {
3535
3543
this . DocCommentTemplate ( /*expectedText*/ undefined , /*expectedOffset*/ undefined , /*empty*/ true ) ;
3536
3544
}
3537
3545
3538
- public rangeAfterCodeFix ( expectedText : string , errorCode ?: number , includeWhiteSpace ?: boolean ) : void {
3539
- this . state . verifyRangeAfterCodeFix ( expectedText , errorCode , includeWhiteSpace ) ;
3546
+ public rangeAfterCodeFix ( expectedText : string , includeWhiteSpace ?: boolean , errorCode ?: number , index ?: number ) : void {
3547
+ this . state . verifyRangeAfterCodeFix ( expectedText , includeWhiteSpace , errorCode , index ) ;
3540
3548
}
3541
3549
3542
3550
public importFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) : void {
0 commit comments