From: Daniel Jasper Date: Fri, 24 Apr 2015 10:08:09 +0000 (+0000) Subject: clang-format: Don't wrap after short first segments of builder calls. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=521c1564ade11adfac2042985ccebeb713bfaddb;p=clang clang-format: Don't wrap after short first segments of builder calls. Before: a() .aaaaa() .aaaaa() .aaaaa(); After: a().aaaaa() .aaaaa() .aaaaa(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235707 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index b03a99a248..9e1014e567 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -319,7 +319,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, 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)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a891ba2a67..b23778aaba 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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();");