diff options
author | Martin Probst <martin@probst.io> | 2017-08-29 08:30:07 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-08-29 08:30:07 +0000 |
commit | c10d97f9244493e0f62cb0b1654c645888c2fe57 (patch) | |
tree | f1d649e76bd8899bf0adb83bd53972c521f39e1c /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 5bea524091732564151d2a0b0e77dafa1c3cad2b (diff) | |
download | bcm5719-llvm-c10d97f9244493e0f62cb0b1654c645888c2fe57.tar.gz bcm5719-llvm-c10d97f9244493e0f62cb0b1654c645888c2fe57.zip |
clang-format: [JS] simplify template string wrapping.
Summary:
Previously, clang-format would try to wrap template string substitutions
by indenting relative to the openening `${`. This helped with
indenting structured strings, such as strings containing HTML, as the
substitutions would be aligned according to the structure of the string.
However it turns out that the overwhelming majority of template string +
substitution usages are for substitutions into non-structured strings,
e.g. URLs or just plain messages. For these situations, clang-format
would often produce very ugly indents, in particular for strings
containing no line breaks:
return `<a href='http://google3/${file}?l=${row}'>${file}</a>(${
row
},${
col
}): `;
This change makes clang-format indent template string substitutions as
if they were string concatenation operations. It wraps +4 on overlong
lines and keeps all operands on the same line:
return `<a href='http://google3/${file}?l=${row}'>${file}</a>(${
row},${col}): `;
While this breaks some lexical continuity between the `${` and `row}`
here, the overall effects are still a huge improvement, and users can
still manually break the string using `+` if desired.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D37142
llvm-svn: 311988
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index d8ae82c1843..15b67634edd 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -661,9 +661,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, // before the corresponding } or ]. if (PreviousNonComment && (PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) || - opensProtoMessageField(*PreviousNonComment, Style) || - (PreviousNonComment->is(TT_TemplateString) && - PreviousNonComment->opensScope()))) + opensProtoMessageField(*PreviousNonComment, Style))) State.Stack.back().BreakBeforeClosingBrace = true; if (State.Stack.back().AvoidBinPacking) { @@ -925,11 +923,6 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, moveStatePastFakeLParens(State, Newline); moveStatePastScopeCloser(State); - if (Current.is(TT_TemplateString) && Current.opensScope()) - State.Stack.back().LastSpace = - (Current.IsMultiline ? Current.LastLineColumnWidth - : State.Column + Current.ColumnWidth) - - strlen("${"); bool CanBreakProtrudingToken = !State.Stack.back().NoLineBreak && !State.Stack.back().NoLineBreakInOperand; moveStatePastScopeOpener(State, Newline); @@ -1101,18 +1094,6 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, LastSpace = std::max(LastSpace, State.Stack.back().Indent); } - // JavaScript template strings are special as we always want to indent - // nested expressions relative to the ${}. Otherwise, this can create quite - // a mess. - if (Current.is(TT_TemplateString)) { - unsigned Column = Current.IsMultiline - ? Current.LastLineColumnWidth - : State.Column + Current.ColumnWidth; - NewIndent = Column; - LastSpace = Column; - NestedBlockIndent = Column; - } - bool EndsInComma = Current.MatchingParen && Current.MatchingParen->getPreviousNonComment() && |