@@ -2376,7 +2376,7 @@ Actual: ${stringify(fullActual)}`);
23762376 */
23772377 public getAndApplyCodeActions ( errorCode ?: number , index ?: number ) {
23782378 const fileName = this . activeFile . fileName ;
2379- this . applyCodeActions ( this . getCodeFixActions ( fileName , errorCode ) , index ) ;
2379+ this . applyCodeActions ( this . getCodeFixes ( fileName , errorCode ) , index ) ;
23802380 }
23812381
23822382 public applyCodeActionFromCompletion ( markerName : string , options : FourSlashInterface . VerifyCompletionActionOptions ) {
@@ -2429,6 +2429,17 @@ Actual: ${stringify(fullActual)}`);
24292429 this . verifyRangeIs ( expectedText , includeWhiteSpace ) ;
24302430 }
24312431
2432+ public verifyCodeFixAll ( options : FourSlashInterface . VerifyCodeFixAllOptions ) : void {
2433+ const { fixId, newFileContent } = options ;
2434+ const fixIds = ts . mapDefined ( this . getCodeFixes ( this . activeFile . fileName ) , a => a . fixId ) ;
2435+ ts . Debug . assert ( ts . contains ( fixIds , fixId ) , "No available code fix has that group id." , ( ) => `Expected '${ fixId } '. Available action ids: ${ fixIds } ` ) ;
2436+ const { changes, commands } = this . languageService . getCombinedCodeFix ( { type : "file" , fileName : this . activeFile . fileName } , fixId , this . formatCodeSettings ) ;
2437+ assert . deepEqual ( commands , options . commands ) ;
2438+ assert ( changes . every ( c => c . fileName === this . activeFile . fileName ) , "TODO: support testing codefixes that touch multiple files" ) ;
2439+ this . applyChanges ( changes ) ;
2440+ this . verifyCurrentFileContent ( newFileContent ) ;
2441+ }
2442+
24322443 /**
24332444 * Applies fixes for the errors in fileName and compares the results to
24342445 * expectedContents after all fixes have been applied.
@@ -2441,7 +2452,7 @@ Actual: ${stringify(fullActual)}`);
24412452 public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string ) {
24422453 fileName = fileName ? fileName : this . activeFile . fileName ;
24432454
2444- this . applyCodeActions ( this . getCodeFixActions ( fileName ) ) ;
2455+ this . applyCodeActions ( this . getCodeFixes ( fileName ) ) ;
24452456
24462457 const actualContents : string = this . getFileContent ( fileName ) ;
24472458 if ( this . removeWhitespace ( actualContents ) !== this . removeWhitespace ( expectedContents ) ) {
@@ -2451,7 +2462,7 @@ Actual: ${stringify(fullActual)}`);
24512462
24522463 public verifyCodeFix ( options : FourSlashInterface . VerifyCodeFixOptions ) {
24532464 const fileName = this . activeFile . fileName ;
2454- const actions = this . getCodeFixActions ( fileName , options . errorCode ) ;
2465+ const actions = this . getCodeFixes ( fileName , options . errorCode ) ;
24552466 let index = options . index ;
24562467 if ( index === undefined ) {
24572468 if ( ! ( actions && actions . length === 1 ) ) {
@@ -2490,7 +2501,7 @@ Actual: ${stringify(fullActual)}`);
24902501 * Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
24912502 * @param fileName Path to file where error should be retrieved from.
24922503 */
2493- private getCodeFixActions ( fileName : string , errorCode ?: number ) : ts . CodeAction [ ] {
2504+ private getCodeFixes ( fileName : string , errorCode ?: number ) : ts . CodeFixAction [ ] {
24942505 const diagnosticsForCodeFix = this . getDiagnostics ( fileName ) . map ( diagnostic => ( {
24952506 start : diagnostic . start ,
24962507 length : diagnostic . length ,
@@ -2506,7 +2517,7 @@ Actual: ${stringify(fullActual)}`);
25062517 } ) ;
25072518 }
25082519
2509- private applyCodeActions ( actions : ts . CodeAction [ ] , index ?: number ) : void {
2520+ private applyCodeActions ( actions : ReadonlyArray < ts . CodeAction > , index ?: number ) : void {
25102521 if ( index === undefined ) {
25112522 if ( ! ( actions && actions . length === 1 ) ) {
25122523 this . raiseError ( `Should find exactly one codefix, but ${ actions ? actions . length : "none" } found. ${ actions ? actions . map ( a => `${ Harness . IO . newLine ( ) } "${ a . description } "` ) : "" } ` ) ;
@@ -2519,8 +2530,10 @@ Actual: ${stringify(fullActual)}`);
25192530 }
25202531 }
25212532
2522- const changes = actions [ index ] . changes ;
2533+ this . applyChanges ( actions [ index ] . changes ) ;
2534+ }
25232535
2536+ private applyChanges ( changes : ReadonlyArray < ts . FileTextChanges > ) : void {
25242537 for ( const change of changes ) {
25252538 this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
25262539 }
@@ -2532,7 +2545,7 @@ Actual: ${stringify(fullActual)}`);
25322545 this . raiseError ( "Exactly one range should be specified in the testfile." ) ;
25332546 }
25342547
2535- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName , errorCode ) ;
2548+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName , errorCode ) ;
25362549
25372550 if ( codeFixes . length === 0 ) {
25382551 if ( expectedTextArray . length !== 0 ) {
@@ -2871,7 +2884,7 @@ Actual: ${stringify(fullActual)}`);
28712884 }
28722885
28732886 public verifyCodeFixAvailable ( negative : boolean , info : FourSlashInterface . VerifyCodeFixAvailableOptions [ ] | undefined ) {
2874- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName ) ;
2887+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName ) ;
28752888
28762889 if ( negative ) {
28772890 if ( codeFixes . length ) {
@@ -3038,7 +3051,7 @@ Actual: ${stringify(fullActual)}`);
30383051 }
30393052
30403053 public printAvailableCodeFixes ( ) {
3041- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName ) ;
3054+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName ) ;
30423055 Harness . IO . log ( stringify ( codeFixes ) ) ;
30433056 }
30443057
@@ -4149,6 +4162,10 @@ namespace FourSlashInterface {
41494162 this . state . verifyRangeAfterCodeFix ( expectedText , includeWhiteSpace , errorCode , index ) ;
41504163 }
41514164
4165+ public codeFixAll ( options : VerifyCodeFixAllOptions ) : void {
4166+ this . state . verifyCodeFixAll ( options ) ;
4167+ }
4168+
41524169 public fileAfterApplyingRefactorAtMarker ( markerName : string , expectedContent : string , refactorNameToApply : string , actionName : string , formattingOptions ?: ts . FormatCodeSettings ) : void {
41534170 this . state . verifyFileAfterApplyingRefactorAtMarker ( markerName , expectedContent , refactorNameToApply , actionName , formattingOptions ) ;
41544171 }
@@ -4584,6 +4601,12 @@ namespace FourSlashInterface {
45844601 commands ?: ts . CodeActionCommand [ ] ;
45854602 }
45864603
4604+ export interface VerifyCodeFixAllOptions {
4605+ fixId : string ;
4606+ newFileContent : string ;
4607+ commands : ReadonlyArray < { } > ;
4608+ }
4609+
45874610 export interface VerifyRefactorOptions {
45884611 name : string ;
45894612 actionName : string ;
0 commit comments