[PATCH] D41195: [ClangFormat] IndentWrappedFunctionNames should be true in the google ObjC style

Ben Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 12:52:11 PST 2017


benhamilton created this revision.
benhamilton added reviewers: krasimir, djasper, klimek.
Herald added a subscriber: cfe-commits.

If we write the following code, it goes over 100 columns, so we need to wrap it:

- (VeryLongReturnTypeName)veryLongMethodParameter:(VeryLongParameterName)thisIsAVeryLongParameterName longMethodParameter:(LongParameterName)thisIsAlsoAnotherLongParameterName;

Currently, clang-format with the google style aligns the method parameter names on the first column:

- (VeryLongReturnTypeName)

veryLongMethodParameter:(VeryLongParameterName)thisIsAVeryLongParameterName

  longMethodParameter:(LongParameterName)thisIsAlsoAnotherLongParameterName;

We'd like clang-format in the google style to align these to column 4 for Objective-C:

- (VeryLongReturnTypeName) veryLongMethodParameter:(VeryLongParameterName)thisIsAVeryLongParameterName longMethodParameter:(LongParameterName)thisIsAlsoAnotherLongParameterName;

Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D41195

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===================================================================
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -229,6 +229,7 @@
   verifyFormat("@interface Foo (HackStuff)<MyProtocol>\n"
                "+ (id)init;\n"
                "@end");
+
   Style.BinPackParameters = false;
   Style.ColumnLimit = 80;
   verifyFormat("@interface aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ()<\n"
@@ -382,9 +383,15 @@
                "            ofSize:(size_t)height\n"
                "                  :(size_t)width;");
 
+  Style = getGoogleStyle(FormatStyle::LK_ObjC);
+  // Wrapped method parameters should be indented.
+  verifyFormat("- (VeryLongReturnTypeName)\n"
+               "    veryLongMethodParameter:(VeryLongParameterName)"
+               "thisIsAVeryLongParameterName\n"
+               "        longMethodParameter:(LongParameterName)"
+               "thisIsAlsoAnotherLongParameterName;");
   // Continuation indent width should win over aligning colons if the function
   // name is long.
-  Style = getGoogleStyle(FormatStyle::LK_ObjC);
   Style.ColumnLimit = 40;
   Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -732,6 +732,7 @@
     GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
     GoogleStyle.ColumnLimit = 100;
+    GoogleStyle.IndentWrappedFunctionNames = true;
   }
 
   return GoogleStyle;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41195.126815.patch
Type: text/x-patch
Size: 1642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171213/519a54db/attachment.bin>


More information about the cfe-commits mailing list