This revision was automatically updated to reflect the committed changes. Closed by commit rL309941: [clang-format] Fix indent of 'key <...>' and 'key {...}' in text protos (authored by krasimir).
Repository: rL LLVM https://reviews.llvm.org/D36143 Files: cfe/trunk/lib/Format/ContinuationIndenter.cpp cfe/trunk/unittests/Format/FormatTestProto.cpp cfe/trunk/unittests/Format/FormatTestTextProto.cpp Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp =================================================================== --- cfe/trunk/lib/Format/ContinuationIndenter.cpp +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp @@ -731,7 +731,10 @@ 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) Index: cfe/trunk/unittests/Format/FormatTestProto.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestProto.cpp +++ cfe/trunk/unittests/Format/FormatTestProto.cpp @@ -361,6 +361,19 @@ " 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) { Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestTextProto.cpp +++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp @@ -245,6 +245,50 @@ ">\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
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp =================================================================== --- cfe/trunk/lib/Format/ContinuationIndenter.cpp +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp @@ -731,7 +731,10 @@ 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) Index: cfe/trunk/unittests/Format/FormatTestProto.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestProto.cpp +++ cfe/trunk/unittests/Format/FormatTestProto.cpp @@ -361,6 +361,19 @@ " 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) { Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestTextProto.cpp +++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp @@ -245,6 +245,50 @@ ">\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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits