@@ -56,6 +56,8 @@ static bool startsNextParameter(const FormatToken &Current,
56
56
if (Current.is (TT_CtorInitializerComma) &&
57
57
Style .BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
58
58
return true ;
59
+ if (Style .Language == FormatStyle::LK_Proto && Current.is (TT_SelectorName))
60
+ return true ;
59
61
return Previous.is (tok::comma) && !Current.isTrailingComment () &&
60
62
((Previous.isNot (TT_CtorInitializerComma) ||
61
63
Style .BreakConstructorInitializers !=
@@ -499,6 +501,13 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
499
501
}
500
502
}
501
503
504
+ static bool lessOpensProtoMessageField (const FormatToken &LessTok,
505
+ const LineState &State) {
506
+ assert (LessTok.is (tok::less));
507
+ return LessTok.NestingLevel > 0 ||
508
+ (LessTok.Previous && LessTok.Previous ->is (tok::equal));
509
+ }
510
+
502
511
unsigned ContinuationIndenter::addTokenOnNewLine (LineState &State,
503
512
bool DryRun) {
504
513
FormatToken &Current = *State.NextToken ;
@@ -641,6 +650,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
641
650
// before the corresponding } or ].
642
651
if (PreviousNonComment &&
643
652
(PreviousNonComment->isOneOf (tok::l_brace, TT_ArrayInitializerLSquare) ||
653
+ (Style .Language == FormatStyle::LK_Proto &&
654
+ PreviousNonComment->is (tok::less) &&
655
+ lessOpensProtoMessageField (*PreviousNonComment, State)) ||
644
656
(PreviousNonComment->is (TT_TemplateString) &&
645
657
PreviousNonComment->opensScope ())))
646
658
State.Stack .back ().BreakBeforeClosingBrace = true ;
@@ -682,7 +694,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
682
694
if (NextNonComment->is (tok::l_brace) && NextNonComment->BlockKind == BK_Block)
683
695
return Current.NestingLevel == 0 ? State.FirstIndent
684
696
: State.Stack .back ().Indent ;
685
- if (Current.isOneOf (tok::r_brace, tok::r_square) && State.Stack .size () > 1 ) {
697
+ if ((Current.isOneOf (tok::r_brace, tok::r_square) ||
698
+ (Current.is (tok::greater) && Style .Language == FormatStyle::LK_Proto)) &&
699
+ State.Stack .size () > 1 ) {
686
700
if (Current.closesBlockOrBlockTypeList (Style ))
687
701
return State.Stack [State.Stack .size () - 2 ].NestedBlockIndent ;
688
702
if (Current.MatchingParen &&
@@ -1035,7 +1049,9 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
1035
1049
bool BreakBeforeParameter = false ;
1036
1050
unsigned NestedBlockIndent = std::max (State.Stack .back ().StartOfFunctionCall ,
1037
1051
State.Stack .back ().NestedBlockIndent );
1038
- if (Current.isOneOf (tok::l_brace, TT_ArrayInitializerLSquare)) {
1052
+ if (Current.isOneOf (tok::l_brace, TT_ArrayInitializerLSquare) ||
1053
+ (Style .Language == FormatStyle::LK_Proto && Current.is (tok::less) &&
1054
+ lessOpensProtoMessageField (Current, State))) {
1039
1055
if (Current.opensBlockOrBlockTypeList (Style )) {
1040
1056
NewIndent = Style .IndentWidth +
1041
1057
std::min (State.Column , State.Stack .back ().NestedBlockIndent );
0 commit comments