[clang] 28ecd7f - [clang-format] Don't break multi block parameters on ObjCBreakBeforeNestedBlockParam

Jin Lin via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 6 14:20:25 PDT 2020


Author: Kanglei Fang
Date: 2020-04-06T14:20:09-07:00
New Revision: 28ecd7f0b0865878a12d814a6d0de92cb7529d22

URL: https://github.com/llvm/llvm-project/commit/28ecd7f0b0865878a12d814a6d0de92cb7529d22
DIFF: https://github.com/llvm/llvm-project/commit/28ecd7f0b0865878a12d814a6d0de92cb7529d22.diff

LOG: [clang-format] Don't break multi block parameters on ObjCBreakBeforeNestedBlockParam

Summary:
While [the original diff](https://reviews.llvm.org/D42493) makes a lot of sense, and multiple inline block parameter/trailing paramemter after inline block paramemter should be discouraged, the formatting result is different than what xcode does by default
For the exact same example provided in the original diff:
```
[object
  blockArgument:^{
    a = 42;
  }
     anotherArg:42];
```
The code is hard to read and not very visually pleasing

This diff uses `ObjCBreakBeforeNestedBlockParam` to shield from the formatting
When it's set to false, don't allign the inline block paramemters.

Reviewers: jolesiak, benhamilton, jinlin

Reviewed By: jolesiak

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77039

Added: 
    

Modified: 
    clang/docs/ClangFormatStyleOptions.rst
    clang/lib/Format/ContinuationIndenter.cpp
    clang/unittests/Format/FormatTestObjC.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 50b4ff5d9010..1c1d0142930f 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2072,8 +2072,8 @@ the configuration (without a prefix: ``Auto``).
      - (void)_aMethod
      {
         [self.test1 t:self
-                     w:self
-            callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
+                    w:self
+             callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
                  u = c;
              }]
      }

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index ba42ba0ca050..03e79a22954e 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -342,6 +342,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
   if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
     return true;
   if (Style.Language == FormatStyle::LK_ObjC &&
+      Style.ObjCBreakBeforeNestedBlockParam &&
       Current.ObjCSelectorNameParts > 1 &&
       Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
     return true;

diff  --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp
index edbf092d0421..42e2a80783be 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -1420,6 +1420,10 @@ TEST_F(FormatTestObjC, BreakLineBeforeNestedBlockParam) {
                "*b, NSNumber *c) {\n"
                "  b = c;\n"
                "}]");
+  verifyFormat("[self.test1 t:self w:self callback:^(typeof(self) self, "
+               "NSNumber *u, NSNumber *v) {\n"
+               "  u = v;\n"
+               "} z:self]");
 
   Style.ColumnLimit = 80;
   verifyFormat(


        


More information about the cfe-commits mailing list