@@ -119,11 +119,13 @@ static bool hasTrivialTrailingClosure(const FuncDecl *FD,
119119}
120120} // end anonymous namespace
121121
122- bool swift::ide::DefaultFilter (ValueDecl *VD, DeclVisibilityKind Kind) {
122+ bool swift::ide::DefaultFilter (ValueDecl *VD, DeclVisibilityKind Kind,
123+ DynamicLookupInfo dynamicLookupInfo) {
123124 return true ;
124125}
125126
126- bool swift::ide::KeyPathFilter (ValueDecl *decl, DeclVisibilityKind) {
127+ bool swift::ide::KeyPathFilter (ValueDecl *decl, DeclVisibilityKind,
128+ DynamicLookupInfo dynamicLookupInfo) {
127129 return isa<TypeDecl>(decl) ||
128130 (isa<VarDecl>(decl) && decl->getDeclContext ()->isTypeContext ());
129131}
@@ -1797,7 +1799,7 @@ void CompletionLookup::foundDecl(ValueDecl *D, DeclVisibilityKind Reason,
17971799 if (D->shouldHideFromEditor ())
17981800 return ;
17991801
1800- if (IsKeyPathExpr && !KeyPathFilter (D, Reason))
1802+ if (IsKeyPathExpr && !KeyPathFilter (D, Reason, dynamicLookupInfo ))
18011803 return ;
18021804
18031805 if (IsSwiftKeyPathExpr && !SwiftKeyPathFilter (D, Reason))
@@ -2693,7 +2695,8 @@ void CompletionLookup::getUnresolvedMemberCompletions(Type T) {
26932695 // type and has the same type (or if the member is a function, then the
26942696 // same result type) as the contextual type.
26952697 FilteredDeclConsumer consumer (*this ,
2696- [=](ValueDecl *VD, DeclVisibilityKind Reason) {
2698+ [=](ValueDecl *VD, DeclVisibilityKind Reason,
2699+ DynamicLookupInfo dynamicLookupInfo) {
26972700 // In optional context, ignore
26982701 // '.init(<some>)', 'init(nilLiteral:)',
26992702 return !isInitializerOnOptional (T, VD);
@@ -3116,3 +3119,32 @@ void CompletionLookup::getStmtLabelCompletions(SourceLoc Loc, bool isContinue) {
31163119 Builder.addTextChunk (name.str ());
31173120 }
31183121}
3122+
3123+ void CompletionLookup::getOptionalBindingCompletions (SourceLoc Loc) {
3124+ ExprType = Type ();
3125+ Kind = LookupKind::ValueInDeclContext;
3126+ NeedLeadingDot = false ;
3127+
3128+ AccessFilteringDeclConsumer AccessFilteringConsumer (CurrDeclContext, *this );
3129+
3130+ // Suggest only 'Optional' type var decls (incl. parameters)
3131+ FilteredDeclConsumer FilteringConsumer (
3132+ AccessFilteringConsumer,
3133+ [&](ValueDecl *VD, DeclVisibilityKind Reason,
3134+ DynamicLookupInfo dynamicLookupInfo) -> bool {
3135+ auto *VarD = dyn_cast<VarDecl>(VD);
3136+ if (!VarD)
3137+ return false ;
3138+
3139+ auto Ty = getTypeOfMember (VD, dynamicLookupInfo);
3140+ return Ty->isOptional ();
3141+ });
3142+
3143+ // FIXME: Currently, it doesn't include top level decls for performance
3144+ // reason. Enabling 'IncludeTopLevel' pulls everything including imported
3145+ // modules. For suggesting top level results, we need a way to filter cached
3146+ // results.
3147+
3148+ lookupVisibleDecls (FilteringConsumer, CurrDeclContext,
3149+ /* IncludeTopLevel=*/ false , Loc);
3150+ }
0 commit comments