@@ -2122,15 +2122,15 @@ namespace FourSlash {
21222122 * Because codefixes are only applied on the working file, it is unsafe
21232123 * to apply this more than once (consider a refactoring across files).
21242124 */
2125- public verifyRangeAfterCodeFix ( expectedText : string , errorCode ?: number , includeWhiteSpace ?: boolean ) {
2125+ public verifyRangeAfterCodeFix ( expectedText : string , includeWhiteSpace ?: boolean , errorCode ?: number , index ?: number ) {
21262126 const ranges = this . getRanges ( ) ;
21272127 if ( ranges . length !== 1 ) {
21282128 this . raiseError ( "Exactly one range should be specified in the testfile." ) ;
21292129 }
21302130
21312131 const fileName = this . activeFile . fileName ;
21322132
2133- this . applyCodeFixActions ( fileName , this . getCodeFixActions ( fileName , errorCode ) ) ;
2133+ this . applyCodeAction ( fileName , this . getCodeFixActions ( fileName , errorCode ) , index ) ;
21342134
21352135 const actualText = this . rangeText ( ranges [ 0 ] ) ;
21362136
@@ -2155,7 +2155,7 @@ namespace FourSlash {
21552155 public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string ) {
21562156 fileName = fileName ? fileName : this . activeFile . fileName ;
21572157
2158- this . applyCodeFixActions ( fileName , this . getCodeFixActions ( fileName ) ) ;
2158+ this . applyCodeAction ( fileName , this . getCodeFixActions ( fileName ) ) ;
21592159
21602160 const actualContents : string = this . getFileContent ( fileName ) ;
21612161 if ( this . removeWhitespace ( actualContents ) !== this . removeWhitespace ( expectedContents ) ) {
@@ -2193,12 +2193,20 @@ namespace FourSlash {
21932193 return actions ;
21942194 }
21952195
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+ }
21992207 }
22002208
2201- const fileChanges = ts . find ( actions [ 0 ] . changes , change => change . fileName === fileName ) ;
2209+ const fileChanges = ts . find ( actions [ index ] . changes , change => change . fileName === fileName ) ;
22022210 if ( ! fileChanges ) {
22032211 this . raiseError ( "The CodeFix found doesn't provide any changes in this file." ) ;
22042212 }
@@ -3535,8 +3543,8 @@ namespace FourSlashInterface {
35353543 this . DocCommentTemplate ( /*expectedText*/ undefined , /*expectedOffset*/ undefined , /*empty*/ true ) ;
35363544 }
35373545
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 ) ;
35403548 }
35413549
35423550 public importFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) : void {
0 commit comments