aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-15 22:19:42 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-15 22:19:42 +0000
commitafc4578f8e55d4377b291e2325b2e9bc2cd72e89 (patch)
treebd398c2cac470af138ed93dd6d3d89603c90f33d
parentc12bbe5cbee8936204d286e17d8e0511dd67ddb4 (diff)
Implement a special code-completion pattern for "IBAction". Fixes
<rdar://problem/8767704>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125604 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Sema/Sema.h3
-rw-r--r--lib/Parse/ParseObjc.cpp2
-rw-r--r--lib/Sema/SemaCodeComplete.cpp23
-rw-r--r--test/Index/complete-method-decls.m7
4 files changed, 31 insertions, 4 deletions
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 80b7952ad9..e76bd67a3c 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -4984,7 +4984,8 @@ public:
void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl);
void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl);
- void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS);
+ void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
+ bool IsParameter);
void CodeCompleteObjCMessageReceiver(Scope *S);
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
IdentifierInfo **SelIdents,
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 0aae43adb8..f32a322f02 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -723,7 +723,7 @@ bool Parser::isTokIdentifier_in() const {
void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter) {
while (1) {
if (Tok.is(tok::code_completion)) {
- Actions.CodeCompleteObjCPassingType(getCurScope(), DS);
+ Actions.CodeCompleteObjCPassingType(getCurScope(), DS, IsParameter);
ConsumeCodeCompletionToken();
}
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index e7a9a8d838..1d7cf98264 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -4307,7 +4307,8 @@ void Sema::CodeCompleteObjCPropertySetter(Scope *S, Decl *ObjCImplDecl) {
Results.data(),Results.size());
}
-void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS) {
+void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
+ bool IsParameter) {
typedef CodeCompletionResult Result;
ResultBuilder Results(*this, CodeCompleter->getAllocator(),
CodeCompletionContext::CCC_Type);
@@ -4335,6 +4336,26 @@ void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS) {
Results.AddResult("oneway");
}
+ // If we're completing the return type of an Objective-C method and the
+ // identifier IBAction refers to a macro, provide a completion item for
+ // an action, e.g.,
+ // IBAction)<#selector#>:(id)sender
+ if (DS.getObjCDeclQualifier() == 0 && !IsParameter &&
+ Context.Idents.get("IBAction").hasMacroDefinition()) {
+ typedef CodeCompletionString::Chunk Chunk;
+ CodeCompletionBuilder Builder(Results.getAllocator(), CCP_CodePattern,
+ CXAvailability_Available);
+ Builder.AddTypedTextChunk("IBAction");
+ Builder.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+ Builder.AddPlaceholderChunk("selector");
+ Builder.AddChunk(Chunk(CodeCompletionString::CK_Colon));
+ Builder.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
+ Builder.AddTextChunk("id");
+ Builder.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+ Builder.AddTextChunk("sender");
+ Results.AddResult(CodeCompletionResult(Builder.TakeString()));
+ }
+
// Add various builtin type names and specifiers.
AddOrdinaryNameResults(PCC_Type, S, *this, Results);
Results.ExitScope();
diff --git a/test/Index/complete-method-decls.m b/test/Index/complete-method-decls.m
index 5e7ba204f9..92208910e0 100644
--- a/test/Index/complete-method-decls.m
+++ b/test/Index/complete-method-decls.m
@@ -1,6 +1,6 @@
/* Note: the RUN lines are near the end of the file, since line/column
matter for this test. */
-
+#define IBAction void
@protocol P1
- (id)abc;
- (id)initWithInt:(int)x;
@@ -158,3 +158,8 @@
// CHECK-CCH: NotImplemented:{TypedText unsigned} (50)
// CHECK-CCH: NotImplemented:{TypedText void} (50)
// CHECK-CCH: NotImplemented:{TypedText volatile} (50)
+
+// IBAction completion
+// RUN: c-index-test -code-completion-at=%s:5:4 %s | FileCheck -check-prefix=CHECK-IBACTION %s
+// CHECK-IBACTION: NotImplemented:{TypedText IBAction}{RightParen )}{Placeholder selector}{Colon :}{LeftParen (}{Text id}{RightParen )}{Text sender} (40)
+