@@ -2371,7 +2371,7 @@ Actual: ${stringify(fullActual)}`);
2371
2371
*/
2372
2372
public getAndApplyCodeActions ( errorCode ?: number , index ?: number ) {
2373
2373
const fileName = this . activeFile . fileName ;
2374
- this . applyCodeActions ( this . getCodeFixActions ( fileName , errorCode ) , index ) ;
2374
+ this . applyCodeActions ( this . getCodeFixes ( fileName , errorCode ) , index ) ;
2375
2375
}
2376
2376
2377
2377
public applyCodeActionFromCompletion ( markerName : string , options : FourSlashInterface . VerifyCompletionActionOptions ) {
@@ -2424,6 +2424,16 @@ Actual: ${stringify(fullActual)}`);
2424
2424
this . verifyRangeIs ( expectedText , includeWhiteSpace ) ;
2425
2425
}
2426
2426
2427
+ public verifyCodeFixAll ( options : FourSlashInterface . VerifyCodeFixAllOptions ) : void {
2428
+ const { groupId, newFileContent } = options ;
2429
+ const groupIds = ts . mapDefined ( this . getCodeFixes ( this . activeFile . fileName ) , a => a . groupId ) ;
2430
+ ts . Debug . assert ( ts . contains ( groupIds , groupId ) , "No available code fix has that group id." , ( ) => `Expected '${ groupId } '. Available group ids: ${ groupIds } ` ) ;
2431
+ const { changes, commands } = this . languageService . getCombinedCodeFix ( this . activeFile . fileName , groupId , this . formatCodeSettings ) ;
2432
+ assert . deepEqual ( commands , options . commands ) ;
2433
+ this . applyChanges ( changes ) ;
2434
+ this . verifyCurrentFileContent ( newFileContent ) ;
2435
+ }
2436
+
2427
2437
/**
2428
2438
* Applies fixes for the errors in fileName and compares the results to
2429
2439
* expectedContents after all fixes have been applied.
@@ -2436,7 +2446,7 @@ Actual: ${stringify(fullActual)}`);
2436
2446
public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string ) {
2437
2447
fileName = fileName ? fileName : this . activeFile . fileName ;
2438
2448
2439
- this . applyCodeActions ( this . getCodeFixActions ( fileName ) ) ;
2449
+ this . applyCodeActions ( this . getCodeFixes ( fileName ) ) ;
2440
2450
2441
2451
const actualContents : string = this . getFileContent ( fileName ) ;
2442
2452
if ( this . removeWhitespace ( actualContents ) !== this . removeWhitespace ( expectedContents ) ) {
@@ -2446,7 +2456,7 @@ Actual: ${stringify(fullActual)}`);
2446
2456
2447
2457
public verifyCodeFix ( options : FourSlashInterface . VerifyCodeFixOptions ) {
2448
2458
const fileName = this . activeFile . fileName ;
2449
- const actions = this . getCodeFixActions ( fileName , options . errorCode ) ;
2459
+ const actions = this . getCodeFixes ( fileName , options . errorCode ) ;
2450
2460
let index = options . index ;
2451
2461
if ( index === undefined ) {
2452
2462
if ( ! ( actions && actions . length === 1 ) ) {
@@ -2472,8 +2482,8 @@ Actual: ${stringify(fullActual)}`);
2472
2482
}
2473
2483
2474
2484
private verifyNewContent ( options : FourSlashInterface . NewContentOptions ) {
2475
- if ( options . newFileContent ) {
2476
- assert ( ! options . newRangeContent ) ;
2485
+ if ( options . newFileContent !== undefined ) {
2486
+ assert ( options . newRangeContent === undefined ) ;
2477
2487
this . verifyCurrentFileContent ( options . newFileContent ) ;
2478
2488
}
2479
2489
else {
@@ -2485,7 +2495,7 @@ Actual: ${stringify(fullActual)}`);
2485
2495
* Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
2486
2496
* @param fileName Path to file where error should be retrieved from.
2487
2497
*/
2488
- private getCodeFixActions ( fileName : string , errorCode ?: number ) : ts . CodeAction [ ] {
2498
+ private getCodeFixes ( fileName : string , errorCode ?: number ) : ts . CodeFix [ ] {
2489
2499
const diagnosticsForCodeFix = this . getDiagnostics ( fileName ) . map ( diagnostic => ( {
2490
2500
start : diagnostic . start ,
2491
2501
length : diagnostic . length ,
@@ -2501,7 +2511,7 @@ Actual: ${stringify(fullActual)}`);
2501
2511
} ) ;
2502
2512
}
2503
2513
2504
- private applyCodeActions ( actions : ts . CodeAction [ ] , index ?: number ) : void {
2514
+ private applyCodeActions ( actions : ReadonlyArray < ts . CodeAction > , index ?: number ) : void {
2505
2515
if ( index === undefined ) {
2506
2516
if ( ! ( actions && actions . length === 1 ) ) {
2507
2517
this . raiseError ( `Should find exactly one codefix, but ${ actions ? actions . length : "none" } found. ${ actions ? actions . map ( a => `${ Harness . IO . newLine ( ) } "${ a . description } "` ) : "" } ` ) ;
@@ -2514,8 +2524,10 @@ Actual: ${stringify(fullActual)}`);
2514
2524
}
2515
2525
}
2516
2526
2517
- const changes = actions [ index ] . changes ;
2527
+ this . applyChanges ( actions [ index ] . changes ) ;
2528
+ }
2518
2529
2530
+ private applyChanges ( changes : ReadonlyArray < ts . FileTextChanges > ) : void {
2519
2531
for ( const change of changes ) {
2520
2532
this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2521
2533
}
@@ -2527,7 +2539,7 @@ Actual: ${stringify(fullActual)}`);
2527
2539
this . raiseError ( "At least one range should be specified in the testfile." ) ;
2528
2540
}
2529
2541
2530
- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName , errorCode ) ;
2542
+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName , errorCode ) ;
2531
2543
2532
2544
if ( codeFixes . length === 0 ) {
2533
2545
if ( expectedTextArray . length !== 0 ) {
@@ -2866,7 +2878,7 @@ Actual: ${stringify(fullActual)}`);
2866
2878
}
2867
2879
2868
2880
public verifyCodeFixAvailable ( negative : boolean , info : FourSlashInterface . VerifyCodeFixAvailableOptions [ ] | undefined ) {
2869
- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName ) ;
2881
+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName ) ;
2870
2882
2871
2883
if ( negative ) {
2872
2884
if ( codeFixes . length ) {
@@ -3033,7 +3045,7 @@ Actual: ${stringify(fullActual)}`);
3033
3045
}
3034
3046
3035
3047
public printAvailableCodeFixes ( ) {
3036
- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName ) ;
3048
+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName ) ;
3037
3049
Harness . IO . log ( stringify ( codeFixes ) ) ;
3038
3050
}
3039
3051
@@ -4143,6 +4155,10 @@ namespace FourSlashInterface {
4143
4155
this . state . verifyRangeAfterCodeFix ( expectedText , includeWhiteSpace , errorCode , index ) ;
4144
4156
}
4145
4157
4158
+ public codeFixAll ( options : VerifyCodeFixAllOptions ) : void {
4159
+ this . state . verifyCodeFixAll ( options ) ;
4160
+ }
4161
+
4146
4162
public fileAfterApplyingRefactorAtMarker ( markerName : string , expectedContent : string , refactorNameToApply : string , actionName : string , formattingOptions ?: ts . FormatCodeSettings ) : void {
4147
4163
this . state . verifyFileAfterApplyingRefactorAtMarker ( markerName , expectedContent , refactorNameToApply , actionName , formattingOptions ) ;
4148
4164
}
@@ -4578,6 +4594,12 @@ namespace FourSlashInterface {
4578
4594
commands ?: ts . CodeActionCommand [ ] ;
4579
4595
}
4580
4596
4597
+ export interface VerifyCodeFixAllOptions {
4598
+ groupId : string ;
4599
+ newFileContent : string ;
4600
+ commands : ReadonlyArray < { } > ;
4601
+ }
4602
+
4581
4603
export interface VerifyRefactorOptions {
4582
4604
name : string ;
4583
4605
actionName : string ;
0 commit comments