Skip to content

Commit 2ec7634

Browse files
committed
Don't filter away private completions if in the same context
Fixes #34405, which was introduced in PR #16953.
1 parent 75301c8 commit 2ec7634

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/services/completions.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,8 +1826,14 @@ namespace ts.Completions {
18261826
if (canGetType) {
18271827
const typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
18281828
if (!typeForObject) return GlobalsSearch.Fail;
1829-
// In a binding pattern, get only known properties. Everywhere else we will get all possible properties.
1830-
typeMembers = typeChecker.getPropertiesOfType(typeForObject).filter((symbol) => !(getDeclarationModifierFlagsFromSymbol(symbol) & ModifierFlags.NonPublicAccessibilityModifier));
1829+
// In a binding pattern, get only known properties (unless in the same scope).
1830+
// Everywhere else we will get all possible properties.
1831+
const containerClass = getContainingClass(objectLikeContainer);
1832+
typeMembers = typeChecker.getPropertiesOfType(typeForObject).filter(symbol =>
1833+
// either public
1834+
!(getDeclarationModifierFlagsFromSymbol(symbol) & ModifierFlags.NonPublicAccessibilityModifier)
1835+
// or we're in it
1836+
|| containerClass && typeForObject.symbol.declarations.indexOf(containerClass) >= 0);
18311837
existingMembers = objectLikeContainer.elements;
18321838
}
18331839
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////class Foo {
4+
//// private xxx1 = 1;
5+
//// protected xxx2 = 2;
6+
//// public xxx3 = 3;
7+
//// foo() {
8+
//// const { /*1*/ } = this;
9+
//// }
10+
////}
11+
////
12+
////const { /*2*/ } = new class {
13+
//// private xxx1 = 1;
14+
//// protected xxx2 = 2;
15+
//// public xxx3 = 3;
16+
////}
17+
18+
verify.completions({ marker: "1", exact: ["xxx1", "xxx2", "xxx3", "foo"] });
19+
verify.completions({ marker: "2", exact: ["xxx3"] });

0 commit comments

Comments
 (0)