[PATCH] D36143: [clang-format] Fix indent of 'key <...>' in text protos

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 2 04:37:38 PDT 2017


krasimir updated this revision to Diff 109322.
krasimir added a comment.

- Fix similar issue for 'key {...}'


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,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: unittests/Format/FormatTestProto.cpp
===================================================================
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -356,6 +356,19 @@
                "  }\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"
+               ">;");
+
+  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: 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->isOneOf(TT_TemplateOpener, tok::l_brace))))
     return State.Stack.back().Indent;
   if (NextNonComment->is(TT_ObjCStringLiteral) &&
       State.StartOfStringLiteral != 0)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36143.109322.patch
Type: text/x-patch
Size: 3521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170802/6f23297e/attachment-0001.bin>


More information about the cfe-commits mailing list