From 9630eb6e375c4477d7fd7fd72ddfa64bb6685a03 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 17 Nov 2009 16:44:22 +0000 Subject: [PATCH] Augment code-completion results to provide argument names and placeholder arguments for Objective-C message sends. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89103 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaCodeComplete.cpp | 33 ++++++++++++++++++++++++++++ test/Index/complete-objc-message.m | 35 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/Index/complete-objc-message.m diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index de30441c53..e2aac77507 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -932,6 +932,39 @@ CodeCompleteConsumer::Result::CreateCodeCompletionString(Sema &S) { return Result; } + if (ObjCMethodDecl *Method = dyn_cast(ND)) { + CodeCompletionString *Result = new CodeCompletionString; + Selector Sel = Method->getSelector(); + if (Sel.isUnarySelector()) { + Result->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName()); + return Result; + } + + Result->AddTypedTextChunk( + Sel.getIdentifierInfoForSlot(0)->getName().str() + std::string(":")); + unsigned Idx = 0; + for (ObjCMethodDecl::param_iterator P = Method->param_begin(), + PEnd = Method->param_end(); + P != PEnd; (void)++P, ++Idx) { + if (Idx > 0) { + std::string Keyword = " "; + if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Idx)) + Keyword += II->getName().str(); + Keyword += ":"; + Result->AddTextChunk(Keyword); + } + + std::string Arg; + (*P)->getType().getAsStringInternal(Arg, S.Context.PrintingPolicy); + Arg = "(" + Arg + ")"; + if (IdentifierInfo *II = (*P)->getIdentifier()) + Arg += II->getName().str(); + Result->AddPlaceholderChunk(Arg); + } + + return Result; + } + if (Qualifier) { CodeCompletionString *Result = new CodeCompletionString; AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, diff --git a/test/Index/complete-objc-message.m b/test/Index/complete-objc-message.m new file mode 100644 index 0000000000..c495d0b7a6 --- /dev/null +++ b/test/Index/complete-objc-message.m @@ -0,0 +1,35 @@ +// Note: the run lines follow their respective tests, since line/column +// matter in this test. + +@protocol FooTestProtocol ++ protocolClassMethod; +- protocolInstanceMethod : (int)value; +@end +@interface Foo { + void *isa; +} ++ (int)classMethod1:a withKeyword:(int)b; ++ (void)classMethod2; ++ new; +- instanceMethod1; +@end + +@interface Foo (FooTestCategory) ++ categoryClassMethod; +- categoryInstanceMethod; +@end + +void func() { + Foo *obj = [Foo new]; + [obj xx]; +} +// RUN: c-index-test -code-completion-at=%s:23:19 %s | FileCheck -check-prefix=CHECK-CC1 %s +// CHECK-CC1: {TypedText categoryClassMethod} +// CHECK-CC1: {TypedText classMethod2} +// CHECK-CC1: {TypedText new} +// CHECK-CC1: {TypedText protocolClassMethod} +// CHECK-CC1: {TypedText classMethod1:}{Placeholder (id)a}{Text withKeyword:}{Placeholder (int)b} +// RUN: c-index-test -code-completion-at=%s:24:8 %s | FileCheck -check-prefix=CHECK-CC2 %s +// CHECK-CC2: {TypedText categoryInstanceMethod} +// CHECK-CC2: {TypedText instanceMethod1} +// CHECK-CC2: {TypedText protocolInstanceMethod:}{Placeholder (int)value} -- 2.50.1