r361829 - [CodeComplete] Consistently break after '{' in multi-line patterns
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 07:33:16 PDT 2019
Author: ibiryukov
Date: Tue May 28 07:33:16 2019
New Revision: 361829
URL: http://llvm.org/viewvc/llvm-project?rev=361829&view=rev
Log:
[CodeComplete] Consistently break after '{' in multi-line patterns
Summary:
Completion can return multi-line patterns in some cases, e.g.
for (<#init#>; <#cond#>; <#inc#>) {
<#body#>
}
However, most patterns break the line only before closing brace,
resulting in code like:
namespace <#name#> { <#decls#>
}
While some (e.g. the 'for' example above) are breaking lines after the
opening brace too.
This change ensures all patterns consistently break after the opening
brace, this leads to nicer UX when using those in an actual editor.
Reviewers: gribozavr
Reviewed By: gribozavr
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62405
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp
cfe/trunk/test/CodeCompletion/ordinary-name.cpp
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=361829&r1=361828&r2=361829&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue May 28 07:33:16 2019
@@ -1899,6 +1899,7 @@ static void AddOrdinaryNameResults(Sema:
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddPlaceholderChunk("identifier");
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("declarations");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
@@ -2046,6 +2047,7 @@ static void AddOrdinaryNameResults(Sema:
SemaRef.getLangOpts().CXXExceptions) {
Builder.AddTypedTextChunk("try");
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
@@ -2054,6 +2056,7 @@ static void AddOrdinaryNameResults(Sema:
Builder.AddPlaceholderChunk("declaration");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
@@ -2072,6 +2075,7 @@ static void AddOrdinaryNameResults(Sema:
Builder.AddPlaceholderChunk("expression");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
@@ -2087,6 +2091,8 @@ static void AddOrdinaryNameResults(Sema:
Builder.AddChunk(CodeCompletionString::CK_RightParen);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+ Builder.AddPlaceholderChunk("cases");
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
Results.AddResult(Result(Builder.TakeString()));
}
@@ -2117,6 +2123,7 @@ static void AddOrdinaryNameResults(Sema:
Builder.AddPlaceholderChunk("expression");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
@@ -2125,6 +2132,7 @@ static void AddOrdinaryNameResults(Sema:
// do { statements } while ( expression );
Builder.AddTypedTextChunk("do");
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+ Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
Modified: cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp?rev=361829&r1=361828&r2=361829&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp (original)
+++ cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp Tue May 28 07:33:16 2019
@@ -14,7 +14,9 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: Pattern : const_cast<<#type#>>(<#expression#>)
// CHECK-CC1: COMPLETION: Pattern : [#void#]delete <#expression#>
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#void#]delete [] <#expression#>
- // CHECK-CC1-NEXT: COMPLETION: Pattern : do{<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : do{
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: double
// CHECK-CC1-NEXT: COMPLETION: Pattern : dynamic_cast<<#type#>>(<#expression#>)
// CHECK-CC1-NEXT: COMPLETION: enum
@@ -24,7 +26,9 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: foo : [#void#]foo()
// CHECK-CC1-NEXT: COMPLETION: Pattern : for(<#init-statement#>;<#condition#>;<#inc-expression#>){
// CHECK-CC1: COMPLETION: Pattern : goto <#label#>;
- // CHECK-CC1-NEXT: COMPLETION: Pattern : if(<#condition#>){<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : if(<#condition#>){
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: int
// CHECK-CC1-NEXT: COMPLETION: long
// CHECK-CC1-NEXT: COMPLETION: Pattern : new <#type#>(<#expressions#>)
@@ -47,7 +51,9 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: thread_local
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#void#]throw <#expression#>
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#bool#]true
- // CHECK-CC1-NEXT: COMPLETION: Pattern : try{<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : try{
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
// CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
@@ -60,7 +66,9 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: void
// CHECK-CC1-NEXT: COMPLETION: volatile
// CHECK-CC1-NEXT: COMPLETION: wchar_t
- // CHECK-CC1-NEXT: COMPLETION: Pattern : while(<#condition#>){<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : while(<#condition#>){
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: X : X
// CHECK-CC1-NEXT: COMPLETION: y : [#int#]y
// CHECK-CC1-NEXT: COMPLETION: z : [#void#]z(<#int#>)
@@ -83,7 +91,9 @@ void foo() {
// CHECK-CC2-NEXT: COMPLETION: inline
// CHECK-CC2-NEXT: COMPLETION: int
// CHECK-CC2-NEXT: COMPLETION: long
- // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#>{<#declarations#>
+ // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#>{
+ // CHECK-CC2-NEXT: <#declarations#>
+ // CHECK-CC2-NEXT: }
// CHECK-CC2: COMPLETION: Pattern : namespace <#name#> = <#namespace#>;
// CHECK-CC2-NEXT: COMPLETION: operator
// CHECK-CC2-NEXT: COMPLETION: short
@@ -209,7 +219,9 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : const_cast<<#type#>>(<#expression#>)
// CHECK-NO-RTTI: COMPLETION: Pattern : [#void#]delete <#expression#>
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : [#void#]delete [] <#expression#>
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : do{<#statements#>
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : do{
+ // CHECK-NO-RTTI-NEXT: <#statements#>
+ // CHECK-NO-RTTI-NEXT: }
// CHECK-NO-RTTI: COMPLETION: double
// CHECK-NO-RTTI-NOT: dynamic_cast
// CHECK-NO-RTTI: COMPLETION: enum
@@ -219,7 +231,9 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: foo : [#void#]foo()
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : for(<#init-statement#>;<#condition#>;<#inc-expression#>){
// CHECK-NO-RTTI: COMPLETION: Pattern : goto <#label#>;
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : if(<#condition#>){<#statements#>
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : if(<#condition#>){
+ // CHECK-NO-RTTI-NEXT: <#statements#>
+ // CHECK-NO-RTTI-NEXT: }
// CHECK-NO-RTTI: COMPLETION: int
// CHECK-NO-RTTI-NEXT: COMPLETION: long
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : new <#type#>(<#expressions#>)
@@ -254,7 +268,7 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: void
// CHECK-NO-RTTI-NEXT: COMPLETION: volatile
// CHECK-NO-RTTI-NEXT: COMPLETION: wchar_t
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : while(<#condition#>){<#statements#>
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : while(<#condition#>){
// CHECK-NO-RTTI: COMPLETION: X : X
// CHECK-NO-RTTI-NEXT: COMPLETION: y : [#int#]y
// CHECK-NO-RTTI-NEXT: COMPLETION: z : [#void#]z(<#int#>)
Modified: cfe/trunk/test/CodeCompletion/ordinary-name.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ordinary-name.cpp?rev=361829&r1=361828&r2=361829&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/ordinary-name.cpp (original)
+++ cfe/trunk/test/CodeCompletion/ordinary-name.cpp Tue May 28 07:33:16 2019
@@ -12,7 +12,9 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: Pattern : const_cast<<#type#>>(<#expression#>)
// CHECK-CC1: COMPLETION: Pattern : [#void#]delete <#expression#>
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#void#]delete [] <#expression#>
- // CHECK-CC1-NEXT: COMPLETION: Pattern : do{<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : do{
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: double
// CHECK-CC1-NEXT: COMPLETION: Pattern : dynamic_cast<<#type#>>(<#expression#>)
// CHECK-CC1-NEXT: COMPLETION: enum
@@ -21,8 +23,12 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: float
// CHECK-CC1-NEXT: COMPLETION: foo : [#void#]foo()
// CHECK-CC1-NEXT: COMPLETION: Pattern : for(<#init-statement#>;<#condition#>;<#inc-expression#>){
+ // CHECK-CC1-NEXT: <#statements#>{{$}}
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: Pattern : goto <#label#>;
- // CHECK-CC1-NEXT: COMPLETION: Pattern : if(<#condition#>){<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : if(<#condition#>){
+ // CHECK-CC1-NEXT: <#statements#>{{$}}
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: int
// CHECK-CC1-NEXT: COMPLETION: long
// CHECK-CC1-NEXT: COMPLETION: Pattern : new <#type#>(<#expressions#>)
@@ -40,7 +46,11 @@ void foo() {
// CHECK-CC1: COMPLETION: t : t
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#void#]throw <#expression#>
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#bool#]true
- // CHECK-CC1-NEXT: COMPLETION: Pattern : try{<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : try{
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }catch(<#declaration#>){
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
// CHECK-CC1-NEXT: COMPLETION: Pattern : typedef <#type#> <#name#>
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#std::type_info#]typeid(<#expression-or-type#>)
@@ -53,7 +63,9 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: void
// CHECK-CC1-NEXT: COMPLETION: volatile
// CHECK-CC1-NEXT: COMPLETION: wchar_t
- // CHECK-CC1-NEXT: COMPLETION: Pattern : while(<#condition#>){<#statements#>
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : while(<#condition#>){
+ // CHECK-CC1-NEXT: <#statements#>
+ // CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: X : X
// CHECK-CC1-NEXT: COMPLETION: y : [#int#]y
// CHECK-CC1-NEXT: COMPLETION: z : [#void#]z(<#int#>)
@@ -71,7 +83,9 @@ void foo() {
// CHECK-CC2-NEXT: COMPLETION: inline
// CHECK-CC2-NEXT: COMPLETION: int
// CHECK-CC2-NEXT: COMPLETION: long
- // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#>{<#declarations#>
+ // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#>{
+ // CHECK-CC2-NEXT: <#declarations#>
+ // CHECK-CC2-NEXT: }
// CHECK-CC2: COMPLETION: Pattern : namespace <#name#> = <#namespace#>;
// CHECK-CC2-NEXT: COMPLETION: operator
// CHECK-CC2-NEXT: COMPLETION: short
@@ -181,7 +195,7 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : const_cast<<#type#>>(<#expression#>)
// CHECK-NO-RTTI: COMPLETION: Pattern : [#void#]delete <#expression#>
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : [#void#]delete [] <#expression#>
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : do{<#statements#>
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : do{
// CHECK-NO-RTTI: COMPLETION: double
// CHECK-NO-RTTI-NOT: dynamic_cast
// CHECK-NO-RTTI: COMPLETION: enum
@@ -191,7 +205,7 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: foo : [#void#]foo()
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : for(<#init-statement#>;<#condition#>;<#inc-expression#>){
// CHECK-NO-RTTI: COMPLETION: Pattern : goto <#label#>;
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : if(<#condition#>){<#statements#>
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : if(<#condition#>){
// CHECK-NO-RTTI: COMPLETION: int
// CHECK-NO-RTTI-NEXT: COMPLETION: long
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : new <#type#>(<#expressions#>)
@@ -222,7 +236,7 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: void
// CHECK-NO-RTTI-NEXT: COMPLETION: volatile
// CHECK-NO-RTTI-NEXT: COMPLETION: wchar_t
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : while(<#condition#>){<#statements#>
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : while(<#condition#>){
// CHECK-NO-RTTI: COMPLETION: X : X
// CHECK-NO-RTTI-NEXT: COMPLETION: y : [#int#]y
// CHECK-NO-RTTI-NEXT: COMPLETION: z : [#void#]z(<#int#>)
More information about the cfe-commits
mailing list