|
@@ -66,6 +66,16 @@ static bool startsNextParameter(const FormatToken &Current,
|
|
!Style.BreakBeforeInheritanceComma));
|
|
!Style.BreakBeforeInheritanceComma));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static bool opensProtoMessageField(const FormatToken &LessTok,
|
|
|
|
+ const FormatStyle &Style) {
|
|
|
|
+ if (LessTok.isNot(tok::less))
|
|
|
|
+ return false;
|
|
|
|
+ return Style.Language == FormatStyle::LK_TextProto ||
|
|
|
|
+ (Style.Language == FormatStyle::LK_Proto &&
|
|
|
|
+ (LessTok.NestingLevel > 0 ||
|
|
|
|
+ (LessTok.Previous && LessTok.Previous->is(tok::equal))));
|
|
|
|
+}
|
|
|
|
+
|
|
ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
|
|
ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
|
|
const AdditionalKeywords &Keywords,
|
|
const AdditionalKeywords &Keywords,
|
|
const SourceManager &SourceMgr,
|
|
const SourceManager &SourceMgr,
|
|
@@ -94,6 +104,13 @@ LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
|
|
State.LowestLevelOnLine = 0;
|
|
State.LowestLevelOnLine = 0;
|
|
State.IgnoreStackForComparison = false;
|
|
State.IgnoreStackForComparison = false;
|
|
|
|
|
|
|
|
+ if (Style.Language == FormatStyle::LK_TextProto) {
|
|
|
|
+ // We need this in order to deal with the bin packing of text fields at
|
|
|
|
+ // global scope.
|
|
|
|
+ State.Stack.back().AvoidBinPacking = true;
|
|
|
|
+ State.Stack.back().BreakBeforeParameter = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
// The first token has already been indented and thus consumed.
|
|
// The first token has already been indented and thus consumed.
|
|
moveStateToNextToken(State, DryRun, /*Newline=*/false);
|
|
moveStateToNextToken(State, DryRun, /*Newline=*/false);
|
|
return State;
|
|
return State;
|
|
@@ -176,7 +193,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
|
|
return true;
|
|
return true;
|
|
if (((Previous.is(TT_DictLiteral) && Previous.is(tok::l_brace)) ||
|
|
if (((Previous.is(TT_DictLiteral) && Previous.is(tok::l_brace)) ||
|
|
(Previous.is(TT_ArrayInitializerLSquare) &&
|
|
(Previous.is(TT_ArrayInitializerLSquare) &&
|
|
- Previous.ParameterCount > 1)) &&
|
|
|
|
|
|
+ Previous.ParameterCount > 1) ||
|
|
|
|
+ opensProtoMessageField(Previous, Style)) &&
|
|
Style.ColumnLimit > 0 &&
|
|
Style.ColumnLimit > 0 &&
|
|
getLengthToMatchingParen(Previous) + State.Column - 1 >
|
|
getLengthToMatchingParen(Previous) + State.Column - 1 >
|
|
getColumnLimit(State))
|
|
getColumnLimit(State))
|
|
@@ -501,13 +519,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static bool lessOpensProtoMessageField(const FormatToken &LessTok,
|
|
|
|
- const LineState &State) {
|
|
|
|
- assert(LessTok.is(tok::less));
|
|
|
|
- return LessTok.NestingLevel > 0 ||
|
|
|
|
- (LessTok.Previous && LessTok.Previous->is(tok::equal));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
|
unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
|
bool DryRun) {
|
|
bool DryRun) {
|
|
FormatToken &Current = *State.NextToken;
|
|
FormatToken &Current = *State.NextToken;
|
|
@@ -650,9 +661,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
|
// before the corresponding } or ].
|
|
// before the corresponding } or ].
|
|
if (PreviousNonComment &&
|
|
if (PreviousNonComment &&
|
|
(PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
|
|
(PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
|
|
- (Style.Language == FormatStyle::LK_Proto &&
|
|
|
|
- PreviousNonComment->is(tok::less) &&
|
|
|
|
- lessOpensProtoMessageField(*PreviousNonComment, State)) ||
|
|
|
|
|
|
+ opensProtoMessageField(*PreviousNonComment, Style) ||
|
|
(PreviousNonComment->is(TT_TemplateString) &&
|
|
(PreviousNonComment->is(TT_TemplateString) &&
|
|
PreviousNonComment->opensScope())))
|
|
PreviousNonComment->opensScope())))
|
|
State.Stack.back().BreakBeforeClosingBrace = true;
|
|
State.Stack.back().BreakBeforeClosingBrace = true;
|
|
@@ -695,7 +704,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
|
|
return Current.NestingLevel == 0 ? State.FirstIndent
|
|
return Current.NestingLevel == 0 ? State.FirstIndent
|
|
: State.Stack.back().Indent;
|
|
: State.Stack.back().Indent;
|
|
if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
|
|
if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
|
|
- (Current.is(tok::greater) && Style.Language == FormatStyle::LK_Proto)) &&
|
|
|
|
|
|
+ (Current.is(tok::greater) &&
|
|
|
|
+ (Style.Language == FormatStyle::LK_Proto ||
|
|
|
|
+ Style.Language == FormatStyle::LK_TextProto))) &&
|
|
State.Stack.size() > 1) {
|
|
State.Stack.size() > 1) {
|
|
if (Current.closesBlockOrBlockTypeList(Style))
|
|
if (Current.closesBlockOrBlockTypeList(Style))
|
|
return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
|
|
return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
|
|
@@ -1050,8 +1061,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
|
|
unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall,
|
|
unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall,
|
|
State.Stack.back().NestedBlockIndent);
|
|
State.Stack.back().NestedBlockIndent);
|
|
if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
|
|
if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
|
|
- (Style.Language == FormatStyle::LK_Proto && Current.is(tok::less) &&
|
|
|
|
- lessOpensProtoMessageField(Current, State))) {
|
|
|
|
|
|
+ opensProtoMessageField(Current, Style)) {
|
|
if (Current.opensBlockOrBlockTypeList(Style)) {
|
|
if (Current.opensBlockOrBlockTypeList(Style)) {
|
|
NewIndent = Style.IndentWidth +
|
|
NewIndent = Style.IndentWidth +
|
|
std::min(State.Column, State.Stack.back().NestedBlockIndent);
|
|
std::min(State.Column, State.Stack.back().NestedBlockIndent);
|
|
@@ -1064,7 +1074,9 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
|
|
Current.MatchingParen->Previous->is(tok::comma);
|
|
Current.MatchingParen->Previous->is(tok::comma);
|
|
AvoidBinPacking =
|
|
AvoidBinPacking =
|
|
EndsInComma || Current.is(TT_DictLiteral) ||
|
|
EndsInComma || Current.is(TT_DictLiteral) ||
|
|
- Style.Language == FormatStyle::LK_Proto || !Style.BinPackArguments ||
|
|
|
|
|
|
+ Style.Language == FormatStyle::LK_Proto ||
|
|
|
|
+ Style.Language == FormatStyle::LK_TextProto ||
|
|
|
|
+ !Style.BinPackArguments ||
|
|
(NextNoComment &&
|
|
(NextNoComment &&
|
|
NextNoComment->isOneOf(TT_DesignatedInitializerPeriod,
|
|
NextNoComment->isOneOf(TT_DesignatedInitializerPeriod,
|
|
TT_DesignatedInitializerLSquare));
|
|
TT_DesignatedInitializerLSquare));
|