r174038 - When code completing in a statement, parenthesized expression, or

Douglas Gregor dgregor at apple.com
Wed Jan 30 21:03:46 PST 2013


Author: dgregor
Date: Wed Jan 30 23:03:46 2013
New Revision: 174038

URL: http://llvm.org/viewvc/llvm-project?rev=174038&view=rev
Log:
When code completing in a statement, parenthesized expression, or
Objective-C message receiver, the user is as likely to want to write a
type name as any other declaration, so give types the same priority as
other declarations. Fixes <rdar://problem/12480600>.

Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-exprs.c
    cfe/trunk/test/Index/complete-objc-message.m
    cfe/trunk/test/Index/complete-stmt.c

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=174038&r1=174037&r2=174038&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Jan 30 23:03:46 2013
@@ -733,7 +733,15 @@ unsigned ResultBuilder::getBasePriority(
   if (isa<EnumConstantDecl>(ND))
     return CCP_Constant;
 
-  if ((isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND)))
+  // Use CCP_Type for type declarations unless we're in a statement, Objective-C
+  // message receiver, or parenthesized expression context. There, it's as
+  // likely that the user will want to write a type as other declarations.
+  if ((isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND)) &&
+      !(CompletionContext.getKind() == CodeCompletionContext::CCC_Statement ||
+        CompletionContext.getKind()
+          == CodeCompletionContext::CCC_ObjCMessageReceiver ||
+        CompletionContext.getKind()
+          == CodeCompletionContext::CCC_ParenthesizedExpression))
     return CCP_Type;
 
   return CCP_Declaration;

Modified: cfe/trunk/test/Index/complete-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-exprs.c?rev=174038&r1=174037&r2=174038&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-exprs.c (original)
+++ cfe/trunk/test/Index/complete-exprs.c Wed Jan 30 23:03:46 2013
@@ -66,4 +66,4 @@ void f5(float f) {
 // CHECK-CC7: FunctionDecl:{ResultType void}{TypedText f3}{LeftParen (}{Placeholder const char *, ...}{Text , NULL}{RightParen )} (50)
 // CHECK-CC7: FunctionDecl:{ResultType void}{TypedText f4}{LeftParen (}{Placeholder const char *str}{RightParen )} (50)
 // CHECK-CC7: FunctionDecl:{ResultType void}{TypedText f5}{LeftParen (}{Placeholder float f}{RightParen )} (50)
-// CHECK-CC7: TypedefDecl:{TypedText type}
+// CHECK-CC7: TypedefDecl:{TypedText type} (50)

Modified: cfe/trunk/test/Index/complete-objc-message.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-objc-message.m?rev=174038&r1=174037&r2=174038&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-objc-message.m (original)
+++ cfe/trunk/test/Index/complete-objc-message.m Wed Jan 30 23:03:46 2013
@@ -239,15 +239,15 @@ void test_DO(DO *d, A* a) {
 // CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)}
 // CHECK-CC9: Objective-C selector: Method:Arg1:
 // RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCA %s
-// CHECK-CCA: TypedefDecl:{TypedText Class}
-// CHECK-CCA-NEXT: ObjCInterfaceDecl:{TypedText Foo}
-// CHECK-CCA-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )}
-// CHECK-CCA:FunctionDecl:{ResultType MyClass *}{TypedText getMyClass}{LeftParen (}{RightParen )}
-// CHECK-CCA: TypedefDecl:{TypedText id}
-// CHECK-CCA: ObjCInterfaceDecl:{TypedText MyClass}
-// CHECK-CCA: ObjCInterfaceDecl:{TypedText MySubClass}
-// CHECK-CCA: {ResultType Class}{TypedText self}
-// CHECK-CCA: {TypedText super}
+// CHECK-CCA: TypedefDecl:{TypedText Class} (50)
+// CHECK-CCA-NEXT: ObjCInterfaceDecl:{TypedText Foo} (50)
+// CHECK-CCA-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} (50)
+// CHECK-CCA:FunctionDecl:{ResultType MyClass *}{TypedText getMyClass}{LeftParen (}{RightParen )} (50)
+// CHECK-CCA: TypedefDecl:{TypedText id} (50)
+// CHECK-CCA: ObjCInterfaceDecl:{TypedText MyClass} (50)
+// CHECK-CCA: ObjCInterfaceDecl:{TypedText MySubClass} (50)
+// CHECK-CCA: {ResultType Class}{TypedText self} (34)
+// CHECK-CCA: {TypedText super} (40)
 // RUN: c-index-test -code-completion-at=%s:103:6 %s | FileCheck -check-prefix=CHECK-CCB %s
 // CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int), ...}
 // CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText SentinelMethod:}{Placeholder (int), ...}{Text , nil}

Modified: cfe/trunk/test/Index/complete-stmt.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-stmt.c?rev=174038&r1=174037&r2=174038&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-stmt.c (original)
+++ cfe/trunk/test/Index/complete-stmt.c Wed Jan 30 23:03:46 2013
@@ -1,7 +1,7 @@
 // Note: the run lines follow their respective tests, since line/column
 // matter in this test.
 
-
+typedef int Integer;
 void f(int x) {
   if (x) {
   } 
@@ -14,3 +14,12 @@ void f(int x) {
 // RUN: c-index-test -code-completion-at=%s:7:4 %s | FileCheck -check-prefix=CHECK-IF-ELSE-SIMPLE %s
 // CHECK-IF-ELSE-SIMPLE: NotImplemented:{TypedText else} (40)
 // CHECK-IF-ELSE-SIMPLE: NotImplemented:{TypedText else}{HorizontalSpace  }{Text if}{HorizontalSpace  }{LeftParen (}{Placeholder expression}{RightParen )} (40)
+
+// RUN: c-index-test -code-completion-at=%s:6:1 %s | FileCheck -check-prefix=CHECK-STMT %s
+// CHECK-STMT: NotImplemented:{TypedText char} (50)
+// CHECK-STMT: NotImplemented:{TypedText const} (50)
+// CHECK-STMT: NotImplemented:{TypedText double} (50)
+// CHECK-STMT: NotImplemented:{TypedText enum} (50)
+// CHECK-STMT: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder int x}{RightParen )} (50)
+// CHECK-STMT: TypedefDecl:{TypedText Integer} (50)
+// CHECK-STMT: ParmDecl:{ResultType int}{TypedText x} (34)





More information about the cfe-commits mailing list