krasimir created this revision. Herald added a subscriber: klimek. This patch fixes the indentation of the code pattern `key <...>` in text protos. Previously, such line would be alinged depending on the column of the previous colon, which usually indents too much.
https://reviews.llvm.org/D36143 Files: lib/Format/ContinuationIndenter.cpp unittests/Format/FormatTestProto.cpp unittests/Format/FormatTestTextProto.cpp Index: unittests/Format/FormatTestTextProto.cpp =================================================================== --- unittests/Format/FormatTestTextProto.cpp +++ unittests/Format/FormatTestTextProto.cpp @@ -245,6 +245,10 @@ ">\n" "field: OK,\n" "field_c <field <field <>>>"); + + verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n" + "head_id: 1\n" + "data <key: value>"); } } // end namespace tooling } // end namespace clang Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -356,6 +356,12 @@ " }\n" " field_g: OK\n" ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " app_id: 'com.javax.swing.salsa.latino'\n" + " head_id: 1\n" + " data <key: value>\n" + ">;"); } TEST_F(FormatTestProto, FormatsService) { Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ 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->is(TT_TemplateOpener)))) return State.Stack.back().Indent; if (NextNonComment->is(TT_ObjCStringLiteral) && State.StartOfStringLiteral != 0)
Index: unittests/Format/FormatTestTextProto.cpp =================================================================== --- unittests/Format/FormatTestTextProto.cpp +++ unittests/Format/FormatTestTextProto.cpp @@ -245,6 +245,10 @@ ">\n" "field: OK,\n" "field_c <field <field <>>>"); + + verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n" + "head_id: 1\n" + "data <key: value>"); } } // end namespace tooling } // end namespace clang Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -356,6 +356,12 @@ " }\n" " field_g: OK\n" ">;"); + + verifyFormat("option (MyProto.options) = <\n" + " app_id: 'com.javax.swing.salsa.latino'\n" + " head_id: 1\n" + " data <key: value>\n" + ">;"); } TEST_F(FormatTestProto, FormatsService) { Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ 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->is(TT_TemplateOpener)))) return State.Stack.back().Indent; if (NextNonComment->is(TT_ObjCStringLiteral) && State.StartOfStringLiteral != 0)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits