From: Jordan Rose Date: Fri, 15 Jun 2012 18:19:56 +0000 (+0000) Subject: [completion] Add completions for @"..." and @(...), and tidy up @[] and @{}. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f6e22d14419db7162202854190f690f393daf2d;p=clang [completion] Add completions for @"..." and @(...), and tidy up @[] and @{}. Specifically, @[] and @{} didn't have a type associated with them; we now use "NSArray *" and "NSDictionary *", respectively. @"" has the type "NSString *". @(), unfortunately, has type "id", since it (currently) may be either an NSNumber or an NSString. Add a test for all the Objective-C at-expression completions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158533 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index ca5ee3b226..bfe9fea058 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -4411,7 +4411,7 @@ static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) { const char *EncodeType = "char[]"; if (Results.getSema().getLangOpts().CPlusPlus || Results.getSema().getLangOpts().ConstStrings) - EncodeType = " const char[]"; + EncodeType = "const char[]"; Builder.AddResultTypeChunk(EncodeType); Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"encode")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); @@ -4434,8 +4434,16 @@ static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) { Builder.AddPlaceholderChunk("selector"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Results.AddResult(Result(Builder.TakeString())); - + + // @"string" + Builder.AddResultTypeChunk("NSString *"); + Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"\"")); + Builder.AddPlaceholderChunk("string"); + Builder.AddTextChunk("\""); + Results.AddResult(Result(Builder.TakeString())); + // @[ objects, ... ] + Builder.AddResultTypeChunk("NSArray *"); Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"[")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("objects, ..."); @@ -4444,6 +4452,7 @@ static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) { Results.AddResult(Result(Builder.TakeString())); // @{ key : object, ... } + Builder.AddResultTypeChunk("NSDictionary *"); Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"{")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("key"); @@ -4454,6 +4463,15 @@ static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) { Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddChunk(CodeCompletionString::CK_RightBrace); Results.AddResult(Result(Builder.TakeString())); + + // @( expression ) + Builder.AddResultTypeChunk("id"); + Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt, "(")); + Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); + Builder.AddPlaceholderChunk("expression"); + Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); + Builder.AddChunk(CodeCompletionString::CK_RightParen); + Results.AddResult(Result(Builder.TakeString())); } static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt) { diff --git a/test/CodeCompletion/objc-expr.m b/test/CodeCompletion/objc-expr.m new file mode 100644 index 0000000000..82ce5381fd --- /dev/null +++ b/test/CodeCompletion/objc-expr.m @@ -0,0 +1,17 @@ +// Note: the run lines follow all tests, since line/column matter here + +id testCompleteAfterAtSign() { + return @""; +} + +// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:4:11 %s -fno-const-strings -o - | FileCheck -check-prefix=AT %s +// CHECK-AT: COMPLETION: Pattern : [#NSString *#]"<#string#>" +// CHECK-AT: COMPLETION: Pattern : [#id#]( <#expression#> ) +// CHECK-AT: COMPLETION: Pattern : [#NSArray *#][ <#objects, ...#> ] +// CHECK-AT: COMPLETION: Pattern : [#char[]#]encode(<#type-name#>) +// CHECK-AT: COMPLETION: Pattern : [#Protocol *#]protocol(<#protocol-name#>) +// CHECK-AT: COMPLETION: Pattern : [#SEL#]selector(<#selector#>) +// CHECK-AT: COMPLETION: Pattern : [#NSDictionary *#]{ <#key#> : <#object, ...#> } + +// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:4:11 %s -fconst-strings -o - | FileCheck -check-prefix=CONST-STRINGS %s +// CHECK-CONST-STRINGS: COMPLETION: Pattern : [#const char[]#]encode(<#type-name#>) diff --git a/test/Index/complete-exprs.m b/test/Index/complete-exprs.m index c3ff63bdbd..8f808eef3c 100644 --- a/test/Index/complete-exprs.m +++ b/test/Index/complete-exprs.m @@ -18,8 +18,10 @@ __strong id global; @end // RUN: c-index-test -code-completion-at=%s:13:2 %s | FileCheck -check-prefix=CHECK-CC1 %s -// CHECK-CC1: NotImplemented:{TypedText @[}{HorizontalSpace }{Placeholder objects, ...}{HorizontalSpace }{RightBracket ]} (40) -// CHECK-CC1: NotImplemented:{TypedText @{}{HorizontalSpace }{Placeholder key}{HorizontalSpace }{Colon :}{HorizontalSpace }{Placeholder object, ...}{HorizontalSpace }{RightBrace }} (40) +// CHECK-CC1: NotImplemented:{ResultType NSString *}{TypedText @"}{Placeholder string}{Text "} (40) +// CHECK-CC1: NotImplemented:{ResultType id}{TypedText @(}{HorizontalSpace }{Placeholder expression}{HorizontalSpace }{RightParen )} (40) +// CHECK-CC1: NotImplemented:{ResultType NSArray *}{TypedText @[}{HorizontalSpace }{Placeholder objects, ...}{HorizontalSpace }{RightBracket ]} (40) +// CHECK-CC1: NotImplemented:{ResultType NSDictionary *}{TypedText @{}{HorizontalSpace }{Placeholder key}{HorizontalSpace }{Colon :}{HorizontalSpace }{Placeholder object, ...}{HorizontalSpace }{RightBrace }} (40) // CHECK-CC1: NotImplemented:{ResultType SEL}{TypedText _cmd} (80) // CHECK-CC1: TypedefDecl:{TypedText BOOL} (50) // CHECK-CC1: macro definition:{TypedText bool} (51) @@ -40,8 +42,8 @@ __strong id global; // RUN: c-index-test -code-completion-at=%s:15:5 %s | FileCheck -check-prefix=CHECK-CC4 %s // RUN: c-index-test -code-completion-at=%s:16:5 %s | FileCheck -check-prefix=CHECK-CC4 %s // RUN: c-index-test -code-completion-at=%s:16:14 %s | FileCheck -check-prefix=CHECK-CC4 %s -// CHECK-CC4: NotImplemented:{TypedText @[}{HorizontalSpace }{Placeholder objects, ...}{HorizontalSpace }{RightBracket ]} (40) -// CHECK-CC4: NotImplemented:{TypedText @{}{HorizontalSpace }{Placeholder key}{HorizontalSpace }{Colon :}{HorizontalSpace }{Placeholder object, ...}{HorizontalSpace }{RightBrace }} (40) +// CHECK-CC4: NotImplemented:{ResultType NSArray *}{TypedText @[}{HorizontalSpace }{Placeholder objects, ...}{HorizontalSpace }{RightBracket ]} (40) +// CHECK-CC4: NotImplemented:{ResultType NSDictionary *}{TypedText @{}{HorizontalSpace }{Placeholder key}{HorizontalSpace }{Colon :}{HorizontalSpace }{Placeholder object, ...}{HorizontalSpace }{RightBrace }} (40) // CHECK-CC4: NotImplemented:{ResultType SEL}{TypedText _cmd} (80) // CHECK-CC4: macro definition:{TypedText bool} (51) // CHECK-CC4: macro definition:{TypedText NO} (65)