Skip to content

Commit d6bd3ac

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

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-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 && contains(typeForObject.symbol.declarations, containerClass));
18311837
existingMembers = objectLikeContainer.elements;
18321838
}
18331839
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////class Foo {
4+
//// private xxx1 = 1;
5+
//// protected xxx2 = 2;
6+
//// public xxx3 = 3;
7+
//// private static xxx4 = 4;
8+
//// protected static xxx5 = 5;
9+
//// public static xxx6 = 6;
10+
//// foo() {
11+
//// const { /*1*/ } = this;
12+
//// const { /*2*/ } = Foo;
13+
//// }
14+
////}
15+
////
16+
////const { /*3*/ } = new Foo();
17+
////const { /*4*/ } = Foo;
18+
19+
verify.completions({ marker: "1", exact: ["xxx1", "xxx2", "xxx3", "foo"] });
20+
verify.completions({ marker: "2", exact: ["prototype", "xxx4", "xxx5", "xxx6"] });
21+
verify.completions({ marker: "3", exact: ["xxx3", "foo"] });
22+
verify.completions({ marker: "4", exact: ["prototype", "xxx6"] });

0 commit comments

Comments
 (0)