@@ -2337,6 +2337,39 @@ namespace FourSlash {
23372337 }
23382338 }
23392339
2340+ public verifyCodeFix ( options : FourSlashInterface . VerifyCodeFixOptions ) {
2341+ const fileName = this . activeFile . fileName ;
2342+ const actions = this . getCodeFixActions ( fileName , options . errorCode ) ;
2343+ let index = options . index ;
2344+ if ( index === undefined ) {
2345+ if ( ! ( actions && actions . length === 1 ) ) {
2346+ this . raiseError ( `Should find exactly one codefix, but ${ actions ? actions . length : "none" } found. ${ actions ? actions . map ( a => `${ Harness . IO . newLine ( ) } "${ a . description } "` ) : "" } ` ) ;
2347+ }
2348+ index = 0 ;
2349+ }
2350+ else {
2351+ if ( ! ( actions && actions . length >= index + 1 ) ) {
2352+ this . raiseError ( `Should find at least ${ index + 1 } codefix(es), but ${ actions ? actions . length : "none" } found.` ) ;
2353+ }
2354+ }
2355+
2356+ const action = actions [ index ] ;
2357+
2358+ assert . equal ( action . description , options . description ) ;
2359+
2360+ for ( const change of action . changes ) {
2361+ this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2362+ }
2363+
2364+ if ( options . newFileContent ) {
2365+ assert ( ! options . newRangeContent ) ;
2366+ this . verifyCurrentFileContent ( options . newFileContent ) ;
2367+ }
2368+ else {
2369+ this . verifyRangeIs ( options . newRangeContent , /*includeWhitespace*/ true ) ;
2370+ }
2371+ }
2372+
23402373 /**
23412374 * Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
23422375 * @param fileName Path to file where error should be retrieved from.
@@ -3716,6 +3749,10 @@ namespace FourSlashInterface {
37163749 this . state . verifySpanOfEnclosingComment ( this . negative , onlyMultiLineDiverges ) ;
37173750 }
37183751
3752+ public codeFix ( options : FourSlashInterface . VerifyCodeFixOptions ) {
3753+ this . state . verifyCodeFix ( options ) ;
3754+ }
3755+
37193756 public codeFixAvailable ( ) {
37203757 this . state . verifyCodeFixAvailable ( this . negative ) ;
37213758 }
@@ -4359,4 +4396,13 @@ namespace FourSlashInterface {
43594396 export interface CompletionsAtOptions {
43604397 isNewIdentifierLocation ?: boolean ;
43614398 }
4399+
4400+ export interface VerifyCodeFixOptions {
4401+ description : string ;
4402+ // One of these should be defined.
4403+ newFileContent ?: string ;
4404+ newRangeContent ?: string ;
4405+ errorCode ?: number ;
4406+ index ?: number ;
4407+ }
43624408}
0 commit comments