Skip to content

Commit f19c312

Browse files
author
Arthur Ozga
committed
Apply codefixes across files
1 parent c9f5a46 commit f19c312

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/harness/fourslash.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ namespace FourSlash {
22832283
*/
22842284
public getAndApplyCodeActions(errorCode?: number, index?: number) {
22852285
const fileName = this.activeFile.fileName;
2286-
this.applyCodeAction(fileName, this.getCodeFixActions(fileName, errorCode), index);
2286+
this.applyCodeActions(this.getCodeFixActions(fileName, errorCode), index);
22872287
}
22882288

22892289
public verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) {
@@ -2307,9 +2307,6 @@ namespace FourSlash {
23072307
* Compares expected text to the text that would be in the sole range
23082308
* (ie: [|...|]) in the file after applying the codefix sole codefix
23092309
* 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).
23132310
*/
23142311
public verifyRangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number) {
23152312
this.getAndApplyCodeActions(errorCode, index);
@@ -2328,7 +2325,7 @@ namespace FourSlash {
23282325
public verifyFileAfterCodeFix(expectedContents: string, fileName?: string) {
23292326
fileName = fileName ? fileName : this.activeFile.fileName;
23302327

2331-
this.applyCodeAction(fileName, this.getCodeFixActions(fileName));
2328+
this.applyCodeActions(this.getCodeFixActions(fileName));
23322329

23332330
const actualContents: string = this.getFileContent(fileName);
23342331
if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) {
@@ -2366,7 +2363,7 @@ namespace FourSlash {
23662363
return actions;
23672364
}
23682365

2369-
private applyCodeAction(fileName: string, actions: ts.CodeAction[], index?: number): void {
2366+
private applyCodeActions(actions: ts.CodeAction[], index?: number): void {
23702367
if (index === undefined) {
23712368
if (!(actions && actions.length === 1)) {
23722369
this.raiseError(`Should find exactly one codefix, but ${actions ? actions.length : "none"} found.`);
@@ -2379,12 +2376,11 @@ namespace FourSlash {
23792376
}
23802377
}
23812378

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;
23862380

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+
}
23882384
}
23892385

23902386
public verifyImportFixAtPosition(expectedTextArray: string[], errorCode?: number) {
@@ -2769,7 +2765,7 @@ namespace FourSlash {
27692765

27702766
const codeActions = this.languageService.getRefactorCodeActions(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply);
27712767

2772-
this.applyCodeAction(this.activeFile.fileName, codeActions);
2768+
this.applyCodeActions(codeActions);
27732769
const actualContent = this.getFileContent(this.activeFile.fileName);
27742770

27752771
if (this.normalizeNewlines(actualContent) !== this.normalizeNewlines(expectedContent)) {

0 commit comments

Comments
 (0)