From 993704436fecf1af9491e0539613f41e5737d554 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 25 Aug 2017 09:53:28 -0700 Subject: [PATCH] Test for action description of code actions, and simplify description for extracting method to file (#18030) * Test for action description of code actions, and simplify description for extracting method to file * Add unit test file missing from tsconfig.json (only affects gulp) and update tests * Use the actual number * Use "module scope" or "global scope" instead of "this file" --- src/compiler/diagnosticMessages.json | 2 +- src/harness/fourslash.ts | 47 +++++++++++++------ src/harness/tsconfig.json | 1 + src/services/refactors/extractMethod.ts | 18 +++---- .../reference/extractMethod/extractMethod1.js | 8 ++-- .../extractMethod/extractMethod10.js | 6 +-- .../extractMethod/extractMethod11.js | 6 +-- .../extractMethod/extractMethod12.js | 2 +- .../reference/extractMethod/extractMethod2.js | 8 ++-- .../reference/extractMethod/extractMethod3.js | 8 ++-- .../reference/extractMethod/extractMethod4.js | 8 ++-- .../reference/extractMethod/extractMethod5.js | 8 ++-- .../reference/extractMethod/extractMethod6.js | 8 ++-- .../reference/extractMethod/extractMethod7.js | 8 ++-- .../reference/extractMethod/extractMethod8.js | 8 ++-- .../reference/extractMethod/extractMethod9.js | 8 ++-- tests/cases/fourslash/extract-method1.ts | 7 ++- tests/cases/fourslash/extract-method10.ts | 9 +++- tests/cases/fourslash/extract-method13.ts | 12 ++++- tests/cases/fourslash/extract-method14.ts | 6 ++- tests/cases/fourslash/extract-method15.ts | 6 ++- tests/cases/fourslash/extract-method18.ts | 7 ++- tests/cases/fourslash/extract-method19.ts | 9 ++-- tests/cases/fourslash/extract-method2.ts | 7 ++- tests/cases/fourslash/extract-method21.ts | 6 ++- tests/cases/fourslash/extract-method24.ts | 6 ++- tests/cases/fourslash/extract-method25.ts | 6 ++- tests/cases/fourslash/extract-method3.ts | 2 +- tests/cases/fourslash/extract-method5.ts | 6 ++- tests/cases/fourslash/extract-method7.ts | 6 ++- tests/cases/fourslash/fourslash.ts | 4 +- 31 files changed, 163 insertions(+), 90 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 77e7f7e7b6246..974224e39e93b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3688,7 +3688,7 @@ "code": 95003 }, - "Extract function into '{0}'": { + "Extract function into {0}": { "category": "Message", "code": 95004 } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 2b28ecbbfec21..77639dcc0787b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2743,20 +2743,25 @@ namespace FourSlash { }); } - public verifyRefactorAvailable(negative: boolean, name?: string, subName?: string) { + public verifyRefactorAvailable(negative: boolean, name: string, actionName?: string) { const selection = this.getSelection(); let refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, selection) || []; - if (name) { - refactors = refactors.filter(r => r.name === name && (subName === undefined || r.actions.some(a => a.name === subName))); - } + refactors = refactors.filter(r => r.name === name && (actionName === undefined || r.actions.some(a => a.name === actionName))); const isAvailable = refactors.length > 0; - if (negative && isAvailable) { - this.raiseError(`verifyApplicableRefactorAvailableForRange failed - expected no refactor but found some: ${refactors.map(r => r.name).join(", ")}`); + if (negative) { + if (isAvailable) { + this.raiseError(`verifyApplicableRefactorAvailableForRange failed - expected no refactor but found: ${refactors.map(r => r.name).join(", ")}`); + } } - else if (!negative && !isAvailable) { - this.raiseError(`verifyApplicableRefactorAvailableForRange failed - expected a refactor but found none.`); + else { + if (!isAvailable) { + this.raiseError(`verifyApplicableRefactorAvailableForRange failed - expected a refactor but found none.`); + } + if (refactors.length > 1) { + this.raiseError(`${refactors.length} available refactors both have name ${name} and action ${actionName}`); + } } } @@ -2776,14 +2781,22 @@ namespace FourSlash { } } - public applyRefactor(refactorName: string, actionName: string) { + public applyRefactor({ refactorName, actionName, actionDescription }: FourSlashInterface.ApplyRefactorOptions) { const range = this.getSelection(); const refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, range); - const refactor = ts.find(refactors, r => r.name === refactorName); + const refactor = refactors.find(r => r.name === refactorName); if (!refactor) { this.raiseError(`The expected refactor: ${refactorName} is not available at the marker location.`); } + const action = refactor.actions.find(a => a.name === actionName); + if (!action) { + this.raiseError(`The expected action: ${action} is not included in: ${refactor.actions.map(a => a.name)}`); + } + if (action.description !== actionDescription) { + this.raiseError(`Expected action description to be ${JSON.stringify(actionDescription)}, got: ${JSON.stringify(action.description)}`); + } + const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, this.formatCodeSettings, range, refactorName, actionName); for (const edit of editInfo.edits) { this.applyEdits(edit.fileName, edit.textChanges, /*isFormattingEdit*/ false); @@ -3660,8 +3673,8 @@ namespace FourSlashInterface { this.state.verifyApplicableRefactorAvailableForRange(this.negative); } - public refactorAvailable(name?: string, subName?: string) { - this.state.verifyRefactorAvailable(this.negative, name, subName); + public refactorAvailable(name: string, actionName?: string) { + this.state.verifyRefactorAvailable(this.negative, name, actionName); } } @@ -4059,8 +4072,8 @@ namespace FourSlashInterface { this.state.enableFormatting = false; } - public applyRefactor(refactorName: string, actionName: string) { - this.state.applyRefactor(refactorName, actionName); + public applyRefactor(options: ApplyRefactorOptions) { + this.state.applyRefactor(options); } } @@ -4273,4 +4286,10 @@ namespace FourSlashInterface { return { classificationType, text, textSpan }; } } + + export interface ApplyRefactorOptions { + refactorName: string; + actionName: string; + actionDescription: string; + } } diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 66ca2fc3f4837..f8ad5e6992ae3 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -123,6 +123,7 @@ "./unittests/printer.ts", "./unittests/transform.ts", "./unittests/customTransforms.ts", + "./unittests/extractMethods.ts", "./unittests/textChanges.ts", "./unittests/telemetry.ts", "./unittests/programMissingFiles.ts" diff --git a/src/services/refactors/extractMethod.ts b/src/services/refactors/extractMethod.ts index f0f85ee6e8167..ac1c8383efa2a 100644 --- a/src/services/refactors/extractMethod.ts +++ b/src/services/refactors/extractMethod.ts @@ -560,32 +560,32 @@ namespace ts.refactor.extractMethod { return "constructor"; case SyntaxKind.FunctionExpression: return scope.name - ? `function expression ${scope.name.getText()}` + ? `function expression ${scope.name.text}` : "anonymous function expression"; case SyntaxKind.FunctionDeclaration: - return `function ${scope.name.getText()}`; + return `function '${scope.name.text}'`; case SyntaxKind.ArrowFunction: return "arrow function"; case SyntaxKind.MethodDeclaration: - return `method ${scope.name.getText()}`; + return `method '${scope.name.getText()}`; case SyntaxKind.GetAccessor: - return `get ${scope.name.getText()}`; + return `'get ${scope.name.getText()}'`; case SyntaxKind.SetAccessor: - return `set ${scope.name.getText()}`; + return `'set ${scope.name.getText()}'`; } } else if (isModuleBlock(scope)) { - return `namespace ${scope.parent.name.getText()}`; + return `namespace '${scope.parent.name.getText()}'`; } else if (isClassLike(scope)) { return scope.kind === SyntaxKind.ClassDeclaration - ? `class ${scope.name.text}` + ? `class '${scope.name.text}'` : scope.name.text - ? `class expression ${scope.name.text}` + ? `class expression '${scope.name.text}'` : "anonymous class expression"; } else if (isSourceFile(scope)) { - return `file '${scope.fileName}'`; + return scope.externalModuleIndicator ? "module scope" : "global scope"; } else { return "unknown"; diff --git a/tests/baselines/reference/extractMethod/extractMethod1.js b/tests/baselines/reference/extractMethod/extractMethod1.js index 60c7e301616e8..10bf2648383bf 100644 --- a/tests/baselines/reference/extractMethod/extractMethod1.js +++ b/tests/baselines/reference/extractMethod/extractMethod1.js @@ -14,7 +14,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { let x = 1; function foo() { @@ -34,7 +34,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { let x = 1; function foo() { @@ -55,7 +55,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { let x = 1; function foo() { @@ -76,7 +76,7 @@ namespace A { return a; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { let x = 1; function foo() { diff --git a/tests/baselines/reference/extractMethod/extractMethod10.js b/tests/baselines/reference/extractMethod/extractMethod10.js index 02923b7ab50c7..b2397744680b2 100644 --- a/tests/baselines/reference/extractMethod/extractMethod10.js +++ b/tests/baselines/reference/extractMethod/extractMethod10.js @@ -9,7 +9,7 @@ namespace A { } } } -==SCOPE::class C== +==SCOPE::class 'C'== namespace A { export interface I { x: number }; class C { @@ -24,7 +24,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { export interface I { x: number }; class C { @@ -39,7 +39,7 @@ namespace A { return a1.x + 10; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { export interface I { x: number }; class C { diff --git a/tests/baselines/reference/extractMethod/extractMethod11.js b/tests/baselines/reference/extractMethod/extractMethod11.js index 77565e7b0a778..21392a07a7a4b 100644 --- a/tests/baselines/reference/extractMethod/extractMethod11.js +++ b/tests/baselines/reference/extractMethod/extractMethod11.js @@ -11,7 +11,7 @@ namespace A { } } } -==SCOPE::class C== +==SCOPE::class 'C'== namespace A { let y = 1; class C { @@ -30,7 +30,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { let y = 1; class C { @@ -49,7 +49,7 @@ namespace A { return { __return: a1.x + 10, z }; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { let y = 1; class C { diff --git a/tests/baselines/reference/extractMethod/extractMethod12.js b/tests/baselines/reference/extractMethod/extractMethod12.js index 8ff6e130dad2a..7cebab5d3c582 100644 --- a/tests/baselines/reference/extractMethod/extractMethod12.js +++ b/tests/baselines/reference/extractMethod/extractMethod12.js @@ -13,7 +13,7 @@ namespace A { } } } -==SCOPE::class C== +==SCOPE::class 'C'== namespace A { let y = 1; class C { diff --git a/tests/baselines/reference/extractMethod/extractMethod2.js b/tests/baselines/reference/extractMethod/extractMethod2.js index 28c27993d7165..3c0d2e7c7b01c 100644 --- a/tests/baselines/reference/extractMethod/extractMethod2.js +++ b/tests/baselines/reference/extractMethod/extractMethod2.js @@ -12,7 +12,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { let x = 1; function foo() { @@ -30,7 +30,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { let x = 1; function foo() { @@ -48,7 +48,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { let x = 1; function foo() { @@ -66,7 +66,7 @@ namespace A { return foo(); } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { let x = 1; function foo() { diff --git a/tests/baselines/reference/extractMethod/extractMethod3.js b/tests/baselines/reference/extractMethod/extractMethod3.js index e5903ead18199..cb28e2755e708 100644 --- a/tests/baselines/reference/extractMethod/extractMethod3.js +++ b/tests/baselines/reference/extractMethod/extractMethod3.js @@ -11,7 +11,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { function foo() { } @@ -28,7 +28,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { function foo() { } @@ -45,7 +45,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { function foo() { } @@ -62,7 +62,7 @@ namespace A { return foo(); } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { function foo() { } diff --git a/tests/baselines/reference/extractMethod/extractMethod4.js b/tests/baselines/reference/extractMethod/extractMethod4.js index 6b9e2eed099d3..07029b2d05063 100644 --- a/tests/baselines/reference/extractMethod/extractMethod4.js +++ b/tests/baselines/reference/extractMethod/extractMethod4.js @@ -13,7 +13,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { function foo() { } @@ -32,7 +32,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { function foo() { } @@ -51,7 +51,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { function foo() { } @@ -70,7 +70,7 @@ namespace A { return foo(); } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { function foo() { } diff --git a/tests/baselines/reference/extractMethod/extractMethod5.js b/tests/baselines/reference/extractMethod/extractMethod5.js index cf63cb2a93214..96a76e426b14f 100644 --- a/tests/baselines/reference/extractMethod/extractMethod5.js +++ b/tests/baselines/reference/extractMethod/extractMethod5.js @@ -14,7 +14,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { let x = 1; export function foo() { @@ -34,7 +34,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { let x = 1; export function foo() { @@ -55,7 +55,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { let x = 1; export function foo() { @@ -76,7 +76,7 @@ namespace A { return a; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { let x = 1; export function foo() { diff --git a/tests/baselines/reference/extractMethod/extractMethod6.js b/tests/baselines/reference/extractMethod/extractMethod6.js index 99f52e9febbe0..d1244ac959649 100644 --- a/tests/baselines/reference/extractMethod/extractMethod6.js +++ b/tests/baselines/reference/extractMethod/extractMethod6.js @@ -14,7 +14,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { let x = 1; export function foo() { @@ -34,7 +34,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { let x = 1; export function foo() { @@ -56,7 +56,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { let x = 1; export function foo() { @@ -78,7 +78,7 @@ namespace A { return { __return: foo(), a }; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { let x = 1; export function foo() { diff --git a/tests/baselines/reference/extractMethod/extractMethod7.js b/tests/baselines/reference/extractMethod/extractMethod7.js index 09d5edaa2c05d..da400d8b05128 100644 --- a/tests/baselines/reference/extractMethod/extractMethod7.js +++ b/tests/baselines/reference/extractMethod/extractMethod7.js @@ -16,7 +16,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { let x = 1; export namespace C { @@ -38,7 +38,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { let x = 1; export namespace C { @@ -62,7 +62,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { let x = 1; export namespace C { @@ -86,7 +86,7 @@ namespace A { return { __return: C.foo(), a }; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { let x = 1; export namespace C { diff --git a/tests/baselines/reference/extractMethod/extractMethod8.js b/tests/baselines/reference/extractMethod/extractMethod8.js index fe9cf2a92f0fd..d298387b9026e 100644 --- a/tests/baselines/reference/extractMethod/extractMethod8.js +++ b/tests/baselines/reference/extractMethod/extractMethod8.js @@ -8,7 +8,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { let x = 1; namespace B { @@ -22,7 +22,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { let x = 1; namespace B { @@ -36,7 +36,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { let x = 1; namespace B { @@ -50,7 +50,7 @@ namespace A { return 1 + a1 + x; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { let x = 1; namespace B { diff --git a/tests/baselines/reference/extractMethod/extractMethod9.js b/tests/baselines/reference/extractMethod/extractMethod9.js index fcc5dcd23de07..609e3535d5762 100644 --- a/tests/baselines/reference/extractMethod/extractMethod9.js +++ b/tests/baselines/reference/extractMethod/extractMethod9.js @@ -8,7 +8,7 @@ namespace A { } } } -==SCOPE::function a== +==SCOPE::function 'a'== namespace A { export interface I { x: number }; namespace B { @@ -22,7 +22,7 @@ namespace A { } } } -==SCOPE::namespace B== +==SCOPE::namespace 'B'== namespace A { export interface I { x: number }; namespace B { @@ -36,7 +36,7 @@ namespace A { } } } -==SCOPE::namespace A== +==SCOPE::namespace 'A'== namespace A { export interface I { x: number }; namespace B { @@ -50,7 +50,7 @@ namespace A { return a1.x + 10; } } -==SCOPE::file '/a.ts'== +==SCOPE::global scope== namespace A { export interface I { x: number }; namespace B { diff --git a/tests/cases/fourslash/extract-method1.ts b/tests/cases/fourslash/extract-method1.ts index 7f5c2ac2d500a..ff061295c8c6b 100644 --- a/tests/cases/fourslash/extract-method1.ts +++ b/tests/cases/fourslash/extract-method1.ts @@ -13,8 +13,11 @@ //// } goTo.select('start', 'end') -verify.refactorAvailable('Extract Method'); -edit.applyRefactor('Extract Method', "scope_0"); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into class 'Foo'", +}); verify.currentFileContentIs( `class Foo { someMethod(m: number) { diff --git a/tests/cases/fourslash/extract-method10.ts b/tests/cases/fourslash/extract-method10.ts index 1a02bfa00f53e..ffbee7350e259 100644 --- a/tests/cases/fourslash/extract-method10.ts +++ b/tests/cases/fourslash/extract-method10.ts @@ -1,6 +1,11 @@ /// -//// (x => x)(/*1*/x => x/*2*/)(1); +//// export {}; // Make this a module +//// (x => x)(/*1*/x => x/*2*/)(1); goTo.select('1', '2'); -edit.applyRefactor('Extract Method', 'scope_0'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: 'scope_0', + actionDescription: "Extract function into module scope", +}); diff --git a/tests/cases/fourslash/extract-method13.ts b/tests/cases/fourslash/extract-method13.ts index b9b7c0096aabc..14a146a80c509 100644 --- a/tests/cases/fourslash/extract-method13.ts +++ b/tests/cases/fourslash/extract-method13.ts @@ -10,10 +10,18 @@ //// } goTo.select('a', 'b'); -edit.applyRefactor('Extract Method', 'scope_0'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into class 'C'", +}); goTo.select('c', 'd'); -edit.applyRefactor('Extract Method', 'scope_0'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into class 'C'", +}); verify.currentFileContentIs(`class C { static j = C.newFunction_1(); diff --git a/tests/cases/fourslash/extract-method14.ts b/tests/cases/fourslash/extract-method14.ts index c8bab1b3a56d7..696bb664bd358 100644 --- a/tests/cases/fourslash/extract-method14.ts +++ b/tests/cases/fourslash/extract-method14.ts @@ -11,7 +11,11 @@ //// } goTo.select('a', 'b'); -edit.applyRefactor('Extract Method', 'scope_1'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_1", + actionDescription: "Extract function into global scope", +}); verify.currentFileContentIs(`function foo() { var i = 10; var __return: any; diff --git a/tests/cases/fourslash/extract-method15.ts b/tests/cases/fourslash/extract-method15.ts index ef62bd3fd3f74..93aa357cfee2e 100644 --- a/tests/cases/fourslash/extract-method15.ts +++ b/tests/cases/fourslash/extract-method15.ts @@ -9,7 +9,11 @@ //// } goTo.select('a', 'b'); -edit.applyRefactor('Extract Method', 'scope_1'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_1", + actionDescription: "Extract function into global scope", +}); verify.currentFileContentIs(`function foo() { var i = 10; diff --git a/tests/cases/fourslash/extract-method18.ts b/tests/cases/fourslash/extract-method18.ts index 9d87979a1ed1c..d99d14bac73f6 100644 --- a/tests/cases/fourslash/extract-method18.ts +++ b/tests/cases/fourslash/extract-method18.ts @@ -9,8 +9,11 @@ //// } goTo.select('a', 'b') -verify.refactorAvailable('Extract Method'); -edit.applyRefactor('Extract Method', "scope_1"); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_1", + actionDescription: "Extract function into global scope", +}); verify.currentFileContentIs(`function fn() { const x = { m: 1 }; newFunction(x); diff --git a/tests/cases/fourslash/extract-method19.ts b/tests/cases/fourslash/extract-method19.ts index 54f79311cc72b..e4fb3e6e1110e 100644 --- a/tests/cases/fourslash/extract-method19.ts +++ b/tests/cases/fourslash/extract-method19.ts @@ -5,12 +5,15 @@ //// function fn() { //// /*a*/console.log("hi");/*b*/ //// } -//// +//// //// function newFunction() { } goTo.select('a', 'b') -verify.refactorAvailable('Extract Method'); -edit.applyRefactor('Extract Method', "scope_0"); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into function 'fn'", +}); verify.currentFileContentIs(`function fn() { newFunction_1(); diff --git a/tests/cases/fourslash/extract-method2.ts b/tests/cases/fourslash/extract-method2.ts index 0a4f346307b5f..508836c419922 100644 --- a/tests/cases/fourslash/extract-method2.ts +++ b/tests/cases/fourslash/extract-method2.ts @@ -10,8 +10,11 @@ //// } //// } goTo.select('start', 'end') -verify.refactorAvailable('Extract Method'); -edit.applyRefactor('Extract Method', "scope_2"); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_2", + actionDescription: "Extract function into global scope", +}); verify.currentFileContentIs( `namespace NS { class Q { diff --git a/tests/cases/fourslash/extract-method21.ts b/tests/cases/fourslash/extract-method21.ts index 0168daf5fcb02..c32df5b59798e 100644 --- a/tests/cases/fourslash/extract-method21.ts +++ b/tests/cases/fourslash/extract-method21.ts @@ -12,7 +12,11 @@ goTo.select('start', 'end') verify.refactorAvailable('Extract Method'); -edit.applyRefactor('Extract Method', "scope_0"); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into class 'Foo'", +}); verify.currentFileContentIs(`class Foo { static method() { diff --git a/tests/cases/fourslash/extract-method24.ts b/tests/cases/fourslash/extract-method24.ts index 9eebc00316bd6..615cb2ac4d2f8 100644 --- a/tests/cases/fourslash/extract-method24.ts +++ b/tests/cases/fourslash/extract-method24.ts @@ -7,7 +7,11 @@ //// } goTo.select('a', 'b') -edit.applyRefactor('Extract Method', 'scope_1'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_1", + actionDescription: "Extract function into global scope", +}); verify.currentFileContentIs(`function M() { let a = [1,2,3]; let x = 0; diff --git a/tests/cases/fourslash/extract-method25.ts b/tests/cases/fourslash/extract-method25.ts index ac7e7a2300497..8585dd06fd4ea 100644 --- a/tests/cases/fourslash/extract-method25.ts +++ b/tests/cases/fourslash/extract-method25.ts @@ -8,7 +8,11 @@ //// } goTo.select('a', 'b') -edit.applyRefactor('Extract Method', 'scope_0'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into function 'fn'", +}); verify.currentFileContentIs(`function fn() { var q = newFunction() q[0]++ diff --git a/tests/cases/fourslash/extract-method3.ts b/tests/cases/fourslash/extract-method3.ts index af543121eebf2..27a520d0555a4 100644 --- a/tests/cases/fourslash/extract-method3.ts +++ b/tests/cases/fourslash/extract-method3.ts @@ -10,7 +10,7 @@ //// } //// } -// Don't offer to to 'extract method' a single identifier +// Don't offer to 'extract method' a single identifier goTo.marker('a'); verify.not.refactorAvailable('Extract Method'); diff --git a/tests/cases/fourslash/extract-method5.ts b/tests/cases/fourslash/extract-method5.ts index ac09f92cc0520..10294298b085b 100644 --- a/tests/cases/fourslash/extract-method5.ts +++ b/tests/cases/fourslash/extract-method5.ts @@ -9,7 +9,11 @@ //// } goTo.select('start', 'end'); -edit.applyRefactor('Extract Method', 'scope_0'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into function 'f'", +}); verify.currentFileContentIs( `function f() { var x: 1 | 2 | 3 = newFunction(); diff --git a/tests/cases/fourslash/extract-method7.ts b/tests/cases/fourslash/extract-method7.ts index 4c95c6a551d57..95c9cbe9897ec 100644 --- a/tests/cases/fourslash/extract-method7.ts +++ b/tests/cases/fourslash/extract-method7.ts @@ -7,7 +7,11 @@ //// } goTo.select('a', 'b'); -edit.applyRefactor('Extract Method', 'scope_0'); +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into global scope", +}); verify.currentFileContentIs(`function fn(x = newFunction()) { } function newFunction() { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 5175b52df6c9f..be842680e17ff 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -158,7 +158,7 @@ declare namespace FourSlashInterface { codeFixDiagnosticsAvailableAtMarkers(markerNames: string[], diagnosticCode?: number): void; applicableRefactorAvailableForRange(): void; - refactorAvailable(name?: string, subName?: string); + refactorAvailable(name: string, actionName?: string); } class verify extends verifyNegatable { assertHasRanges(ranges: Range[]): void; @@ -309,7 +309,7 @@ declare namespace FourSlashInterface { enableFormatting(): void; disableFormatting(): void; - applyRefactor(refactorName: string, actionName: string): void; + applyRefactor(options: { refactorName: string, actionName: string, actionDescription: string }): void; } class debug { printCurrentParameterHelp(): void;