@@ -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}
@@ -1799,7 +1801,7 @@ void CompletionLookup::foundDecl(ValueDecl *D, DeclVisibilityKind Reason,
17991801 if (D->shouldHideFromEditor ())
18001802 return ;
18011803
1802- if (IsKeyPathExpr && !KeyPathFilter (D, Reason))
1804+ if (IsKeyPathExpr && !KeyPathFilter (D, Reason, dynamicLookupInfo ))
18031805 return ;
18041806
18051807 if (IsSwiftKeyPathExpr && !SwiftKeyPathFilter (D, Reason))
@@ -2695,7 +2697,8 @@ void CompletionLookup::getUnresolvedMemberCompletions(Type T) {
26952697 // type and has the same type (or if the member is a function, then the
26962698 // same result type) as the contextual type.
26972699 FilteredDeclConsumer consumer (*this ,
2698- [=](ValueDecl *VD, DeclVisibilityKind Reason) {
2700+ [=](ValueDecl *VD, DeclVisibilityKind Reason,
2701+ DynamicLookupInfo dynamicLookupInfo) {
26992702 // In optional context, ignore
27002703 // '.init(<some>)', 'init(nilLiteral:)',
27012704 return !isInitializerOnOptional (T, VD);
@@ -3118,3 +3121,32 @@ void CompletionLookup::getStmtLabelCompletions(SourceLoc Loc, bool isContinue) {
31183121 Builder.addTextChunk (name.str ());
31193122 }
31203123}
3124+
3125+ void CompletionLookup::getOptionalBindingCompletions (SourceLoc Loc) {
3126+ ExprType = Type ();
3127+ Kind = LookupKind::ValueInDeclContext;
3128+ NeedLeadingDot = false ;
3129+
3130+ AccessFilteringDeclConsumer AccessFilteringConsumer (CurrDeclContext, *this );
3131+
3132+ // Suggest only 'Optional' type var decls (incl. parameters)
3133+ FilteredDeclConsumer FilteringConsumer (
3134+ AccessFilteringConsumer,
3135+ [&](ValueDecl *VD, DeclVisibilityKind Reason,
3136+ DynamicLookupInfo dynamicLookupInfo) -> bool {
3137+ auto *VarD = dyn_cast<VarDecl>(VD);
3138+ if (!VarD)
3139+ return false ;
3140+
3141+ auto Ty = getTypeOfMember (VD, dynamicLookupInfo);
3142+ return Ty->isOptional ();
3143+ });
3144+
3145+ // FIXME: Currently, it doesn't include top level decls for performance
3146+ // reason. Enabling 'IncludeTopLevel' pulls everything including imported
3147+ // modules. For suggesting top level results, we need a way to filter cached
3148+ // results.
3149+
3150+ lookupVisibleDecls (FilteringConsumer, CurrDeclContext,
3151+ /* IncludeTopLevel=*/ false , Loc);
3152+ }
0 commit comments