r214084 - clang-format: [proto] Improve formatting of text-proto options.
Daniel Jasper
djasper at google.com
Mon Jul 28 07:08:09 PDT 2014
Author: djasper
Date: Mon Jul 28 09:08:09 2014
New Revision: 214084
URL: http://llvm.org/viewvc/llvm-project?rev=214084&view=rev
Log:
clang-format: [proto] Improve formatting of text-proto options.
Initial patch and tests by Kaushik Sridharan, thank you!
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=214084&r1=214083&r2=214084&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jul 28 09:08:09 2014
@@ -150,7 +150,8 @@ bool ContinuationIndenter::mustBreak(con
Previous.Type != TT_InlineASMColon &&
Previous.Type != TT_ConditionalExpr && nextIsMultilineString(State))
return true;
- if (((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||
+ if (Style.Language != FormatStyle::LK_Proto &&
+ ((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||
Previous.Type == TT_ArrayInitializerLSquare) &&
Style.ColumnLimit > 0 &&
getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State))
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=214084&r1=214083&r2=214084&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jul 28 09:08:09 2014
@@ -311,8 +311,7 @@ private:
if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))
return false;
updateParameterCount(Left, CurrentToken);
- if (CurrentToken->is(tok::colon) &&
- Style.Language != FormatStyle::LK_Proto) {
+ if (CurrentToken->is(tok::colon)) {
if (CurrentToken->getPreviousNonComment()->is(tok::identifier))
CurrentToken->getPreviousNonComment()->Type = TT_SelectorName;
Left->Type = TT_DictLiteral;
@@ -1683,6 +1682,9 @@ bool TokenAnnotator::mustBreakBefore(con
} else if (isAllmanBrace(Left) || isAllmanBrace(Right)) {
return Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
Style.BreakBeforeBraces == FormatStyle::BS_GNU;
+ } else if (Style.Language == FormatStyle::LK_Proto &&
+ Left.isNot(tok::l_brace) && Right.Type == TT_SelectorName) {
+ return true;
}
// If the last token before a '}' is a comma or a comment, the intention is to
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=214084&r1=214083&r2=214084&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Mon Jul 28 09:08:09 2014
@@ -98,8 +98,27 @@ TEST_F(FormatTestProto, MessageFieldAttr
}
TEST_F(FormatTestProto, FormatsOptions) {
- verifyFormat("option java_package = \"my.test.package\";");
- verifyFormat("option (my_custom_option) = \"abc\";");
+ verifyFormat("option (MyProto.options) = {\n"
+ " field_a: OK\n"
+ " field_b: \"OK\"\n"
+ " field_c: \"OK\"\n"
+ " msg_field: {field_d: 123}\n"
+ "};");
+
+ verifyFormat("option (MyProto.options) = {\n"
+ " field_a: OK\n"
+ " field_b: \"OK\"\n"
+ " field_c: \"OK\"\n"
+ " msg_field: {field_d: 123\n"
+ " field_e: OK}\n"
+ "};");
+
+ verifyFormat("option (MyProto.options) = {\n"
+ " field_a: OK // Comment\n"
+ " field_b: \"OK\"\n"
+ " field_c: \"OK\"\n"
+ " msg_field: {field_d: 123}\n"
+ "};");
}
TEST_F(FormatTestProto, FormatsService) {
More information about the cfe-commits
mailing list