mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
Remove 'verify.fileAfterCodeFix', use 'verify.codeFix' (#28110)
This commit is contained in:
@@ -2422,7 +2422,20 @@ Actual: ${stringify(fullActual)}`);
|
||||
*/
|
||||
public getAndApplyCodeActions(errorCode?: number, index?: number) {
|
||||
const fileName = this.activeFile.fileName;
|
||||
this.applyCodeActions(this.getCodeFixes(fileName, errorCode), index);
|
||||
const fixes = this.getCodeFixes(fileName, errorCode);
|
||||
if (index === undefined) {
|
||||
if (!(fixes && fixes.length === 1)) {
|
||||
this.raiseError(`Should find exactly one codefix, but ${fixes ? fixes.length : "none"} found. ${fixes ? fixes.map(a => `${Harness.IO.newLine()} "${a.description}"`) : ""}`);
|
||||
}
|
||||
index = 0;
|
||||
}
|
||||
else {
|
||||
if (!(fixes && fixes.length >= index + 1)) {
|
||||
this.raiseError(`Should find at least ${index + 1} codefix(es), but ${fixes ? fixes.length : "none"} found.`);
|
||||
}
|
||||
}
|
||||
|
||||
this.applyChanges(fixes[index].changes);
|
||||
}
|
||||
|
||||
public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) {
|
||||
@@ -2433,12 +2446,12 @@ Actual: ${stringify(fullActual)}`);
|
||||
if (codeActions.length !== 1) {
|
||||
this.raiseError(`Expected one code action, got ${codeActions.length}`);
|
||||
}
|
||||
const codeAction = ts.first(codeActions);
|
||||
|
||||
if (codeActions[0].description !== options.description) {
|
||||
if (codeAction.description !== options.description) {
|
||||
this.raiseError(`Expected description to be:\n${options.description}\ngot:\n${codeActions[0].description}`);
|
||||
}
|
||||
|
||||
this.applyCodeActions(codeActions);
|
||||
this.applyChanges(codeAction.changes);
|
||||
|
||||
this.verifyNewContentAfterChange(options, ts.flatMap(codeActions, a => a.changes.map(c => c.fileName)));
|
||||
}
|
||||
@@ -2483,26 +2496,6 @@ Actual: ${stringify(fullActual)}`);
|
||||
this.verifyNewContent({ newFileContent }, changes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies fixes for the errors in fileName and compares the results to
|
||||
* expectedContents after all fixes have been applied.
|
||||
*
|
||||
* Note: applying one codefix may generate another (eg: remove duplicate implements
|
||||
* may generate an extends -> interface conversion fix).
|
||||
* @param expectedContents The contents of the file after the fixes are applied.
|
||||
* @param fileName The file to check. If not supplied, the current open file is used.
|
||||
*/
|
||||
public verifyFileAfterCodeFix(expectedContents: string, fileName?: string, index?: number) {
|
||||
fileName = fileName ? fileName : this.activeFile.fileName;
|
||||
|
||||
this.applyCodeActions(this.getCodeFixes(fileName), index);
|
||||
|
||||
const actualContents: string = this.getFileContent(fileName);
|
||||
if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) {
|
||||
this.raiseError(`Actual text doesn't match expected text. Actual:\n${actualContents}\n\nExpected:\n${expectedContents}`);
|
||||
}
|
||||
}
|
||||
|
||||
public verifyCodeFix(options: FourSlashInterface.VerifyCodeFixOptions) {
|
||||
const fileName = this.activeFile.fileName;
|
||||
const actions = this.getCodeFixes(fileName, options.errorCode, options.preferences);
|
||||
@@ -2607,22 +2600,6 @@ Actual: ${stringify(fullActual)}`);
|
||||
});
|
||||
}
|
||||
|
||||
private applyCodeActions(actions: ReadonlyArray<ts.CodeAction>, index?: number): void {
|
||||
if (index === undefined) {
|
||||
if (!(actions && actions.length === 1)) {
|
||||
this.raiseError(`Should find exactly one codefix, but ${actions ? actions.length : "none"} found. ${actions ? actions.map(a => `${Harness.IO.newLine()} "${a.description}"`) : ""}`);
|
||||
}
|
||||
index = 0;
|
||||
}
|
||||
else {
|
||||
if (!(actions && actions.length >= index + 1)) {
|
||||
this.raiseError(`Should find at least ${index + 1} codefix(es), but ${actions ? actions.length : "none"} found.`);
|
||||
}
|
||||
}
|
||||
|
||||
this.applyChanges(actions[index].changes);
|
||||
}
|
||||
|
||||
private applyChanges(changes: ReadonlyArray<ts.FileTextChanges>): void {
|
||||
for (const change of changes) {
|
||||
this.applyEdits(change.fileName, change.textChanges, /*isFormattingEdit*/ false);
|
||||
@@ -4364,10 +4341,6 @@ namespace FourSlashInterface {
|
||||
this.state.verifyRangeAfterCodeFix(expectedText, includeWhiteSpace, errorCode, index);
|
||||
}
|
||||
|
||||
public fileAfterCodeFix(expectedContents: string, fileName?: string, index?: number) {
|
||||
this.state.verifyFileAfterCodeFix(expectedContents, fileName, index);
|
||||
}
|
||||
|
||||
public codeFixAll(options: VerifyCodeFixAllOptions): void {
|
||||
this.state.verifyCodeFixAll(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user