@@ -1086,6 +1086,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
1086
1086
bool HasSpace = false ;
1087
1087
bool HasRParen = false ;
1088
1088
bool ShouldCompleteCallPatternAfterParen = true ;
1089
+ bool PreferFunctionReferencesToCalls = false ;
1089
1090
Optional<DeclKind> AttTargetDK;
1090
1091
1091
1092
SmallVector<StringRef, 3 > ParsedKeywords;
@@ -1419,6 +1420,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1419
1420
bool HaveRParen = false ;
1420
1421
bool IsSuperRefExpr = false ;
1421
1422
bool IsDynamicLookup = false ;
1423
+ bool PreferFunctionReferencesToCalls = false ;
1422
1424
bool HaveLeadingSpace = false ;
1423
1425
1424
1426
// / \brief True if we are code completing inside a static method.
@@ -1566,6 +1568,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1566
1568
IsDynamicLookup = true ;
1567
1569
}
1568
1570
1571
+ void setPreferFunctionReferencesToCalls () {
1572
+ PreferFunctionReferencesToCalls = true ;
1573
+ }
1574
+
1569
1575
void setHaveLeadingSpace (bool value) { HaveLeadingSpace = value; }
1570
1576
1571
1577
void addExpressionSpecificDecl (const Decl *D) {
@@ -2402,6 +2408,43 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2402
2408
Builder.addDeclAttrKeyword (Name, Annotation);
2403
2409
}
2404
2410
2411
+ // / Add the compound function name for the given function.
2412
+ void addCompoundFunctionName (AbstractFunctionDecl *AFD,
2413
+ DeclVisibilityKind Reason) {
2414
+ CommandWordsPairs Pairs;
2415
+ CodeCompletionResultBuilder Builder (
2416
+ Sink, CodeCompletionResult::ResultKind::Declaration,
2417
+ getSemanticContext (AFD, Reason), ExpectedTypes);
2418
+ setClangDeclKeywords (AFD, Pairs, Builder);
2419
+ Builder.setAssociatedDecl (AFD);
2420
+
2421
+ // Base name
2422
+ addLeadingDot (Builder);
2423
+ Builder.addTextChunk (AFD->getFullName ().getBaseName ().str ());
2424
+
2425
+ // Add the argument labels.
2426
+ auto ArgLabels = AFD->getFullName ().getArgumentNames ();
2427
+ if (ArgLabels.size () > 0 ) {
2428
+ if (!HaveLParen)
2429
+ Builder.addLeftParen ();
2430
+ else
2431
+ Builder.addAnnotatedLeftParen ();
2432
+
2433
+ for (auto ArgLabel : ArgLabels) {
2434
+ if (ArgLabel.empty ())
2435
+ Builder.addTextChunk (" _" );
2436
+ else
2437
+ Builder.addTextChunk (ArgLabel.str ());
2438
+ Builder.addTextChunk (" :" );
2439
+ }
2440
+
2441
+ if (!HaveRParen)
2442
+ Builder.addRightParen ();
2443
+ else
2444
+ Builder.addAnnotatedRightParen ();
2445
+ }
2446
+ }
2447
+
2405
2448
// Implement swift::VisibleDeclConsumer.
2406
2449
void foundDecl (ValueDecl *D, DeclVisibilityKind Reason) override {
2407
2450
// Hide private stdlib declarations.
@@ -2424,6 +2467,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2424
2467
switch (Kind) {
2425
2468
case LookupKind::ValueExpr:
2426
2469
if (auto *CD = dyn_cast<ConstructorDecl>(D)) {
2470
+ // Do we want compound function names here?
2471
+ if (PreferFunctionReferencesToCalls) {
2472
+ addCompoundFunctionName (CD, Reason);
2473
+ return ;
2474
+ }
2475
+
2427
2476
if (auto MT = ExprType->getRValueType ()->getAs <AnyMetatypeType>()) {
2428
2477
if (HaveDot) {
2429
2478
Type Ty;
@@ -2481,6 +2530,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2481
2530
if (FD->isAccessor ())
2482
2531
return ;
2483
2532
2533
+ // Do we want compound function names here?
2534
+ if (PreferFunctionReferencesToCalls) {
2535
+ addCompoundFunctionName (FD, Reason);
2536
+ return ;
2537
+ }
2538
+
2484
2539
addMethodCall (FD, Reason);
2485
2540
return ;
2486
2541
}
@@ -3759,6 +3814,9 @@ void CodeCompletionCallbacksImpl::completeDotExpr(Expr *E, SourceLoc DotLoc) {
3759
3814
return ;
3760
3815
3761
3816
Kind = CompletionKind::DotExpr;
3817
+ if (InObjCSelectorExpr)
3818
+ PreferFunctionReferencesToCalls = true ;
3819
+
3762
3820
ParsedExpr = E;
3763
3821
this ->DotLoc = DotLoc;
3764
3822
CurDeclContext = P.CurDeclContext ;
@@ -3780,6 +3838,9 @@ void CodeCompletionCallbacksImpl::completePostfixExprBeginning(CodeCompletionExp
3780
3838
return ;
3781
3839
3782
3840
Kind = CompletionKind::PostfixExprBeginning;
3841
+ if (InObjCSelectorExpr)
3842
+ PreferFunctionReferencesToCalls = true ;
3843
+
3783
3844
CurDeclContext = P.CurDeclContext ;
3784
3845
CStyleForLoopIterationVariable =
3785
3846
CodeCompletionCallbacks::CStyleForLoopIterationVariable;
@@ -3795,6 +3856,9 @@ void CodeCompletionCallbacksImpl::completePostfixExpr(Expr *E, bool hasSpace) {
3795
3856
3796
3857
HasSpace = hasSpace;
3797
3858
Kind = CompletionKind::PostfixExpr;
3859
+ if (InObjCSelectorExpr)
3860
+ PreferFunctionReferencesToCalls = true ;
3861
+
3798
3862
ParsedExpr = E;
3799
3863
CurDeclContext = P.CurDeclContext ;
3800
3864
}
@@ -3833,6 +3897,9 @@ void CodeCompletionCallbacksImpl::completeExprSuper(SuperRefExpr *SRE) {
3833
3897
return ;
3834
3898
3835
3899
Kind = CompletionKind::SuperExpr;
3900
+ if (InObjCSelectorExpr)
3901
+ PreferFunctionReferencesToCalls = true ;
3902
+
3836
3903
ParsedExpr = SRE;
3837
3904
CurDeclContext = P.CurDeclContext ;
3838
3905
}
@@ -3843,6 +3910,9 @@ void CodeCompletionCallbacksImpl::completeExprSuperDot(SuperRefExpr *SRE) {
3843
3910
return ;
3844
3911
3845
3912
Kind = CompletionKind::SuperExprDot;
3913
+ if (InObjCSelectorExpr)
3914
+ PreferFunctionReferencesToCalls = true ;
3915
+
3846
3916
ParsedExpr = SRE;
3847
3917
CurDeclContext = P.CurDeclContext ;
3848
3918
}
@@ -4376,6 +4446,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
4376
4446
if (ExprType) {
4377
4447
Lookup.setIsStaticMetatype (ParsedExpr->isStaticallyDerivedMetatype ());
4378
4448
}
4449
+ if (PreferFunctionReferencesToCalls)
4450
+ Lookup.setPreferFunctionReferencesToCalls ();
4379
4451
4380
4452
auto DoPostfixExprBeginning = [&] (){
4381
4453
if (CStyleForLoopIterationVariable)
0 commit comments