Skip to content

Commit ba663f6

Browse files
zardoysandersn
andauthored
Exclude completions of binding pattern variable initializers (#52723)
Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 7205eda commit ba663f6

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Diff for: src/services/completions.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -2745,8 +2745,14 @@ export function getCompletionEntriesFromSymbols(
27452745
}
27462746
// Filter out variables from their own initializers
27472747
// `const a = /* no 'a' here */`
2748-
if (tryCast(closestSymbolDeclaration, isVariableDeclaration) && symbol.valueDeclaration === closestSymbolDeclaration) {
2749-
return false;
2748+
if (closestSymbolDeclaration && tryCast(closestSymbolDeclaration, isVariableDeclaration)) {
2749+
if (symbol.valueDeclaration === closestSymbolDeclaration) {
2750+
return false;
2751+
}
2752+
// const { a } = /* no 'a' here */;
2753+
if (isBindingPattern(closestSymbolDeclaration.name) && closestSymbolDeclaration.name.elements.some(e => e === symbol.valueDeclaration)) {
2754+
return false;
2755+
}
27502756
}
27512757

27522758
// Filter out current and latter parameters from defaults

Diff for: tests/cases/fourslash/completionListWithoutVariableinitializer.ts

+27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
//// const fn = (p = /*7*/) => {}
1010
//// const { g, h = /*8*/ } = { ... }
1111
//// const [ g1, h1 = /*9*/ ] = [ ... ]
12+
//// const { a1 } = a/*10*/;
13+
//// const { a2 } = fn({a: a/*11*/});
14+
//// const [ a3 ] = a/*12*/;
15+
//// const [ a4 ] = fn([a/*13*/]);
1216

1317
verify.completions({
1418
marker: ["1"],
@@ -58,3 +62,26 @@ verify.completions({
5862
marker: ["9"],
5963
includes: ["a", "b", "c", "d", "e", "fn"],
6064
});
65+
66+
verify.completions({
67+
marker: ["10"],
68+
excludes: ["a1"],
69+
isNewIdentifierLocation: true,
70+
});
71+
72+
verify.completions({
73+
marker: ["11"],
74+
excludes: ["a2"],
75+
});
76+
77+
verify.completions({
78+
marker: ["12"],
79+
excludes: ["a3"],
80+
isNewIdentifierLocation: true,
81+
});
82+
83+
verify.completions({
84+
marker: ["13"],
85+
excludes: ["a4"],
86+
isNewIdentifierLocation: true,
87+
});

0 commit comments

Comments
 (0)