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
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index de30441..e2aac77 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -932,6 +932,39 @@
     return Result;
   }
   
+  if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(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 0000000..c495d0b
--- /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 <FooTestProtocol> {
+  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}