summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp6
-rw-r--r--clang/unittests/Format/FormatTestProto.cpp13
2 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 767096b60ef..d78a37532fe 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1570,8 +1570,10 @@ private:
const FormatToken *NextNonComment = Current->getNextNonComment();
if (Current->is(TT_ConditionalExpr))
return prec::Conditional;
- if (NextNonComment && NextNonComment->is(tok::colon) &&
- NextNonComment->is(TT_DictLiteral))
+ if (NextNonComment && Current->is(TT_SelectorName) &&
+ (NextNonComment->is(TT_DictLiteral) ||
+ (Style.Language == FormatStyle::LK_Proto &&
+ NextNonComment->is(tok::less))))
return prec::Assignment;
if (Current->is(TT_JsComputedPropertyName))
return prec::Assignment;
diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp
index 0b052bd4c64..2e3b9311d12 100644
--- a/clang/unittests/Format/FormatTestProto.cpp
+++ b/clang/unittests/Format/FormatTestProto.cpp
@@ -201,6 +201,12 @@ TEST_F(FormatTestProto, FormatsOptions) {
" field_c: \"OK\"\n"
" msg_field{field_d: 123}\n"
"};");
+ verifyFormat("option (MyProto.options) = {\n"
+ " field_a: OK\n"
+ " field_b{field_c: OK}\n"
+ " field_d: OKOKOK\n"
+ " field_e: OK\n"
+ "}");
// Support syntax with <> instead of {}.
verifyFormat("option (MyProto.options) = {\n"
@@ -209,6 +215,13 @@ TEST_F(FormatTestProto, FormatsOptions) {
"};");
verifyFormat("option (MyProto.options) = {\n"
+ " field_a: OK\n"
+ " field_b<field_c: OK>\n"
+ " field_d: OKOKOK\n"
+ " field_e: OK\n"
+ "}");
+
+ verifyFormat("option (MyProto.options) = {\n"
" msg_field: <>\n"
" field_c: \"OK\",\n"
" msg_field: <field_d: 123>\n"
OpenPOWER on IntegriCloud