From 97fe61ca1749110c28eb4570a710c8983711c7b3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 18 Sep 2010 15:16:27 +0000 Subject: [PATCH] Give the Objective-C _cmd an "unlikely" code completion priority; it's very rarely used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114286 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/CodeCompleteConsumer.h | 5 ++++- lib/Sema/CodeCompleteConsumer.cpp | 10 +++++++++- test/Index/complete-exprs.m | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/Index/complete-exprs.m diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 9a388a294b..c251cedaf3 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -59,7 +59,10 @@ enum { CCP_NestedNameSpecifier = 75, /// \brief Priority for a result that isn't likely to be what the user wants, /// but is included for completeness. - CCP_Unlikely = 80 + CCP_Unlikely = 80, + + /// \brief Priority for the Objective-C "_cmd" implicit parameter. + CCP_ObjC_cmd = CCP_Unlikely }; /// \brief Priority value deltas that are added to code-completion results diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index 58a1627b47..3322782d87 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -389,8 +389,15 @@ unsigned CodeCompletionResult::getPriorityFromDecl(NamedDecl *ND) { // Context-based decisions. DeclContext *DC = ND->getDeclContext()->getRedeclContext(); - if (DC->isFunctionOrMethod() || isa(DC)) + if (DC->isFunctionOrMethod() || isa(DC)) { + // _cmd is relatively rare + if (ImplicitParamDecl *ImplicitParam = dyn_cast(ND)) + if (ImplicitParam->getIdentifier() && + ImplicitParam->getIdentifier()->isStr("_cmd")) + return CCP_ObjC_cmd; + return CCP_LocalDeclaration; + } if (DC->isRecord() || isa(DC)) return CCP_MemberDeclaration; @@ -399,6 +406,7 @@ unsigned CodeCompletionResult::getPriorityFromDecl(NamedDecl *ND) { return CCP_Constant; if (isa(ND) || isa(ND)) return CCP_Type; + return CCP_Declaration; } diff --git a/test/Index/complete-exprs.m b/test/Index/complete-exprs.m new file mode 100644 index 0000000000..0171803ffe --- /dev/null +++ b/test/Index/complete-exprs.m @@ -0,0 +1,15 @@ +@interface A +- (int)method:(id)param1; + +@property int prop1; +@end + +@implementation A +- (int)method:(id)param1 { + +} +@end + +// RUN: c-index-test -code-completion-at=%s:9:2 %s | FileCheck -check-prefix=CHECK-CC1 %s +// CHECK-CC1: NotImplemented:{ResultType SEL}{TypedText _cmd} (80) +// CHECK-CC1: NotImplemented:{ResultType A *}{TypedText self} (8) -- 2.40.0