r309941 - [clang-format] Fix indent of 'key <...>' and 'key {...}' in text protos
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 3 07:17:29 PDT 2017
Author: krasimir
Date: Thu Aug 3 07:17:29 2017
New Revision: 309941
URL: http://llvm.org/viewvc/llvm-project?rev=309941&view=rev
Log:
[clang-format] Fix indent of 'key <...>' and 'key {...}' in text protos
Summary:
This patch fixes the indentation of the code pattern `key <...>`and `key {...}` in text protos.
Previously, such line would be alinged depending on the column of the previous
colon, which usually indents too much.
I'm gonna go ahead and commit this since it's a straightforward bugfix.
Reviewers: djasper, klimek
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D36143
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=309941&r1=309940&r2=309941&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Aug 3 07:17:29 2017
@@ -731,7 +731,10 @@ unsigned ContinuationIndenter::getNewLin
if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
return State.Stack[State.Stack.size() - 2].LastSpace;
if (Current.is(tok::identifier) && Current.Next &&
- Current.Next->is(TT_DictLiteral))
+ (Current.Next->is(TT_DictLiteral) ||
+ ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+ Current.Next->isOneOf(TT_TemplateOpener, tok::l_brace))))
return State.Stack.back().Indent;
if (NextNonComment->is(TT_ObjCStringLiteral) &&
State.StartOfStringLiteral != 0)
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=309941&r1=309940&r2=309941&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Aug 3 07:17:29 2017
@@ -361,6 +361,19 @@ TEST_F(FormatTestProto, FormatsOptions)
" data1 <key1: value1>\n"
" data2 {key2: value2}\n"
">;");
+
+ verifyFormat("option (MyProto.options) = <\n"
+ " app_id: 'com.javax.swing.salsa.latino'\n"
+ " head_id: 1\n"
+ " data <key: value>\n"
+ ">;");
+
+ verifyFormat("option (MyProto.options) = {\n"
+ " app_id: 'com.javax.swing.salsa.latino'\n"
+ " head_id: 1\n"
+ " headheadheadheadheadhead_id: 1\n"
+ " product_data {product {1}}\n"
+ "};");
}
TEST_F(FormatTestProto, FormatsService) {
Modified: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestTextProto.cpp?rev=309941&r1=309940&r2=309941&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp Thu Aug 3 07:17:29 2017
@@ -245,6 +245,50 @@ TEST_F(FormatTestTextProto, SupportsAngl
">\n"
"field: OK,\n"
"field_c <field <field <>>>");
+
+ verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+ "head_id: 1\n"
+ "data <key: value>");
+
+ verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+ "head_id: 1\n"
+ "data <key: value>\n"
+ "tail_id: 2");
+
+ verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+ "head_id: 1\n"
+ "data <key: value>\n"
+ "data {key: value}");
+
+ verifyFormat("app {\n"
+ " app_id: 'com.javax.swing.salsa.latino'\n"
+ " head_id: 1\n"
+ " data <key: value>\n"
+ "}");
+
+ verifyFormat("app: {\n"
+ " app_id: 'com.javax.swing.salsa.latino'\n"
+ " head_id: 1\n"
+ " data <key: value>\n"
+ "}");
+
+ verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+ "headheadheadheadheadhead_id: 1\n"
+ "product_data {product {1}}");
+
+ verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+ "headheadheadheadheadhead_id: 1\n"
+ "product_data <product {1}>");
+
+ verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
+ "headheadheadheadheadhead_id: 1\n"
+ "product_data <product <1>>");
+
+ verifyFormat("app <\n"
+ " app_id: 'com.javax.swing.salsa.latino'\n"
+ " headheadheadheadheadhead_id: 1\n"
+ " product_data <product {1}>\n"
+ ">");
}
} // end namespace tooling
} // end namespace clang
More information about the cfe-commits
mailing list