State.Column += Current.ColumnWidth;
State.NextToken = State.NextToken->Next;
- unsigned Penalty = handleEndOfLine(Current, State, DryRun, AllowBreak);
+ unsigned Penalty =
+ handleEndOfLine(Current, State, DryRun, AllowBreak, Newline);
if (Current.Role)
Current.Role->formatFromToken(State, this, DryRun);
unsigned ContinuationIndenter::reformatRawStringLiteral(
const FormatToken &Current, LineState &State,
- const FormatStyle &RawStringStyle, bool DryRun) {
+ const FormatStyle &RawStringStyle, bool DryRun, bool Newline) {
unsigned StartColumn = State.Column - Current.ColumnWidth;
StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText);
StringRef NewDelimiter =
// source.
bool ContentStartsOnNewline = Current.TokenText[OldPrefixSize] == '\n';
// If this token is the last parameter (checked by looking if it's followed by
- // `)`, the base the indent off the line's nested block indent. Otherwise,
- // base the indent off the arguments indent, so we can achieve:
+ // `)` and is not on a newline, the base the indent off the line's nested
+ // block indent. Otherwise, base the indent off the arguments indent, so we
+ // can achieve:
+ //
// fffffffffff(1, 2, 3, R"pb(
// key1: 1 #
// key2: 2)pb");
// R"pb(
// key1: 1 #
// key2: 2
+ // )pb");
+ //
+ // fffffffffff(1, 2, 3,
+ // R"pb(
+ // key1: 1 #
+ // key2: 2
// )pb",
// 5);
- unsigned CurrentIndent = (Current.Next && Current.Next->is(tok::r_paren))
- ? State.Stack.back().NestedBlockIndent
- : State.Stack.back().Indent;
+ unsigned CurrentIndent =
+ (!Newline && Current.Next && Current.Next->is(tok::r_paren))
+ ? State.Stack.back().NestedBlockIndent
+ : State.Stack.back().Indent;
unsigned NextStartColumn = ContentStartsOnNewline
? CurrentIndent + Style.IndentWidth
: FirstStartColumn;
unsigned ContinuationIndenter::handleEndOfLine(const FormatToken &Current,
LineState &State, bool DryRun,
- bool AllowBreak) {
+ bool AllowBreak, bool Newline) {
unsigned Penalty = 0;
// Compute the raw string style to use in case this is a raw string literal
// that can be reformatted.
auto RawStringStyle = getRawStringStyle(Current, State);
if (RawStringStyle && !Current.Finalized) {
- Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun);
+ Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun,
+ Newline);
} else if (Current.IsMultiline && Current.isNot(TT_BlockComment)) {
// Don't break multi-line tokens other than block comments and raw string
// literals. Instead, just update the state.
unsigned reformatRawStringLiteral(const FormatToken &Current,
LineState &State,
const FormatStyle &RawStringStyle,
- bool DryRun);
+ bool DryRun, bool Newline);
/// If the current token is at the end of the current line, handle
/// the transition to the next line.
unsigned handleEndOfLine(const FormatToken &Current, LineState &State,
- bool DryRun, bool AllowBreak);
+ bool DryRun, bool AllowBreak, bool Newline);
/// If \p Current is a raw string that is configured to be reformatted,
/// return the style to be used.