From: Daniel Jasper Date: Fri, 8 Nov 2013 02:08:01 +0000 (+0000) Subject: clang-format: Properly indent ObjC calls wrapped before first selector X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=072ac6cfde19fb395d434b2bbcb66e210607cf1e;p=clang clang-format: Properly indent ObjC calls wrapped before first selector Before: [self // break a:a aa:aa aaaaa:aaa]; After: [self // break a:a aa:aa aaaaa:aaa]; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194241 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 442f9fa850..d075c7482d 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -375,7 +375,11 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, State.Line->StartsDefinition))) { State.Column = State.Stack.back().Indent; } else if (Current.Type == TT_ObjCSelectorName) { - if (State.Stack.back().ColonPos > Current.ColumnWidth) { + if (State.Stack.back().ColonPos == 0) { + State.Stack.back().ColonPos = + State.Stack.back().Indent + Current.LongestObjCSelectorName; + State.Column = State.Stack.back().ColonPos - Current.ColumnWidth; + } else if (State.Stack.back().ColonPos > Current.ColumnWidth) { State.Column = State.Stack.back().ColonPos - Current.ColumnWidth; } else { State.Column = State.Stack.back().Indent; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e6757c5d2a..776bf49a4a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5474,6 +5474,9 @@ TEST_F(FormatTest, FormatObjCMethodExpr) { "[self aaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa];"); + verifyFormat("[self // break\n" + " a:a\n" + " aaa:aaa];"); } TEST_F(FormatTest, ObjCAt) {