From 797c5362a2fc43c130a0d80807b9caaa759cf372 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 16 Jan 2020 10:07:37 -0800 Subject: [PATCH] =?UTF-8?q?Codefix:=20Don=E2=80=99t=20return=20a=20`fixId`?= =?UTF-8?q?=20if=20there=E2=80=99s=20definitely=20nothing=20else=20that=20?= =?UTF-8?q?can=20be=20fixed=20(#35765)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Start fixing fixId * Fix tests * Add comment * Fix unit tests, remove fixAllDescription when unavailable * Add codeFixAllAvailable to fourslash harness --- src/harness/fourslashImpl.ts | 28 ++++++++++++++++--- src/harness/fourslashInterfaceImpl.ts | 4 +++ src/services/codeFixProvider.ts | 28 ++++++++++++++++--- src/services/codefixes/addMissingAwait.ts | 4 ++- src/services/codefixes/addMissingConst.ts | 6 ++-- src/services/codefixes/convertToEs6Module.ts | 2 +- .../codefixes/disableJsDiagnostics.ts | 2 +- src/services/codefixes/fixAddMissingMember.ts | 2 +- .../fixEnableExperimentalDecorators.ts | 2 +- src/services/codefixes/fixEnableJsxFlag.ts | 2 +- .../codefixes/fixInvalidImportSyntax.ts | 4 +-- src/services/codefixes/importFixes.ts | 5 ++-- .../unittests/tsserver/duplicatePackages.ts | 4 +-- .../unittests/tsserver/untitledFiles.ts | 4 +-- .../codeFixAddMissingAwait_initializer4.ts | 11 +------- .../fourslash/codeFixAddMissingMember10.ts | 6 ++-- .../fourslash/codeFixAddMissingMember11.ts | 6 ++-- .../fourslash/codeFixAddMissingMember9.ts | 6 ++-- ...eFixAddMissingMember_generator_function.ts | 6 ++-- ...AddMissingMember_non_generator_function.ts | 6 ++-- .../fourslash/codeFixInferFromUsageCallJS.ts | 6 ++-- tests/cases/fourslash/fourslash.ts | 1 + .../importNameCodeFixWithPrologue.ts | 10 +++---- 23 files changed, 97 insertions(+), 58 deletions(-) diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 972c191f189..eb33a99d6f6 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2544,8 +2544,8 @@ namespace FourSlash { public verifyCodeFixAll({ fixId, fixAllDescription, newFileContent, commands: expectedCommands }: FourSlashInterface.VerifyCodeFixAllOptions): void { const fixWithId = ts.find(this.getCodeFixes(this.activeFile.fileName), a => a.fixId === fixId); - ts.Debug.assert(fixWithId !== undefined, "No available code fix has that group id.", () => - `Expected '${fixId}'. Available action ids: ${ts.mapDefined(this.getCodeFixes(this.activeFile.fileName), a => a.fixId)}`); + ts.Debug.assert(fixWithId !== undefined, "No available code fix has the expected id. Fix All is not available if there is only one potentially fixable diagnostic present.", () => + `Expected '${fixId}'. Available actions:\n${ts.mapDefined(this.getCodeFixes(this.activeFile.fileName), a => `${a.fixName} (${a.fixId || "no fix id"})`).join("\n")}`); ts.Debug.assertEqual(fixWithId!.fixAllDescription, fixAllDescription); const { changes, commands } = this.languageService.getCombinedCodeFix({ type: "file", fileName: this.activeFile.fileName }, fixId, this.formatCodeSettings, ts.emptyOptions); @@ -2681,7 +2681,7 @@ namespace FourSlash { } const range = ts.firstOrUndefined(ranges); - const codeFixes = this.getCodeFixes(fileName, errorCode, preferences).filter(f => f.fixId === ts.codefix.importFixId); + const codeFixes = this.getCodeFixes(fileName, errorCode, preferences).filter(f => f.fixName === ts.codefix.importFixName); if (codeFixes.length === 0) { if (expectedTextArray.length !== 0) { @@ -2717,7 +2717,7 @@ namespace FourSlash { const codeFixes = this.getCodeFixes(marker.fileName, ts.Diagnostics.Cannot_find_name_0.code, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true - }, marker.position).filter(f => f.fixId === ts.codefix.importFixId); + }, marker.position).filter(f => f.fixName === ts.codefix.importFixName); const actualModuleSpecifiers = ts.mapDefined(codeFixes, fix => { return ts.forEach(ts.flatMap(fix.changes, c => c.textChanges), c => { @@ -3044,6 +3044,26 @@ namespace FourSlash { } } + public verifyCodeFixAllAvailable(negative: boolean, fixName: string) { + const availableFixes = this.getCodeFixes(this.activeFile.fileName); + const hasFix = availableFixes.some(fix => fix.fixName === fixName && fix.fixId); + if (negative && hasFix) { + this.raiseError(`Expected not to find a fix with the name '${fixName}', but one exists.`); + } + else if (!negative && !hasFix) { + if (availableFixes.some(fix => fix.fixName === fixName)) { + this.raiseError(`Found a fix with the name '${fixName}', but fix-all is not available.`); + } + + this.raiseError( + `Expected to find a fix with the name '${fixName}', but none exists.` + + availableFixes.length + ? ` Available fixes: ${availableFixes.map(fix => `${fix.fixName} (${fix.fixId ? "with" : "without"} fix-all)`).join(", ")}` + : "" + ); + } + } + public verifyApplicableRefactorAvailableAtMarker(negative: boolean, markerName: string) { const isAvailable = this.getApplicableRefactors(this.getMarkerByName(markerName)).length > 0; if (negative && isAvailable) { diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 91ddf5b6293..04441468a73 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -191,6 +191,10 @@ namespace FourSlashInterface { this.state.verifyCodeFixAvailable(this.negative, options); } + public codeFixAllAvailable(fixName: string) { + this.state.verifyCodeFixAllAvailable(this.negative, fixName); + } + public applicableRefactorAvailableAtMarker(markerName: string) { this.state.verifyApplicableRefactorAvailableAtMarker(this.negative, markerName); } diff --git a/src/services/codeFixProvider.ts b/src/services/codeFixProvider.ts index 1673a63d702..e50477358ed 100644 --- a/src/services/codeFixProvider.ts +++ b/src/services/codeFixProvider.ts @@ -10,7 +10,7 @@ namespace ts.codefix { : getLocaleSpecificMessage(diag); } - export function createCodeFixActionNoFixId(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments) { + export function createCodeFixActionWithoutFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments) { return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, /*fixId*/ undefined, /*fixAllDescription*/ undefined); } @@ -38,8 +38,24 @@ namespace ts.codefix { return arrayFrom(errorCodeToFixes.keys()); } + function removeFixIdIfFixAllUnavailable(registration: CodeFixRegistration, diagnostics: Diagnostic[]) { + const { errorCodes } = registration; + let maybeFixableDiagnostics = 0; + for (const diag of diagnostics) { + if (contains(errorCodes, diag.code)) maybeFixableDiagnostics++; + if (maybeFixableDiagnostics > 1) break; + } + + const fixAllUnavailable = maybeFixableDiagnostics < 2; + return ({ fixId, fixAllDescription, ...action }: CodeFixAction): CodeFixAction => { + return fixAllUnavailable ? action : { ...action, fixId, fixAllDescription }; + }; + } + export function getFixes(context: CodeFixContext): readonly CodeFixAction[] { - return flatMap(errorCodeToFixes.get(String(context.errorCode)) || emptyArray, f => f.getCodeActions(context)); + const diagnostics = getDiagnostics(context); + const registrations = errorCodeToFixes.get(String(context.errorCode)); + return flatMap(registrations, f => map(f.getCodeActions(context), removeFixIdIfFixAllUnavailable(f, diagnostics))); } export function getAllFixes(context: CodeFixAllContext): CombinedCodeActions { @@ -65,11 +81,15 @@ namespace ts.codefix { return createCombinedCodeActions(changes, commands.length === 0 ? undefined : commands); } - export function eachDiagnostic({ program, sourceFile, cancellationToken }: CodeFixAllContext, errorCodes: readonly number[], cb: (diag: DiagnosticWithLocation) => void): void { - for (const diag of program.getSemanticDiagnostics(sourceFile, cancellationToken).concat(computeSuggestionDiagnostics(sourceFile, program, cancellationToken))) { + export function eachDiagnostic(context: CodeFixAllContext, errorCodes: readonly number[], cb: (diag: DiagnosticWithLocation) => void): void { + for (const diag of getDiagnostics(context)) { if (contains(errorCodes, diag.code)) { cb(diag as DiagnosticWithLocation); } } } + + function getDiagnostics({ program, sourceFile, cancellationToken }: CodeFixContextBase) { + return program.getSemanticDiagnostics(sourceFile, cancellationToken).concat(computeSuggestionDiagnostics(sourceFile, program, cancellationToken)); + } } diff --git a/src/services/codefixes/addMissingAwait.ts b/src/services/codefixes/addMissingAwait.ts index 96cf09ed08a..60f5814c396 100644 --- a/src/services/codefixes/addMissingAwait.ts +++ b/src/services/codefixes/addMissingAwait.ts @@ -68,7 +68,9 @@ namespace ts.codefix { makeChange(t, errorCode, sourceFile, checker, expression, fixedDeclarations); } }); - return createCodeFixActionNoFixId( + // No fix-all because it will already be included once with the use site fix, + // and for simplicity the fix-all doesn‘t let the user choose between use-site and declaration-site fixes. + return createCodeFixActionWithoutFixAll( "addMissingAwaitToInitializer", initializerChanges, awaitableInitializers.initializers.length === 1 diff --git a/src/services/codefixes/addMissingConst.ts b/src/services/codefixes/addMissingConst.ts index 37739d01eee..1c819cafe0f 100644 --- a/src/services/codefixes/addMissingConst.ts +++ b/src/services/codefixes/addMissingConst.ts @@ -30,7 +30,7 @@ namespace ts.codefix { if (forInitializer) return applyChange(changeTracker, forInitializer, sourceFile, fixedNodes); const parent = token.parent; - if (isBinaryExpression(parent) && isExpressionStatement(parent.parent)) { + if (isBinaryExpression(parent) && parent.operatorToken.kind === SyntaxKind.EqualsToken && isExpressionStatement(parent.parent)) { return applyChange(changeTracker, token, sourceFile, fixedNodes); } @@ -104,6 +104,8 @@ namespace ts.codefix { return every([expression.left, expression.right], expression => expressionCouldBeVariableDeclaration(expression, checker)); } - return isIdentifier(expression.left) && !checker.getSymbolAtLocation(expression.left); + return expression.operatorToken.kind === SyntaxKind.EqualsToken + && isIdentifier(expression.left) + && !checker.getSymbolAtLocation(expression.left); } } diff --git a/src/services/codefixes/convertToEs6Module.ts b/src/services/codefixes/convertToEs6Module.ts index 70abac28bb6..3880f85bad0 100644 --- a/src/services/codefixes/convertToEs6Module.ts +++ b/src/services/codefixes/convertToEs6Module.ts @@ -13,7 +13,7 @@ namespace ts.codefix { } }); // No support for fix-all since this applies to the whole file at once anyway. - return [createCodeFixActionNoFixId("convertToEs6Module", changes, Diagnostics.Convert_to_ES6_module)]; + return [createCodeFixActionWithoutFixAll("convertToEs6Module", changes, Diagnostics.Convert_to_ES6_module)]; }, }); diff --git a/src/services/codefixes/disableJsDiagnostics.ts b/src/services/codefixes/disableJsDiagnostics.ts index bde8b118264..a4feeaa2dbd 100644 --- a/src/services/codefixes/disableJsDiagnostics.ts +++ b/src/services/codefixes/disableJsDiagnostics.ts @@ -18,7 +18,7 @@ namespace ts.codefix { const fixes: CodeFixAction[] = [ // fixId unnecessary because adding `// @ts-nocheck` even once will ignore every error in the file. - createCodeFixActionNoFixId( + createCodeFixActionWithoutFixAll( fixName, [createFileTextChanges(sourceFile.fileName, [ createTextChange(sourceFile.checkJsDirective diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index c5756553151..5c1e7a655a3 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -255,7 +255,7 @@ namespace ts.codefix { const changes = textChanges.ChangeTracker.with(context, t => t.insertNodeAtClassStart(declSourceFile, classDeclaration, indexSignature)); // No fixId here because code-fix-all currently only works on adding individual named properties. - return createCodeFixActionNoFixId(fixName, changes, [Diagnostics.Add_index_signature_for_property_0, tokenName]); + return createCodeFixActionWithoutFixAll(fixName, changes, [Diagnostics.Add_index_signature_for_property_0, tokenName]); } function getActionForMethodDeclaration( diff --git a/src/services/codefixes/fixEnableExperimentalDecorators.ts b/src/services/codefixes/fixEnableExperimentalDecorators.ts index 8ab1c276910..8c8f6726b43 100644 --- a/src/services/codefixes/fixEnableExperimentalDecorators.ts +++ b/src/services/codefixes/fixEnableExperimentalDecorators.ts @@ -13,7 +13,7 @@ namespace ts.codefix { } const changes = textChanges.ChangeTracker.with(context, changeTracker => doChange(changeTracker, configFile)); - return [createCodeFixActionNoFixId(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)]; + return [createCodeFixActionWithoutFixAll(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)]; }, fixIds: [fixId], getAllCodeActions: context => codeFixAll(context, errorCodes, (changes) => { diff --git a/src/services/codefixes/fixEnableJsxFlag.ts b/src/services/codefixes/fixEnableJsxFlag.ts index 728366392f1..d1085052646 100644 --- a/src/services/codefixes/fixEnableJsxFlag.ts +++ b/src/services/codefixes/fixEnableJsxFlag.ts @@ -14,7 +14,7 @@ namespace ts.codefix { doChange(changeTracker, configFile) ); return [ - createCodeFixActionNoFixId(fixID, changes, Diagnostics.Enable_the_jsx_flag_in_your_configuration_file) + createCodeFixActionWithoutFixAll(fixID, changes, Diagnostics.Enable_the_jsx_flag_in_your_configuration_file) ]; }, fixIds: [fixID], diff --git a/src/services/codefixes/fixInvalidImportSyntax.ts b/src/services/codefixes/fixInvalidImportSyntax.ts index dc37aeff12b..5893a1e5e74 100644 --- a/src/services/codefixes/fixInvalidImportSyntax.ts +++ b/src/services/codefixes/fixInvalidImportSyntax.ts @@ -26,7 +26,7 @@ namespace ts.codefix { function createAction(context: CodeFixContext, sourceFile: SourceFile, node: Node, replacement: Node): CodeFixAction { const changes = textChanges.ChangeTracker.with(context, t => t.replaceNode(sourceFile, node, replacement)); - return createCodeFixActionNoFixId(fixName, changes, [Diagnostics.Replace_import_with_0, changes[0].textChanges[0].newText]); + return createCodeFixActionWithoutFixAll(fixName, changes, [Diagnostics.Replace_import_with_0, changes[0].textChanges[0].newText]); } registerCodeFix({ @@ -89,7 +89,7 @@ namespace ts.codefix { if (isExpression(expr) && !(isNamedDeclaration(expr.parent) && expr.parent.name === expr)) { const sourceFile = context.sourceFile; const changes = textChanges.ChangeTracker.with(context, t => t.replaceNode(sourceFile, expr, createPropertyAccess(expr, "default"), {})); - fixes.push(createCodeFixActionNoFixId(fixName, changes, Diagnostics.Use_synthetic_default_member)); + fixes.push(createCodeFixActionWithoutFixAll(fixName, changes, Diagnostics.Use_synthetic_default_member)); } return fixes; } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index e5e141407cb..557362fb4b8 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -1,6 +1,7 @@ /* @internal */ namespace ts.codefix { - export const importFixId = "fixMissingImport"; + export const importFixName = "import"; + const importFixId = "fixMissingImport"; const errorCodes: readonly number[] = [ Diagnostics.Cannot_find_name_0.code, Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, @@ -542,7 +543,7 @@ namespace ts.codefix { const changes = textChanges.ChangeTracker.with(context, tracker => { diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference); }); - return createCodeFixAction("import", changes, diag, importFixId, Diagnostics.Add_all_missing_imports); + return createCodeFixAction(importFixName, changes, diag, importFixId, Diagnostics.Add_all_missing_imports); } function codeActionForFixWorker(changes: textChanges.ChangeTracker, sourceFile: SourceFile, symbolName: string, fix: ImportFix, quotePreference: QuotePreference): DiagnosticAndArguments { switch (fix.kind) { diff --git a/src/testRunner/unittests/tsserver/duplicatePackages.ts b/src/testRunner/unittests/tsserver/duplicatePackages.ts index 3de23225cd7..c6e4868ba4a 100644 --- a/src/testRunner/unittests/tsserver/duplicatePackages.ts +++ b/src/testRunner/unittests/tsserver/duplicatePackages.ts @@ -35,8 +35,6 @@ namespace ts.projectSystem { { description: `Import 'foo' from module "foo"`, fixName: "import", - fixId: "fixMissingImport", - fixAllDescription: "Add all missing imports", changes: [{ fileName: user.path, textChanges: [{ @@ -46,6 +44,8 @@ namespace ts.projectSystem { }], }], commands: undefined, + fixId: undefined, + fixAllDescription: undefined }, ]); } diff --git a/src/testRunner/unittests/tsserver/untitledFiles.ts b/src/testRunner/unittests/tsserver/untitledFiles.ts index 7f5c36ac6e2..31612d49a14 100644 --- a/src/testRunner/unittests/tsserver/untitledFiles.ts +++ b/src/testRunner/unittests/tsserver/untitledFiles.ts @@ -26,8 +26,6 @@ namespace ts.projectSystem { assert.deepEqual(response, [ { description: "Change spelling to 'foo'", - fixAllDescription: "Fix all detected spelling errors", - fixId: "fixSpelling", fixName: "spelling", changes: [{ fileName: untitledFile, @@ -38,6 +36,8 @@ namespace ts.projectSystem { }], }], commands: undefined, + fixId: undefined, + fixAllDescription: undefined }, ]); }); diff --git a/tests/cases/fourslash/codeFixAddMissingAwait_initializer4.ts b/tests/cases/fourslash/codeFixAddMissingAwait_initializer4.ts index 3106eaeccb6..349370b09e4 100644 --- a/tests/cases/fourslash/codeFixAddMissingAwait_initializer4.ts +++ b/tests/cases/fourslash/codeFixAddMissingAwait_initializer4.ts @@ -16,13 +16,4 @@ verify.codeFix({ }` }); -verify.codeFixAll({ - fixAllDescription: ts.Diagnostics.Fix_all_expressions_possibly_missing_await.message, - fixId: "addMissingAwait", - newFileContent: -`async function fn(a: string, b: Promise) { - const x = await b; - const y = await b; - x + y; -}` -}); +verify.not.codeFixAllAvailable("addMissingAwait"); diff --git a/tests/cases/fourslash/codeFixAddMissingMember10.ts b/tests/cases/fourslash/codeFixAddMissingMember10.ts index 990d86ec49a..3a33d17b117 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember10.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember10.ts @@ -3,9 +3,9 @@ //// class C {} //// const n: number = new C().add(1, 2); -verify.codeFixAll({ - fixId: "addMissingMember", - fixAllDescription: "Add all missing members", +verify.codeFix({ + index: 0, + description: ignoreInterpolations(ts.Diagnostics.Declare_method_0), newFileContent: `class C { add(arg0: number, arg1: number): number { diff --git a/tests/cases/fourslash/codeFixAddMissingMember11.ts b/tests/cases/fourslash/codeFixAddMissingMember11.ts index 6f68502d4c9..c87115e5a6b 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember11.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember11.ts @@ -4,9 +4,9 @@ //// function f(v: number): void { } //// f(new C().add(1, 2)) -verify.codeFixAll({ - fixId: "addMissingMember", - fixAllDescription: "Add all missing members", +verify.codeFix({ + index: 0, + description: ignoreInterpolations(ts.Diagnostics.Declare_method_0), newFileContent: `class C { add(arg0: number, arg1: number): number { diff --git a/tests/cases/fourslash/codeFixAddMissingMember9.ts b/tests/cases/fourslash/codeFixAddMissingMember9.ts index e22e854c2e5..7fa8b47e366 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember9.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember9.ts @@ -8,9 +8,9 @@ //// } ////} -verify.codeFixAll({ - fixId: "addMissingMember", - fixAllDescription: "Add all missing members", +verify.codeFix({ + index: 0, + description: ignoreInterpolations(ts.Diagnostics.Declare_method_0), newFileContent: `class C { z: boolean = true; diff --git a/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts b/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts index ad0bd7b47ca..12adb5b0717 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts @@ -6,9 +6,9 @@ //// } ////} -verify.codeFixAll({ - fixId: "addMissingMember", - fixAllDescription: "Add all missing members", +verify.codeFix({ + index: 0, + description: ignoreInterpolations(ts.Diagnostics.Declare_method_0), newFileContent: `class C { *method() { diff --git a/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts b/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts index c3773bf285c..acb2f4c86c4 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts @@ -6,9 +6,9 @@ //// } ////} -verify.codeFixAll({ - fixId: "addMissingMember", - fixAllDescription: "Add all missing members", +verify.codeFix({ + index: 0, + description: ignoreInterpolations(ts.Diagnostics.Declare_method_0), newFileContent: `class C { method() { diff --git a/tests/cases/fourslash/codeFixInferFromUsageCallJS.ts b/tests/cases/fourslash/codeFixInferFromUsageCallJS.ts index fa7eb5ee671..edb8a0bea5f 100644 --- a/tests/cases/fourslash/codeFixInferFromUsageCallJS.ts +++ b/tests/cases/fourslash/codeFixInferFromUsageCallJS.ts @@ -8,9 +8,9 @@ //// b(); ////} -verify.codeFixAll({ - fixId: "inferFromUsage", - fixAllDescription: "Infer all types from usage", +verify.codeFix({ + index: 0, + description: ignoreInterpolations(ts.Diagnostics.Infer_parameter_types_from_usage), newFileContent: `/** * @param {() => void} b diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 84b770fc394..baeff000912 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -236,6 +236,7 @@ declare namespace FourSlashInterface { commands?: {}[], }); codeFixAvailable(options?: ReadonlyArray | string): void; + codeFixAllAvailable(fixName: string): void; applicableRefactorAvailableAtMarker(markerName: string): void; codeFixDiagnosticsAvailableAtMarkers(markerNames: string[], diagnosticCode?: number): void; applicableRefactorAvailableForRange(): void; diff --git a/tests/cases/fourslash/importNameCodeFixWithPrologue.ts b/tests/cases/fourslash/importNameCodeFixWithPrologue.ts index 383f8b1555e..c71d03c063d 100644 --- a/tests/cases/fourslash/importNameCodeFixWithPrologue.ts +++ b/tests/cases/fourslash/importNameCodeFixWithPrologue.ts @@ -17,9 +17,8 @@ ////export class B extends A { } goTo.file("/b.ts"); -verify.codeFixAll({ - fixId: "fixMissingImport", - fixAllDescription: "Add all missing imports", +verify.codeFix({ + description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1), newFileContent: `"use strict"; @@ -29,9 +28,8 @@ export class B extends A { }`, }); goTo.file("/c.ts"); -verify.codeFixAll({ - fixId: "fixMissingImport", - fixAllDescription: "Add all missing imports", +verify.codeFix({ + description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1), newFileContent: `/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved.