r362363 - [CodeComplete] Add a bit more whitespace to completed patterns
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 3 01:34:26 PDT 2019
Author: ibiryukov
Date: Mon Jun 3 01:34:25 2019
New Revision: 362363
URL: http://llvm.org/viewvc/llvm-project?rev=362363&view=rev
Log:
[CodeComplete] Add a bit more whitespace to completed patterns
Summary:
E.g. we now turn `while(<#cond#>){` into `while (<#cond#>) {`
This slightly improves the final output. Should not affect clients that
format the result on their own.
Reviewers: gribozavr
Reviewed By: gribozavr
Subscribers: jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62616
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=362363&r1=362362&r2=362363&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Jun 3 01:34:25 2019
@@ -1900,6 +1900,7 @@ static void AddOrdinaryNameResults(Sema:
Builder.AddTypedTextChunk("namespace");
Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddPlaceholderChunk("identifier");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("declarations");
@@ -2048,15 +2049,19 @@ static void AddOrdinaryNameResults(Sema:
if (SemaRef.getLangOpts().CPlusPlus && Results.includeCodePatterns() &&
SemaRef.getLangOpts().CXXExceptions) {
Builder.AddTypedTextChunk("try");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddTextChunk("catch");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Builder.AddPlaceholderChunk("declaration");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
@@ -2070,12 +2075,14 @@ static void AddOrdinaryNameResults(Sema:
if (Results.includeCodePatterns()) {
// if (condition) { statements }
Builder.AddTypedTextChunk("if");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
if (SemaRef.getLangOpts().CPlusPlus)
Builder.AddPlaceholderChunk("condition");
else
Builder.AddPlaceholderChunk("expression");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
@@ -2085,12 +2092,14 @@ static void AddOrdinaryNameResults(Sema:
// switch (condition) { }
Builder.AddTypedTextChunk("switch");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
if (SemaRef.getLangOpts().CPlusPlus)
Builder.AddPlaceholderChunk("condition");
else
Builder.AddPlaceholderChunk("expression");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("cases");
@@ -2118,12 +2127,14 @@ static void AddOrdinaryNameResults(Sema:
if (Results.includeCodePatterns()) {
/// while (condition) { statements }
Builder.AddTypedTextChunk("while");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
if (SemaRef.getLangOpts().CPlusPlus)
Builder.AddPlaceholderChunk("condition");
else
Builder.AddPlaceholderChunk("expression");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
@@ -2133,12 +2144,14 @@ static void AddOrdinaryNameResults(Sema:
// do { statements } while ( expression );
Builder.AddTypedTextChunk("do");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddChunk(CodeCompletionString::CK_RightBrace);
Builder.AddTextChunk("while");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Builder.AddPlaceholderChunk("expression");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
@@ -2146,16 +2159,20 @@ static void AddOrdinaryNameResults(Sema:
// for ( for-init-statement ; condition ; expression ) { statements }
Builder.AddTypedTextChunk("for");
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftParen);
if (SemaRef.getLangOpts().CPlusPlus || SemaRef.getLangOpts().C99)
Builder.AddPlaceholderChunk("init-statement");
else
Builder.AddPlaceholderChunk("init-expression");
Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddPlaceholderChunk("condition");
Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddPlaceholderChunk("inc-expression");
Builder.AddChunk(CodeCompletionString::CK_RightParen);
+ Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
Builder.AddPlaceholderChunk("statements");
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=362363&r1=362362&r2=362363&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp (original)
+++ cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp Mon Jun 3 01:34:25 2019
@@ -14,7 +14,7 @@ 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{
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : do {
// CHECK-CC1-NEXT: <#statements#>
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: double
@@ -24,9 +24,9 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#bool#]false
// 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: COMPLETION: Pattern : for (<#init-statement#>; <#condition#>; <#inc-expression#>) {
// CHECK-CC1: COMPLETION: Pattern : goto <#label#>;
- // CHECK-CC1-NEXT: COMPLETION: Pattern : if(<#condition#>){
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : if (<#condition#>) {
// CHECK-CC1-NEXT: <#statements#>
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: int
@@ -46,12 +46,12 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: Pattern : static_assert(<#expression#>, <#message#>);
// CHECK-CC1-NEXT: COMPLETION: Pattern : static_cast<<#type#>>(<#expression#>)
// CHECK-CC1-NEXT: COMPLETION: struct
- // CHECK-CC1-NEXT: COMPLETION: Pattern : switch(<#condition#>){
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : switch (<#condition#>) {
// CHECK-CC1: COMPLETION: t : t
// 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{
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : try {
// CHECK-CC1-NEXT: <#statements#>
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
@@ -66,7 +66,7 @@ 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#>){
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : while (<#condition#>) {
// CHECK-CC1-NEXT: <#statements#>
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: X : X
@@ -91,7 +91,7 @@ void foo() {
// CHECK-CC2-NEXT: COMPLETION: inline
// CHECK-CC2-NEXT: COMPLETION: int
// CHECK-CC2-NEXT: COMPLETION: long
- // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#>{
+ // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#> {
// CHECK-CC2-NEXT: <#declarations#>
// CHECK-CC2-NEXT: }
// CHECK-CC2: COMPLETION: Pattern : namespace <#name#> = <#namespace#>;
@@ -219,7 +219,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{
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : do {
// CHECK-NO-RTTI-NEXT: <#statements#>
// CHECK-NO-RTTI-NEXT: }
// CHECK-NO-RTTI: COMPLETION: double
@@ -229,9 +229,9 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : [#bool#]false
// CHECK-NO-RTTI-NEXT: COMPLETION: float
// CHECK-NO-RTTI-NEXT: COMPLETION: foo : [#void#]foo()
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : for(<#init-statement#>;<#condition#>;<#inc-expression#>){
+ // 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#>){
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : if (<#condition#>) {
// CHECK-NO-RTTI-NEXT: <#statements#>
// CHECK-NO-RTTI-NEXT: }
// CHECK-NO-RTTI: COMPLETION: int
@@ -251,7 +251,7 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : static_assert(<#expression#>, <#message#>);
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : static_cast<<#type#>>(<#expression#>)
// CHECK-NO-RTTI-NEXT: COMPLETION: struct
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : switch(<#condition#>){
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : switch (<#condition#>) {
// CHECK-NO-RTTI: COMPLETION: t : t
// CHECK-NO-RTTI-NOT: throw
// CHECK-NO-RTTI: COMPLETION: Pattern : [#bool#]true
@@ -268,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#>){
+ // 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=362363&r1=362362&r2=362363&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/ordinary-name.cpp (original)
+++ cfe/trunk/test/CodeCompletion/ordinary-name.cpp Mon Jun 3 01:34:25 2019
@@ -12,7 +12,7 @@ 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{
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : do {
// CHECK-CC1-NEXT: <#statements#>
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: double
@@ -22,11 +22,11 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: Pattern : [#bool#]false
// 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: 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#>){
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : if (<#condition#>) {
// CHECK-CC1-NEXT: <#statements#>{{$}}
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: int
@@ -42,13 +42,13 @@ void foo() {
// CHECK-CC1-NEXT: COMPLETION: static
// CHECK-CC1-NEXT: COMPLETION: Pattern : static_cast<<#type#>>(<#expression#>)
// CHECK-CC1-NEXT: COMPLETION: struct
- // CHECK-CC1-NEXT: COMPLETION: Pattern : switch(<#condition#>){
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : switch (<#condition#>) {
// 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{
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : try {
// CHECK-CC1-NEXT: <#statements#>
- // CHECK-CC1-NEXT: }catch(<#declaration#>){
+ // CHECK-CC1-NEXT: } catch (<#declaration#>) {
// CHECK-CC1-NEXT: <#statements#>
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: TYPEDEF : TYPEDEF
@@ -63,7 +63,7 @@ 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#>){
+ // CHECK-CC1-NEXT: COMPLETION: Pattern : while (<#condition#>) {
// CHECK-CC1-NEXT: <#statements#>
// CHECK-CC1-NEXT: }
// CHECK-CC1: COMPLETION: X : X
@@ -83,7 +83,7 @@ void foo() {
// CHECK-CC2-NEXT: COMPLETION: inline
// CHECK-CC2-NEXT: COMPLETION: int
// CHECK-CC2-NEXT: COMPLETION: long
- // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#>{
+ // CHECK-CC2-NEXT: COMPLETION: Pattern : namespace <#identifier#> {
// CHECK-CC2-NEXT: <#declarations#>
// CHECK-CC2-NEXT: }
// CHECK-CC2: COMPLETION: Pattern : namespace <#name#> = <#namespace#>;
@@ -195,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{
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : do {
// CHECK-NO-RTTI: COMPLETION: double
// CHECK-NO-RTTI-NOT: dynamic_cast
// CHECK-NO-RTTI: COMPLETION: enum
@@ -203,9 +203,9 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : [#bool#]false
// CHECK-NO-RTTI-NEXT: COMPLETION: float
// CHECK-NO-RTTI-NEXT: COMPLETION: foo : [#void#]foo()
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : for(<#init-statement#>;<#condition#>;<#inc-expression#>){
+ // 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#>){
+ // 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#>)
@@ -219,7 +219,7 @@ void foo() {
// CHECK-NO-RTTI-NEXT: COMPLETION: static
// CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : static_cast<<#type#>>(<#expression#>)
// CHECK-NO-RTTI-NEXT: COMPLETION: struct
- // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : switch(<#condition#>){
+ // CHECK-NO-RTTI-NEXT: COMPLETION: Pattern : switch (<#condition#>) {
// CHECK-NO-RTTI: COMPLETION: t : t
// CHECK-NO-RTTI-NOT: throw
// CHECK-NO-RTTI: COMPLETION: Pattern : [#bool#]true
@@ -236,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#>){
+ // 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