Skip to content

Commit

Permalink
[ClangFormat] IndentWrappedFunctionNames should be true in the google…
Browse files Browse the repository at this point in the history
… ObjC style

Summary:
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

Reviewers: krasimir, djasper, klimek

Reviewed By: djasper

Subscribers: cfe-commits, thakis

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

llvm-svn: 320714
  • Loading branch information
bhamiltoncx committed Dec 14, 2017
1 parent 3d161ab commit 687e5fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions clang/lib/Format/Format.cpp
Expand Up @@ -732,6 +732,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
GoogleStyle.SpacesInContainerLiterals = false;
} else if (Language == FormatStyle::LK_ObjC) {
GoogleStyle.ColumnLimit = 100;
GoogleStyle.IndentWrappedFunctionNames = true;
}

return GoogleStyle;
Expand Down
7 changes: 5 additions & 2 deletions clang/unittests/Format/FormatTestObjC.cpp
Expand Up @@ -382,9 +382,9 @@ TEST_F(FormatTestObjC, FormatObjCMethodDeclarations) {
" ofSize:(size_t)height\n"
" :(size_t)width;");

Style = getGoogleStyle(FormatStyle::LK_ObjC);
// 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"
Expand All @@ -395,7 +395,10 @@ TEST_F(FormatTestObjC, FormatObjCMethodDeclarations) {
verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
" aShortf:(NSRect)theRect {\n"
"}");

// Wrapped method parameters should be indented.
verifyFormat("- (LongReturnTypeName)\n"
" longParam:(ParamName)longParamName\n"
" param:(paramName)paramName;");
// Format pairs correctly.
Style.ColumnLimit = 80;
verifyFormat("- (void)drawRectOn:(id)surface\n"
Expand Down

0 comments on commit 687e5fa

Please sign in to comment.