summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2017-05-15 11:15:29 +0000
committerMartin Probst <martin@probst.io>2017-05-15 11:15:29 +0000
commit2c1cdae2dfe5b9aa4eceb9e76fa52bf621cc66aa (patch)
treefcb10919adfdbd37e0c505938fe5872c9d4e6818 /clang/lib/Format/ContinuationIndenter.cpp
parent4ab5193735ca202b7c01f3c29765dd35bc573eb1 (diff)
downloadbcm5719-llvm-2c1cdae2dfe5b9aa4eceb9e76fa52bf621cc66aa.tar.gz
bcm5719-llvm-2c1cdae2dfe5b9aa4eceb9e76fa52bf621cc66aa.zip
JavaScript allows parameter lists to include trailing commas:
myFunction(param1, param2,); For symmetry with other parenthesized lists ([...], {...}), clang-format should wrap parenthesized lists one-per-line if they contain a trailing comma: myFunction( param1, param2, ); This is particularly useful in function declarations or calls with many arguments, e.g. commonly in constructors. Differential Revision: https://reviews.llvm.org/D33023 llvm-svn: 303049
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 709eeb1539a..488f9dd582f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -674,6 +674,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
return State.Stack[State.Stack.size() - 2].LastSpace;
return State.FirstIndent;
}
+ if (Current.is(tok::r_paren) && State.Stack.size() > 1)
+ return State.Stack[State.Stack.size() - 2].LastSpace;
if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
return State.Stack[State.Stack.size() - 2].LastSpace;
if (Current.is(tok::identifier) && Current.Next &&
@@ -1038,13 +1040,20 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
NestedBlockIndent = Column;
}
+ bool EndsInComma =
+ Current.MatchingParen &&
+ Current.MatchingParen->getPreviousNonComment() &&
+ Current.MatchingParen->getPreviousNonComment()->is(tok::comma);
+
AvoidBinPacking =
+ (Style.Language == FormatStyle::LK_JavaScript && EndsInComma) ||
(State.Line->MustBeDeclaration && !Style.BinPackParameters) ||
(!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||
(Style.ExperimentalAutoDetectBinPacking &&
(Current.PackingKind == PPK_OnePerLine ||
(!BinPackInconclusiveFunctions &&
Current.PackingKind == PPK_Inconclusive)));
+
if (Current.is(TT_ObjCMethodExpr) && Current.MatchingParen) {
if (Style.ColumnLimit) {
// If this '[' opens an ObjC call, determine whether all parameters fit
@@ -1065,6 +1074,9 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
}
}
}
+
+ if (Style.Language == FormatStyle::LK_JavaScript && EndsInComma)
+ BreakBeforeParameter = true;
}
// Generally inherit NoLineBreak from the current scope to nested scope.
// However, don't do this for non-empty nested blocks, dict literals and
OpenPOWER on IntegriCloud