r341824 - [clang] Make sure codecompletion is called for calls even when inside a token.

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 10 06:46:28 PDT 2018


Author: kadircet
Date: Mon Sep 10 06:46:28 2018
New Revision: 341824

URL: http://llvm.org/viewvc/llvm-project?rev=341824&view=rev
Log:
[clang] Make sure codecompletion is called for calls even when inside a token.

Summary:
Currently CodeCompleteCall only gets called after a comma or parantheses. This
patch makes sure it is called even at the cases like:
```foo(1^);```

Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51038

Added:
    cfe/trunk/test/CodeCompletion/function-overloads.cpp
Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/lib/Parse/ParseOpenMP.cpp
    cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
    cfe/trunk/test/Index/complete-block-property-assignment.m

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=341824&r1=341823&r2=341824&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Sep 10 06:46:28 2018
@@ -214,6 +214,11 @@ class Parser : public CodeCompletionHand
   /// should not be set directly.
   bool InMessageExpression;
 
+  /// Gets set to true after calling ProduceSignatureHelp, it is for a
+  /// workaround to make sure ProduceSignatureHelp is only called at the deepest
+  /// function call.
+  bool CalledSignatureHelp = false;
+
   /// The "depth" of the template parameters currently being parsed.
   unsigned TemplateParameterDepth;
 

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=341824&r1=341823&r2=341824&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Sep 10 06:46:28 2018
@@ -2305,6 +2305,7 @@ Decl *Parser::ParseDeclarationAfterDecla
       QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
           getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
           ThisDecl->getLocation(), Exprs, T.getOpenLocation());
+      CalledSignatureHelp = true;
       Actions.CodeCompleteExpression(getCurScope(), PreferredType);
     };
     if (ThisVarDecl) {
@@ -2317,6 +2318,12 @@ Decl *Parser::ParseDeclarationAfterDecla
     }
 
     if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
+      if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) {
+        Actions.ProduceConstructorSignatureHelp(
+            getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+            ThisDecl->getLocation(), Exprs, T.getOpenLocation());
+        CalledSignatureHelp = true;
+      }
       Actions.ActOnInitializerError(ThisDecl);
       SkipUntil(tok::r_paren, StopAtSemi);
     } else {

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=341824&r1=341823&r2=341824&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Sep 10 06:46:28 2018
@@ -1652,6 +1652,7 @@ Parser::ParsePostfixExpressionSuffix(Exp
       if (Tok.is(tok::code_completion)) {
         QualType PreferredType = Actions.ProduceCallSignatureHelp(
             getCurScope(), LHS.get(), None, PT.getOpenLocation());
+        CalledSignatureHelp = true;
         Actions.CodeCompleteExpression(getCurScope(), PreferredType);
         cutOffParsing();
         return ExprError();
@@ -1662,9 +1663,19 @@ Parser::ParsePostfixExpressionSuffix(Exp
           if (ParseExpressionList(ArgExprs, CommaLocs, [&] {
                 QualType PreferredType = Actions.ProduceCallSignatureHelp(
                     getCurScope(), LHS.get(), ArgExprs, PT.getOpenLocation());
+                CalledSignatureHelp = true;
                 Actions.CodeCompleteExpression(getCurScope(), PreferredType);
               })) {
             (void)Actions.CorrectDelayedTyposInExpr(LHS);
+            // If we got an error when parsing expression list, we don't call
+            // the CodeCompleteCall handler inside the parser. So call it here
+            // to make sure we get overload suggestions even when we are in the
+            // middle of a parameter.
+            if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
+              Actions.ProduceCallSignatureHelp(getCurScope(), LHS.get(),
+                                               ArgExprs, PT.getOpenLocation());
+              CalledSignatureHelp = true;
+            }
             LHS = ExprError();
           } else if (LHS.isInvalid()) {
             for (auto &E : ArgExprs)

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=341824&r1=341823&r2=341824&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon Sep 10 06:46:28 2018
@@ -1688,8 +1688,15 @@ Parser::ParseCXXTypeConstructExpression(
             QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
                 getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
                 DS.getEndLoc(), Exprs, T.getOpenLocation());
+            CalledSignatureHelp = true;
             Actions.CodeCompleteExpression(getCurScope(), PreferredType);
           })) {
+        if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
+          Actions.ProduceConstructorSignatureHelp(
+              getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
+              DS.getEndLoc(), Exprs, T.getOpenLocation());
+          CalledSignatureHelp = true;
+        }
         SkipUntil(tok::r_paren, StopAtSemi);
         return ExprError();
       }
@@ -2818,13 +2825,22 @@ Parser::ParseCXXNewExpression(bool UseGl
     if (Tok.isNot(tok::r_paren)) {
       CommaLocsTy CommaLocs;
       if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] {
-            ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(),
-                                                       DeclaratorInfo).get();
+            ParsedType TypeRep =
+                Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
             QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
                 getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
                 DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen);
+            CalledSignatureHelp = true;
             Actions.CodeCompleteExpression(getCurScope(), PreferredType);
-      })) {
+          })) {
+        if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
+          ParsedType TypeRep =
+              Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
+          Actions.ProduceConstructorSignatureHelp(
+              getCurScope(), TypeRep.get()->getCanonicalTypeInternal(),
+              DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen);
+          CalledSignatureHelp = true;
+        }
         SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
         return ExprError();
       }

Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=341824&r1=341823&r2=341824&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Mon Sep 10 06:46:28 2018
@@ -422,8 +422,15 @@ void Parser::ParseOpenMPReductionInitial
                   getCurScope(),
                   OmpPrivParm->getType()->getCanonicalTypeInternal(),
                   OmpPrivParm->getLocation(), Exprs, LParLoc);
+              CalledSignatureHelp = true;
               Actions.CodeCompleteExpression(getCurScope(), PreferredType);
             })) {
+      if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
+        Actions.ProduceConstructorSignatureHelp(
+            getCurScope(), OmpPrivParm->getType()->getCanonicalTypeInternal(),
+            OmpPrivParm->getLocation(), Exprs, LParLoc);
+        CalledSignatureHelp = true;
+      }
       Actions.ActOnInitializerError(OmpPrivParm);
       SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
     } else {

Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=341824&r1=341823&r2=341824&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Mon Sep 10 06:46:28 2018
@@ -619,6 +619,10 @@ static std::string getOverloadAsString(c
       OS << "<#" << C.Text << "#>";
       break;
 
+    // FIXME: We can also print optional parameters of an overload.
+    case CodeCompletionString::CK_Optional:
+      break;
+
     default: OS << C.Text; break;
     }
   }

Added: cfe/trunk/test/CodeCompletion/function-overloads.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/function-overloads.cpp?rev=341824&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/function-overloads.cpp (added)
+++ cfe/trunk/test/CodeCompletion/function-overloads.cpp Mon Sep 10 06:46:28 2018
@@ -0,0 +1,27 @@
+int f(int i, int j = 2, int k = 5);
+int f(float x, float y...);
+
+class A {
+ public:
+  A(int, int, int);
+};
+
+void test() {
+  A a(f(1, 2, 3, 4), 2, 3);
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:10 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:17 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:19 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:20 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:21 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC1: OVERLOAD: [#int#]f(<#float x#>, float y)
+// CHECK-CC1: OVERLOAD: [#int#]f(<#int i#>)
+// CHECK-CC1-NOT, CHECK-CC2-NOT: OVERLOAD: A(
+// CHECK-CC2: OVERLOAD: [#int#]f(float x, float y)
+// CHECK-CC2-NOT: OVERLOAD: [#int#]f(int i)
+// CHECK-CC3: OVERLOAD: A(<#int#>, int, int)
+// CHECK-CC3: OVERLOAD: A(<#const A &#>)
+// CHECK-CC3: OVERLOAD: A(<#A &&#>)
+// CHECK-CC4: OVERLOAD: A(int, <#int#>, int)

Modified: cfe/trunk/test/Index/complete-block-property-assignment.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-block-property-assignment.m?rev=341824&r1=341823&r2=341824&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-block-property-assignment.m (original)
+++ cfe/trunk/test/Index/complete-block-property-assignment.m Mon Sep 10 06:46:28 2018
@@ -60,7 +60,6 @@ typedef void (^FooBlock)(Foo *someParame
 // RUN: c-index-test -code-completion-at=%s:51:16 %s | FileCheck -check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:52:23 %s | FileCheck -check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:53:12 %s | FileCheck -check-prefix=CHECK-NO %s
-// RUN: c-index-test -code-completion-at=%s:54:15 %s | FileCheck -check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:56:15 %s | FileCheck -check-prefix=CHECK-NO %s
 // CHECK-NO: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
@@ -69,4 +68,12 @@ typedef void (^FooBlock)(Foo *someParame
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(int *)}{TypedText onReadonly} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType int (^)(int)}{TypedText processEvent} (35)
 
+// RUN: c-index-test -code-completion-at=%s:54:15 %s | FileCheck -check-prefix=CHECK-NO1 %s
+// CHECK-NO1: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
+// CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
+// CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText onAction} (35)
+// CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType FooBlock}{TypedText onEventHandler} (35)
+// CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType void (^)(int *)}{TypedText onReadonly} (35)
+// CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType int (^)(int)}{TypedText processEvent} (35)
+// CHECK-NO1-NEXT: OverloadCandidate:{ResultType void}{Text func}{LeftParen (}{CurrentParameter int x}{RightParen )} (1)
 @end




More information about the cfe-commits mailing list