Skip to content

Commit 2cb7e77

Browse files
authoredOct 13, 2022
fix(50416): correctly names disabled export refactors (#50663)
* added test case to try to retrieve duplicate refactor as in #50416. 'verify.refactorAvailable' correctly retrieves nonduplicate refactors... * optional arguments in refactorAvailable return `true` even if there is no single refactor that satisfies both * it still passes :C * Delete fixExtractToInnerFunctionDuplicaton.ts * deleted extra test code * fix 'verify.refactorAvailable' so that tests correctly check for multiple arguments * fixes #50416 * refactor
1 parent 2bcfed0 commit 2cb7e77

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed
 

‎src/harness/fourslashImpl.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
namespace FourSlash {
32
import ArrayOrSingle = FourSlashInterface.ArrayOrSingle;
43

@@ -3481,8 +3480,18 @@ namespace FourSlash {
34813480

34823481
public verifyRefactorAvailable(negative: boolean, triggerReason: ts.RefactorTriggerReason, name: string, actionName?: string, actionDescription?: string) {
34833482
let refactors = this.getApplicableRefactorsAtSelection(triggerReason);
3484-
refactors = refactors.filter(r =>
3485-
r.name === name && (actionName === undefined || r.actions.some(a => a.name === actionName)) && (actionDescription === undefined || r.actions.some(a => a.description === actionDescription)));
3483+
refactors = refactors.filter(r => r.name === name);
3484+
3485+
if (actionName !== undefined) {
3486+
refactors.forEach(r => r.actions = r.actions.filter(a => a.name === actionName));
3487+
}
3488+
3489+
if (actionDescription !== undefined) {
3490+
refactors.forEach(r => r.actions = r.actions.filter(a => a.description === actionDescription));
3491+
}
3492+
3493+
refactors = refactors.filter(r => r.actions.length > 0);
3494+
34863495
const isAvailable = refactors.length > 0;
34873496

34883497
if (negative) {

‎src/services/refactors/extractSymbol.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ namespace ts.refactor.extractSymbol {
6969

7070
let i = 0;
7171
for (const { functionExtraction, constantExtraction } of extractions) {
72-
const description = functionExtraction.description;
7372
if (refactorKindBeginsWith(extractFunctionAction.kind, requestedRefactor)) {
73+
const description = functionExtraction.description;
7474
if (functionExtraction.errors.length === 0) {
7575
// Don't issue refactorings with duplicated names.
7676
// Scopes come back in "innermost first" order, so extractions will
@@ -95,11 +95,11 @@ namespace ts.refactor.extractSymbol {
9595
}
9696

9797
if (refactorKindBeginsWith(extractConstantAction.kind, requestedRefactor)) {
98+
const description = constantExtraction.description;
9899
if (constantExtraction.errors.length === 0) {
99100
// Don't issue refactorings with duplicated names.
100101
// Scopes come back in "innermost first" order, so extractions will
101102
// preferentially go into nearer scopes
102-
const description = constantExtraction.description;
103103
if (!usedConstantNames.has(description)) {
104104
usedConstantNames.set(description, true);
105105
constantActions.push({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
//// function foo(): void { /*x*/console.log('a');/*y*/ }
4+
5+
goTo.select("x","y");
6+
verify.refactorAvailable("Extract Symbol", 'function_scope_0', "Extract to inner function in function 'foo'");
7+
verify.refactorAvailable("Extract Symbol", 'function_scope_1', "Extract to function in global scope");
8+
9+
verify.not.refactorAvailable("Extract Symbol", 'constant_scope_0', "Extract to inner function in function 'foo'");
10+
11+
verify.refactorAvailable("Extract Symbol", 'constant_scope_0', "Extract to constant in enclosing scope");
12+
verify.refactorAvailable("Extract Symbol", 'constant_scope_1', "Extract to constant in global scope");
13+
14+
verify.not.refactorAvailable("Extract Symbol", 'constant_scope_0', "Extract to constant in global scope");

0 commit comments

Comments
 (0)
Please sign in to comment.