Skip to content

Don't filter away private completions if in the same context #34822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1826,8 +1826,14 @@ namespace ts.Completions {
if (canGetType) {
const typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
if (!typeForObject) return GlobalsSearch.Fail;
// In a binding pattern, get only known properties. Everywhere else we will get all possible properties.
typeMembers = typeChecker.getPropertiesOfType(typeForObject).filter((symbol) => !(getDeclarationModifierFlagsFromSymbol(symbol) & ModifierFlags.NonPublicAccessibilityModifier));
// In a binding pattern, get only known properties (unless in the same scope).
// Everywhere else we will get all possible properties.
const containerClass = getContainingClass(objectLikeContainer);
typeMembers = typeChecker.getPropertiesOfType(typeForObject).filter(symbol =>
// either public
!(getDeclarationModifierFlagsFromSymbol(symbol) & ModifierFlags.NonPublicAccessibilityModifier)
// or we're in it
|| containerClass && contains(typeForObject.symbol.declarations, containerClass));
existingMembers = objectLikeContainer.elements;
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/cases/fourslash/completionListInObjectBindingPattern15.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference path="fourslash.ts"/>

////class Foo {
//// private xxx1 = 1;
//// protected xxx2 = 2;
//// public xxx3 = 3;
//// private static xxx4 = 4;
//// protected static xxx5 = 5;
//// public static xxx6 = 6;
//// foo() {
//// const { /*1*/ } = this;
//// const { /*2*/ } = Foo;
//// }
////}
////
////const { /*3*/ } = new Foo();
////const { /*4*/ } = Foo;

verify.completions({ marker: "1", exact: ["xxx1", "xxx2", "xxx3", "foo"] });
verify.completions({ marker: "2", exact: ["prototype", "xxx4", "xxx5", "xxx6"] });
verify.completions({ marker: "3", exact: ["xxx3", "foo"] });
verify.completions({ marker: "4", exact: ["prototype", "xxx6"] });