@@ -2283,7 +2283,7 @@ namespace FourSlash {
2283
2283
*/
2284
2284
public getAndApplyCodeActions ( errorCode ?: number , index ?: number ) {
2285
2285
const fileName = this . activeFile . fileName ;
2286
- this . applyCodeAction ( fileName , this . getCodeFixActions ( fileName , errorCode ) , index ) ;
2286
+ this . applyCodeActions ( this . getCodeFixActions ( fileName , errorCode ) , index ) ;
2287
2287
}
2288
2288
2289
2289
public verifyRangeIs ( expectedText : string , includeWhiteSpace ?: boolean ) {
@@ -2307,9 +2307,6 @@ namespace FourSlash {
2307
2307
* Compares expected text to the text that would be in the sole range
2308
2308
* (ie: [|...|]) in the file after applying the codefix sole codefix
2309
2309
* in the source file.
2310
- *
2311
- * Because codefixes are only applied on the working file, it is unsafe
2312
- * to apply this more than once (consider a refactoring across files).
2313
2310
*/
2314
2311
public verifyRangeAfterCodeFix ( expectedText : string , includeWhiteSpace ?: boolean , errorCode ?: number , index ?: number ) {
2315
2312
this . getAndApplyCodeActions ( errorCode , index ) ;
@@ -2328,7 +2325,7 @@ namespace FourSlash {
2328
2325
public verifyFileAfterCodeFix ( expectedContents : string , fileName ?: string ) {
2329
2326
fileName = fileName ? fileName : this . activeFile . fileName ;
2330
2327
2331
- this . applyCodeAction ( fileName , this . getCodeFixActions ( fileName ) ) ;
2328
+ this . applyCodeActions ( this . getCodeFixActions ( fileName ) ) ;
2332
2329
2333
2330
const actualContents : string = this . getFileContent ( fileName ) ;
2334
2331
if ( this . removeWhitespace ( actualContents ) !== this . removeWhitespace ( expectedContents ) ) {
@@ -2366,7 +2363,7 @@ namespace FourSlash {
2366
2363
return actions ;
2367
2364
}
2368
2365
2369
- private applyCodeAction ( fileName : string , actions : ts . CodeAction [ ] , index ?: number ) : void {
2366
+ private applyCodeActions ( actions : ts . CodeAction [ ] , index ?: number ) : void {
2370
2367
if ( index === undefined ) {
2371
2368
if ( ! ( actions && actions . length === 1 ) ) {
2372
2369
this . raiseError ( `Should find exactly one codefix, but ${ actions ? actions . length : "none" } found.` ) ;
@@ -2379,12 +2376,11 @@ namespace FourSlash {
2379
2376
}
2380
2377
}
2381
2378
2382
- const fileChanges = ts . find ( actions [ index ] . changes , change => change . fileName === fileName ) ;
2383
- if ( ! fileChanges ) {
2384
- this . raiseError ( "The CodeFix found doesn't provide any changes in this file." ) ;
2385
- }
2379
+ const changes = actions [ index ] . changes ;
2386
2380
2387
- this . applyEdits ( fileChanges . fileName , fileChanges . textChanges , /*isFormattingEdit*/ false ) ;
2381
+ for ( const change of changes ) {
2382
+ this . applyEdits ( change . fileName , change . textChanges , /*isFormattingEdit*/ false ) ;
2383
+ }
2388
2384
}
2389
2385
2390
2386
public verifyImportFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) {
@@ -2769,7 +2765,7 @@ namespace FourSlash {
2769
2765
2770
2766
const codeActions = this . languageService . getRefactorCodeActions ( this . activeFile . fileName , formattingOptions , markerPos , refactorNameToApply ) ;
2771
2767
2772
- this . applyCodeAction ( this . activeFile . fileName , codeActions ) ;
2768
+ this . applyCodeActions ( codeActions ) ;
2773
2769
const actualContent = this . getFileContent ( this . activeFile . fileName ) ;
2774
2770
2775
2771
if ( this . normalizeNewlines ( actualContent ) !== this . normalizeNewlines ( expectedContent ) ) {
0 commit comments