From: Douglas Gregor Date: Thu, 31 Jan 2013 05:03:46 +0000 (+0000) Subject: When code completing in a statement, parenthesized expression, or X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=626799b2903a2ab7f58ed82f10153bad4e0f1b7f;p=clang 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 . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174038 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 3f6393724e..04f6ba72fc 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -733,7 +733,15 @@ unsigned ResultBuilder::getBasePriority(const NamedDecl *ND) { if (isa(ND)) return CCP_Constant; - if ((isa(ND) || isa(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(ND) || isa(ND)) && + !(CompletionContext.getKind() == CodeCompletionContext::CCC_Statement || + CompletionContext.getKind() + == CodeCompletionContext::CCC_ObjCMessageReceiver || + CompletionContext.getKind() + == CodeCompletionContext::CCC_ParenthesizedExpression)) return CCP_Type; return CCP_Declaration; diff --git a/test/Index/complete-exprs.c b/test/Index/complete-exprs.c index afb6219ae3..bace0678c4 100644 --- a/test/Index/complete-exprs.c +++ b/test/Index/complete-exprs.c @@ -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) diff --git a/test/Index/complete-objc-message.m b/test/Index/complete-objc-message.m index 776a0490ef..5a7200570b 100644 --- a/test/Index/complete-objc-message.m +++ b/test/Index/complete-objc-message.m @@ -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} diff --git a/test/Index/complete-stmt.c b/test/Index/complete-stmt.c index e39431ebdc..3d31ca2f90 100644 --- a/test/Index/complete-stmt.c +++ b/test/Index/complete-stmt.c @@ -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)