From a7e7388f15cfeda21d23625f31f3de2f27dc458c Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 24 Aug 2017 14:11:08 -0700 Subject: [PATCH 1/4] Test for action description of code actions, and simplify description for extracting method to file --- src/compiler/diagnosticMessages.json | 2 +- src/harness/fourslash.ts | 47 ++++++++++++++++------- src/services/refactors/extractMethod.ts | 18 ++++----- tests/cases/fourslash/extract-method1.ts | 7 +++- tests/cases/fourslash/extract-method10.ts | 8 +++- 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 +- 18 files changed, 118 insertions(+), 47 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8121f036ceabb..9a3492e5c377a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3696,7 +3696,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 ab33fa87997bc..880a823a1cc7c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2761,20 +2761,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(`2 available refactors both have name ${name} and action ${actionName}`); + } } } @@ -2794,14 +2799,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); @@ -3682,8 +3695,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); } } @@ -4081,8 +4094,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); } } @@ -4295,4 +4308,10 @@ namespace FourSlashInterface { return { classificationType, text, textSpan }; } } + + export interface ApplyRefactorOptions { + refactorName: string; + actionName: string; + actionDescription: string; + } } diff --git a/src/services/refactors/extractMethod.ts b/src/services/refactors/extractMethod.ts index 90e3304169576..dbdd52444fb00 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 "this file"; } else { return "unknown"; 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..b2515aabf291c 100644 --- a/tests/cases/fourslash/extract-method10.ts +++ b/tests/cases/fourslash/extract-method10.ts @@ -1,6 +1,10 @@ /// -//// (x => x)(/*1*/x => x/*2*/)(1); +//// (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 this file", +}); 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..a84816d336caf 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 this file", +}); 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..fd2352154f94b 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 this file", +}); 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..3863a10cdbcbc 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 this file", +}); 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..900d26554e0e3 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 this file", +}); 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..577036d70c946 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 this file", +}); 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..435e56ea4fdf2 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 this file", +}); verify.currentFileContentIs(`function fn(x = newFunction()) { } function newFunction() { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index abb2c38c6b47a..652ed4812c04a 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -159,7 +159,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; @@ -310,7 +310,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; From 613de1563296ff4e4dbdc165141a4dcb6e8be2f0 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 24 Aug 2017 15:14:52 -0700 Subject: [PATCH 2/4] Add unit test file missing from tsconfig.json (only affects gulp) and update tests --- src/harness/tsconfig.json | 1 + tests/baselines/reference/extractMethod/extractMethod1.js | 8 ++++---- .../baselines/reference/extractMethod/extractMethod10.js | 6 +++--- .../baselines/reference/extractMethod/extractMethod11.js | 6 +++--- .../baselines/reference/extractMethod/extractMethod12.js | 2 +- tests/baselines/reference/extractMethod/extractMethod2.js | 8 ++++---- tests/baselines/reference/extractMethod/extractMethod3.js | 8 ++++---- tests/baselines/reference/extractMethod/extractMethod4.js | 8 ++++---- tests/baselines/reference/extractMethod/extractMethod5.js | 8 ++++---- tests/baselines/reference/extractMethod/extractMethod6.js | 8 ++++---- tests/baselines/reference/extractMethod/extractMethod7.js | 8 ++++---- tests/baselines/reference/extractMethod/extractMethod8.js | 8 ++++---- tests/baselines/reference/extractMethod/extractMethod9.js | 8 ++++---- 13 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 9165e59cb0a1a..1469079bcaaf3 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -125,6 +125,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/tests/baselines/reference/extractMethod/extractMethod1.js b/tests/baselines/reference/extractMethod/extractMethod1.js index 60c7e301616e8..1f4fbad80773b 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::this file== 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..e77a303db7e56 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::this file== 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..ca31d3e0eadc8 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::this file== 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..68223edcd86aa 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::this file== 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..17284ee4bc1e3 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::this file== namespace A { function foo() { } diff --git a/tests/baselines/reference/extractMethod/extractMethod4.js b/tests/baselines/reference/extractMethod/extractMethod4.js index 6b9e2eed099d3..ac050ad99e599 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::this file== namespace A { function foo() { } diff --git a/tests/baselines/reference/extractMethod/extractMethod5.js b/tests/baselines/reference/extractMethod/extractMethod5.js index cf63cb2a93214..85629291bcb5c 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::this file== 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..f02bb51b295b9 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::this file== 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..67797723c5eda 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::this file== 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..4fcba7afe6328 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::this file== 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..82e2ec59e4a25 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::this file== namespace A { export interface I { x: number }; namespace B { From 34b46c79d588667a26ee3427bc65fb624dc951db Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 24 Aug 2017 15:15:46 -0700 Subject: [PATCH 3/4] Use the actual number --- src/harness/fourslash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 880a823a1cc7c..3010fc5353345 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2778,7 +2778,7 @@ namespace FourSlash { this.raiseError(`verifyApplicableRefactorAvailableForRange failed - expected a refactor but found none.`); } if (refactors.length > 1) { - this.raiseError(`2 available refactors both have name ${name} and action ${actionName}`); + this.raiseError(`${refactors.length} available refactors both have name ${name} and action ${actionName}`); } } } From fd78f1f2c34bca51a18023112b4e9b4c6c1ad4bd Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 25 Aug 2017 07:56:45 -0700 Subject: [PATCH 4/4] Use "module scope" or "global scope" instead of "this file" --- src/services/refactors/extractMethod.ts | 2 +- tests/baselines/reference/extractMethod/extractMethod1.js | 2 +- tests/baselines/reference/extractMethod/extractMethod10.js | 2 +- tests/baselines/reference/extractMethod/extractMethod11.js | 2 +- tests/baselines/reference/extractMethod/extractMethod2.js | 2 +- tests/baselines/reference/extractMethod/extractMethod3.js | 2 +- tests/baselines/reference/extractMethod/extractMethod4.js | 2 +- tests/baselines/reference/extractMethod/extractMethod5.js | 2 +- tests/baselines/reference/extractMethod/extractMethod6.js | 2 +- tests/baselines/reference/extractMethod/extractMethod7.js | 2 +- tests/baselines/reference/extractMethod/extractMethod8.js | 2 +- tests/baselines/reference/extractMethod/extractMethod9.js | 2 +- tests/cases/fourslash/extract-method10.ts | 3 ++- tests/cases/fourslash/extract-method14.ts | 2 +- tests/cases/fourslash/extract-method15.ts | 2 +- tests/cases/fourslash/extract-method18.ts | 2 +- tests/cases/fourslash/extract-method2.ts | 2 +- tests/cases/fourslash/extract-method24.ts | 2 +- tests/cases/fourslash/extract-method7.ts | 2 +- 19 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/services/refactors/extractMethod.ts b/src/services/refactors/extractMethod.ts index dbdd52444fb00..f32321aff2a17 100644 --- a/src/services/refactors/extractMethod.ts +++ b/src/services/refactors/extractMethod.ts @@ -585,7 +585,7 @@ namespace ts.refactor.extractMethod { : "anonymous class expression"; } else if (isSourceFile(scope)) { - return "this file"; + 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 1f4fbad80773b..10bf2648383bf 100644 --- a/tests/baselines/reference/extractMethod/extractMethod1.js +++ b/tests/baselines/reference/extractMethod/extractMethod1.js @@ -76,7 +76,7 @@ namespace A { return a; } } -==SCOPE::this file== +==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 e77a303db7e56..b2397744680b2 100644 --- a/tests/baselines/reference/extractMethod/extractMethod10.js +++ b/tests/baselines/reference/extractMethod/extractMethod10.js @@ -39,7 +39,7 @@ namespace A { return a1.x + 10; } } -==SCOPE::this file== +==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 ca31d3e0eadc8..21392a07a7a4b 100644 --- a/tests/baselines/reference/extractMethod/extractMethod11.js +++ b/tests/baselines/reference/extractMethod/extractMethod11.js @@ -49,7 +49,7 @@ namespace A { return { __return: a1.x + 10, z }; } } -==SCOPE::this file== +==SCOPE::global scope== namespace A { let y = 1; class C { diff --git a/tests/baselines/reference/extractMethod/extractMethod2.js b/tests/baselines/reference/extractMethod/extractMethod2.js index 68223edcd86aa..3c0d2e7c7b01c 100644 --- a/tests/baselines/reference/extractMethod/extractMethod2.js +++ b/tests/baselines/reference/extractMethod/extractMethod2.js @@ -66,7 +66,7 @@ namespace A { return foo(); } } -==SCOPE::this file== +==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 17284ee4bc1e3..cb28e2755e708 100644 --- a/tests/baselines/reference/extractMethod/extractMethod3.js +++ b/tests/baselines/reference/extractMethod/extractMethod3.js @@ -62,7 +62,7 @@ namespace A { return foo(); } } -==SCOPE::this file== +==SCOPE::global scope== namespace A { function foo() { } diff --git a/tests/baselines/reference/extractMethod/extractMethod4.js b/tests/baselines/reference/extractMethod/extractMethod4.js index ac050ad99e599..07029b2d05063 100644 --- a/tests/baselines/reference/extractMethod/extractMethod4.js +++ b/tests/baselines/reference/extractMethod/extractMethod4.js @@ -70,7 +70,7 @@ namespace A { return foo(); } } -==SCOPE::this file== +==SCOPE::global scope== namespace A { function foo() { } diff --git a/tests/baselines/reference/extractMethod/extractMethod5.js b/tests/baselines/reference/extractMethod/extractMethod5.js index 85629291bcb5c..96a76e426b14f 100644 --- a/tests/baselines/reference/extractMethod/extractMethod5.js +++ b/tests/baselines/reference/extractMethod/extractMethod5.js @@ -76,7 +76,7 @@ namespace A { return a; } } -==SCOPE::this file== +==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 f02bb51b295b9..d1244ac959649 100644 --- a/tests/baselines/reference/extractMethod/extractMethod6.js +++ b/tests/baselines/reference/extractMethod/extractMethod6.js @@ -78,7 +78,7 @@ namespace A { return { __return: foo(), a }; } } -==SCOPE::this file== +==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 67797723c5eda..da400d8b05128 100644 --- a/tests/baselines/reference/extractMethod/extractMethod7.js +++ b/tests/baselines/reference/extractMethod/extractMethod7.js @@ -86,7 +86,7 @@ namespace A { return { __return: C.foo(), a }; } } -==SCOPE::this file== +==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 4fcba7afe6328..d298387b9026e 100644 --- a/tests/baselines/reference/extractMethod/extractMethod8.js +++ b/tests/baselines/reference/extractMethod/extractMethod8.js @@ -50,7 +50,7 @@ namespace A { return 1 + a1 + x; } } -==SCOPE::this file== +==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 82e2ec59e4a25..609e3535d5762 100644 --- a/tests/baselines/reference/extractMethod/extractMethod9.js +++ b/tests/baselines/reference/extractMethod/extractMethod9.js @@ -50,7 +50,7 @@ namespace A { return a1.x + 10; } } -==SCOPE::this file== +==SCOPE::global scope== namespace A { export interface I { x: number }; namespace B { diff --git a/tests/cases/fourslash/extract-method10.ts b/tests/cases/fourslash/extract-method10.ts index b2515aabf291c..ffbee7350e259 100644 --- a/tests/cases/fourslash/extract-method10.ts +++ b/tests/cases/fourslash/extract-method10.ts @@ -1,10 +1,11 @@ /// +//// export {}; // Make this a module //// (x => x)(/*1*/x => x/*2*/)(1); goTo.select('1', '2'); edit.applyRefactor({ refactorName: "Extract Method", actionName: 'scope_0', - actionDescription: "Extract function into this file", + actionDescription: "Extract function into module scope", }); diff --git a/tests/cases/fourslash/extract-method14.ts b/tests/cases/fourslash/extract-method14.ts index a84816d336caf..696bb664bd358 100644 --- a/tests/cases/fourslash/extract-method14.ts +++ b/tests/cases/fourslash/extract-method14.ts @@ -14,7 +14,7 @@ goTo.select('a', 'b'); edit.applyRefactor({ refactorName: "Extract Method", actionName: "scope_1", - actionDescription: "Extract function into this file", + actionDescription: "Extract function into global scope", }); verify.currentFileContentIs(`function foo() { var i = 10; diff --git a/tests/cases/fourslash/extract-method15.ts b/tests/cases/fourslash/extract-method15.ts index fd2352154f94b..93aa357cfee2e 100644 --- a/tests/cases/fourslash/extract-method15.ts +++ b/tests/cases/fourslash/extract-method15.ts @@ -12,7 +12,7 @@ goTo.select('a', 'b'); edit.applyRefactor({ refactorName: "Extract Method", actionName: "scope_1", - actionDescription: "Extract function into this file", + actionDescription: "Extract function into global scope", }); verify.currentFileContentIs(`function foo() { diff --git a/tests/cases/fourslash/extract-method18.ts b/tests/cases/fourslash/extract-method18.ts index 3863a10cdbcbc..d99d14bac73f6 100644 --- a/tests/cases/fourslash/extract-method18.ts +++ b/tests/cases/fourslash/extract-method18.ts @@ -12,7 +12,7 @@ goTo.select('a', 'b') edit.applyRefactor({ refactorName: "Extract Method", actionName: "scope_1", - actionDescription: "Extract function into this file", + actionDescription: "Extract function into global scope", }); verify.currentFileContentIs(`function fn() { const x = { m: 1 }; diff --git a/tests/cases/fourslash/extract-method2.ts b/tests/cases/fourslash/extract-method2.ts index 900d26554e0e3..508836c419922 100644 --- a/tests/cases/fourslash/extract-method2.ts +++ b/tests/cases/fourslash/extract-method2.ts @@ -13,7 +13,7 @@ goTo.select('start', 'end') edit.applyRefactor({ refactorName: "Extract Method", actionName: "scope_2", - actionDescription: "Extract function into this file", + actionDescription: "Extract function into global scope", }); verify.currentFileContentIs( `namespace NS { diff --git a/tests/cases/fourslash/extract-method24.ts b/tests/cases/fourslash/extract-method24.ts index 577036d70c946..615cb2ac4d2f8 100644 --- a/tests/cases/fourslash/extract-method24.ts +++ b/tests/cases/fourslash/extract-method24.ts @@ -10,7 +10,7 @@ goTo.select('a', 'b') edit.applyRefactor({ refactorName: "Extract Method", actionName: "scope_1", - actionDescription: "Extract function into this file", + actionDescription: "Extract function into global scope", }); verify.currentFileContentIs(`function M() { let a = [1,2,3]; diff --git a/tests/cases/fourslash/extract-method7.ts b/tests/cases/fourslash/extract-method7.ts index 435e56ea4fdf2..95c9cbe9897ec 100644 --- a/tests/cases/fourslash/extract-method7.ts +++ b/tests/cases/fourslash/extract-method7.ts @@ -10,7 +10,7 @@ goTo.select('a', 'b'); edit.applyRefactor({ refactorName: "Extract Method", actionName: "scope_0", - actionDescription: "Extract function into this file", + actionDescription: "Extract function into global scope", }); verify.currentFileContentIs(`function fn(x = newFunction()) { }