r235707 - clang-format: Don't wrap after short first segments of builder calls.
Daniel Jasper
djasper at google.com
Fri Apr 24 03:08:09 PDT 2015
Author: djasper
Date: Fri Apr 24 05:08:09 2015
New Revision: 235707
URL: http://llvm.org/viewvc/llvm-project?rev=235707&view=rev
Log:
clang-format: Don't wrap after short first segments of builder calls.
Before:
a()
.aaaaa()
.aaaaa()
.aaaaa();
After:
a().aaaaa()
.aaaaa()
.aaaaa();
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=235707&r1=235706&r2=235707&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Apr 24 05:08:09 2015
@@ -319,7 +319,8 @@ void ContinuationIndenter::addTokenOnCur
State.Stack.back().Indent = State.Column + Spaces;
if (State.Stack.back().AvoidBinPacking && startsNextParameter(Current, Style))
State.Stack.back().NoLineBreak = true;
- if (startsSegmentOfBuilderTypeCall(Current))
+ if (startsSegmentOfBuilderTypeCall(Current) &&
+ State.Column > getNewLineColumn(State))
State.Stack.back().ContainsUnwrappedBuilder = true;
if (Current.is(TT_LambdaArrow))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=235707&r1=235706&r2=235707&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Apr 24 05:08:09 2015
@@ -4154,6 +4154,18 @@ TEST_F(FormatTest, FormatsBuilderPattern
" ->aaaaaaaaaaaaaae(0)\n"
" ->aaaaaaaaaaaaaaa();");
+ // Don't linewrap after very short segments.
+ verifyFormat("a().aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
+ " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
+ " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();");
+ verifyFormat("aa().aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
+ " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
+ " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();");
+ verifyFormat("aaa()\n"
+ " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
+ " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
+ " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();");
+
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaa()\n"
" .aaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
" .has<bbbbbbbbbbbbbbbbbbbbb>();");
More information about the cfe-commits
mailing list