@@ -2376,7 +2376,7 @@ Actual: ${stringify(fullActual)}`);
2376
2376
*/
2377
2377
public getAndApplyCodeActions ( errorCode ?: number , index ?: number ) {
2378
2378
const fileName = this . activeFile . fileName ;
2379
- this . applyCodeActions ( this . getCodeFixActions ( fileName , errorCode ) , index ) ;
2379
+ this . applyCodeActions ( this . getCodeFixes ( fileName , errorCode ) , index ) ;
2380
2380
}
2381
2381
2382
2382
public applyCodeActionFromCompletion ( markerName : string , options : FourSlashInterface . VerifyCompletionActionOptions ) {
@@ -2429,6 +2429,17 @@ Actual: ${stringify(fullActual)}`);
2429
2429
this . verifyRangeIs ( expectedText , includeWhiteSpace ) ;
2430
2430
}
2431
2431
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
+
2432
2443
/**
2433
2444
* Applies fixes for the errors in fileName and compares the results to
2434
2445
* expectedContents after all fixes have been applied.
@@ -2441,7 +2452,7 @@ Actual: ${stringify(fullActual)}`);
2441
2452
public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string ) {
2442
2453
fileName = fileName ? fileName : this . activeFile . fileName ;
2443
2454
2444
- this . applyCodeActions ( this . getCodeFixActions ( fileName ) ) ;
2455
+ this . applyCodeActions ( this . getCodeFixes ( fileName ) ) ;
2445
2456
2446
2457
const actualContents : string = this . getFileContent ( fileName ) ;
2447
2458
if ( this . removeWhitespace ( actualContents ) !== this . removeWhitespace ( expectedContents ) ) {
@@ -2451,7 +2462,7 @@ Actual: ${stringify(fullActual)}`);
2451
2462
2452
2463
public verifyCodeFix ( options : FourSlashInterface . VerifyCodeFixOptions ) {
2453
2464
const fileName = this . activeFile . fileName ;
2454
- const actions = this . getCodeFixActions ( fileName , options . errorCode ) ;
2465
+ const actions = this . getCodeFixes ( fileName , options . errorCode ) ;
2455
2466
let index = options . index ;
2456
2467
if ( index === undefined ) {
2457
2468
if ( ! ( actions && actions . length === 1 ) ) {
@@ -2490,7 +2501,7 @@ Actual: ${stringify(fullActual)}`);
2490
2501
* Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
2491
2502
* @param fileName Path to file where error should be retrieved from.
2492
2503
*/
2493
- private getCodeFixActions ( fileName : string , errorCode ?: number ) : ts . CodeAction [ ] {
2504
+ private getCodeFixes ( fileName : string , errorCode ?: number ) : ts . CodeFixAction [ ] {
2494
2505
const diagnosticsForCodeFix = this . getDiagnostics ( fileName ) . map ( diagnostic => ( {
2495
2506
start : diagnostic . start ,
2496
2507
length : diagnostic . length ,
@@ -2506,7 +2517,7 @@ Actual: ${stringify(fullActual)}`);
2506
2517
} ) ;
2507
2518
}
2508
2519
2509
- private applyCodeActions ( actions : ts . CodeAction [ ] , index ?: number ) : void {
2520
+ private applyCodeActions ( actions : ReadonlyArray < ts . CodeAction > , index ?: number ) : void {
2510
2521
if ( index === undefined ) {
2511
2522
if ( ! ( actions && actions . length === 1 ) ) {
2512
2523
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)}`);
2519
2530
}
2520
2531
}
2521
2532
2522
- const changes = actions [ index ] . changes ;
2533
+ this . applyChanges ( actions [ index ] . changes ) ;
2534
+ }
2523
2535
2536
+ private applyChanges ( changes : ReadonlyArray < ts . FileTextChanges > ) : void {
2524
2537
for ( const change of changes ) {
2525
2538
this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2526
2539
}
@@ -2532,7 +2545,7 @@ Actual: ${stringify(fullActual)}`);
2532
2545
this . raiseError ( "Exactly one range should be specified in the testfile." ) ;
2533
2546
}
2534
2547
2535
- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName , errorCode ) ;
2548
+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName , errorCode ) ;
2536
2549
2537
2550
if ( codeFixes . length === 0 ) {
2538
2551
if ( expectedTextArray . length !== 0 ) {
@@ -2871,7 +2884,7 @@ Actual: ${stringify(fullActual)}`);
2871
2884
}
2872
2885
2873
2886
public verifyCodeFixAvailable ( negative : boolean , info : FourSlashInterface . VerifyCodeFixAvailableOptions [ ] | undefined ) {
2874
- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName ) ;
2887
+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName ) ;
2875
2888
2876
2889
if ( negative ) {
2877
2890
if ( codeFixes . length ) {
@@ -3038,7 +3051,7 @@ Actual: ${stringify(fullActual)}`);
3038
3051
}
3039
3052
3040
3053
public printAvailableCodeFixes ( ) {
3041
- const codeFixes = this . getCodeFixActions ( this . activeFile . fileName ) ;
3054
+ const codeFixes = this . getCodeFixes ( this . activeFile . fileName ) ;
3042
3055
Harness . IO . log ( stringify ( codeFixes ) ) ;
3043
3056
}
3044
3057
@@ -4149,6 +4162,10 @@ namespace FourSlashInterface {
4149
4162
this . state . verifyRangeAfterCodeFix ( expectedText , includeWhiteSpace , errorCode , index ) ;
4150
4163
}
4151
4164
4165
+ public codeFixAll ( options : VerifyCodeFixAllOptions ) : void {
4166
+ this . state . verifyCodeFixAll ( options ) ;
4167
+ }
4168
+
4152
4169
public fileAfterApplyingRefactorAtMarker ( markerName : string , expectedContent : string , refactorNameToApply : string , actionName : string , formattingOptions ?: ts . FormatCodeSettings ) : void {
4153
4170
this . state . verifyFileAfterApplyingRefactorAtMarker ( markerName , expectedContent , refactorNameToApply , actionName , formattingOptions ) ;
4154
4171
}
@@ -4584,6 +4601,12 @@ namespace FourSlashInterface {
4584
4601
commands ?: ts . CodeActionCommand [ ] ;
4585
4602
}
4586
4603
4604
+ export interface VerifyCodeFixAllOptions {
4605
+ fixId : string ;
4606
+ newFileContent : string ;
4607
+ commands : ReadonlyArray < { } > ;
4608
+ }
4609
+
4587
4610
export interface VerifyRefactorOptions {
4588
4611
name : string ;
4589
4612
actionName : string ;
0 commit comments