@@ -3887,6 +3887,53 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3887
3887
3888
3888
using FunctionParams = ArrayRef<AnyFunctionType::Param>;
3889
3889
3890
+ static void collectPossibleParamListByQualifiedLookup (
3891
+ DeclContext &DC, Type baseTy, DeclBaseName name,
3892
+ SmallVectorImpl<FunctionParams> &candidates) {
3893
+
3894
+ SmallVector<ValueDecl *, 2 > decls;
3895
+ auto resolver = DC.getASTContext ().getLazyResolver ();
3896
+ if (!DC.lookupQualified (baseTy, name, NL_QualifiedDefault, resolver, decls))
3897
+ return ;
3898
+
3899
+ for (auto *VD : decls) {
3900
+ if (!isa<AbstractFunctionDecl>(VD) ||
3901
+ shouldHideDeclFromCompletionResults (VD))
3902
+ continue ;
3903
+ resolver->resolveDeclSignature (VD);
3904
+ if (!VD->hasInterfaceType ())
3905
+ continue ;
3906
+ Type declaredMemberType = VD->getInterfaceType ();
3907
+ if (auto *AFD = dyn_cast<AbstractFunctionDecl>(VD))
3908
+ declaredMemberType = AFD->getMethodInterfaceType ();
3909
+
3910
+ auto fnType =
3911
+ baseTy->getTypeOfMember (DC.getParentModule (), VD, declaredMemberType);
3912
+
3913
+ if (!fnType || fnType->hasError ())
3914
+ continue ;
3915
+ if (auto *AFT = fnType->getAs <AnyFunctionType>()) {
3916
+ candidates.push_back (AFT->getParams ());
3917
+ }
3918
+ }
3919
+ }
3920
+
3921
+ static void collectPossibleParamListByQualifiedLookup (
3922
+ DeclContext &DC, Expr *baseExpr, DeclBaseName name,
3923
+ SmallVectorImpl<FunctionParams> &candidates) {
3924
+ ConcreteDeclRef ref = nullptr ;
3925
+ auto baseTyOpt = getTypeOfCompletionContextExpr (
3926
+ DC.getASTContext (), &DC, CompletionTypeCheckKind::Normal, baseExpr,
3927
+ ref);
3928
+ if (!baseTyOpt)
3929
+ return ;
3930
+ auto baseTy = (*baseTyOpt)->getRValueType ()->getMetatypeInstanceType ();
3931
+ if (!baseTy->mayHaveMembers ())
3932
+ return ;
3933
+
3934
+ collectPossibleParamListByQualifiedLookup (DC, baseTy, name, candidates);
3935
+ }
3936
+
3890
3937
static bool
3891
3938
collectPossibleParamLists (DeclContext &DC, ApplyExpr *callExpr,
3892
3939
SmallVectorImpl<FunctionParams> &candidates) {
@@ -3907,17 +3954,27 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3907
3954
if (auto *funcType = declType->getAs <AnyFunctionType>())
3908
3955
candidates.push_back (funcType->getParams ());
3909
3956
}
3910
- } else {
3911
- ConcreteDeclRef ref = nullptr ;
3912
- auto fnType = getTypeOfCompletionContextExpr (DC.getASTContext (),
3913
- &DC, CompletionTypeCheckKind::Normal,
3914
- fnExpr, ref);
3957
+ } else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(fnExpr)) {
3958
+ collectPossibleParamListByQualifiedLookup (
3959
+ DC, UDE->getBase (), UDE->getName ().getBaseName (), candidates);
3960
+ }
3915
3961
3962
+ if (candidates.empty ()) {
3963
+ ConcreteDeclRef ref = nullptr ;
3964
+ auto fnType = getTypeOfCompletionContextExpr (
3965
+ DC.getASTContext (), &DC, CompletionTypeCheckKind::Normal, fnExpr,
3966
+ ref);
3916
3967
if (!fnType)
3917
3968
return false ;
3918
3969
3919
- if (auto *AFT = (*fnType)->getAs <AnyFunctionType>())
3970
+ if (auto *AFT = (*fnType)->getAs <AnyFunctionType>()) {
3920
3971
candidates.push_back (AFT->getParams ());
3972
+ } else if (auto *AMT = (*fnType)->getAs <AnyMetatypeType>()) {
3973
+ auto baseTy = AMT->getInstanceType ();
3974
+ if (baseTy->mayHaveMembers ())
3975
+ collectPossibleParamListByQualifiedLookup (
3976
+ DC, baseTy, DeclBaseName::createConstructor (), candidates);
3977
+ }
3921
3978
}
3922
3979
3923
3980
return !candidates.empty ();
@@ -5165,30 +5222,30 @@ namespace {
5165
5222
5166
5223
public:
5167
5224
llvm::SmallVector<ParentTy, 5 > Ancestors;
5168
- ParentTy ParentClosest;
5169
- ParentTy ParentFarthest;
5170
5225
ExprParentFinder (Expr* ChildExpr,
5171
5226
llvm::function_ref<bool (ParentTy, ParentTy)> Predicate) :
5172
5227
ChildExpr (ChildExpr), Predicate(Predicate) {}
5173
5228
5174
5229
std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
5175
- if (E != ChildExpr && Predicate (E, Parent)) {
5230
+ // Finish if we found the target.
5231
+ if (E == ChildExpr)
5232
+ return { false , nullptr };
5233
+
5234
+ if (Predicate (E, Parent))
5176
5235
Ancestors.push_back (E);
5177
- return { true , E };
5178
- }
5179
- if (E == ChildExpr || arePositionsSame (E, ChildExpr)) {
5180
- if (!Ancestors.empty ()) {
5181
- ParentClosest = Ancestors.back ();
5182
- ParentFarthest = Ancestors.front ();
5183
- }
5184
- return {false , nullptr };
5185
- }
5186
5236
return { true , E };
5187
5237
}
5188
5238
5189
5239
Expr *walkToExprPost (Expr *E) override {
5190
5240
if (Predicate (E, Parent))
5191
5241
Ancestors.pop_back ();
5242
+
5243
+ // 'ChildExpr' might have been replaced with typechecked expression. In
5244
+ // that case, find deepest expression that position is the same as the
5245
+ // target.
5246
+ if (arePositionsSame (E, ChildExpr))
5247
+ return nullptr ;
5248
+
5192
5249
return E;
5193
5250
}
5194
5251
0 commit comments