Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2301,6 +2301,8 @@ if (Right.is(tok::l_paren) && Left.isOneOf(Keywords.kw_returns, Keywords.kw_option)) return true; + if (Right.isOneOf(tok::l_brace, tok::less) && Left.is(TT_SelectorName)) + return true; } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -199,11 +199,11 @@ "};"); verifyFormat("option (MyProto.options) = {\n" " field_c: \"OK\"\n" - " msg_field{field_d: 123}\n" + " msg_field {field_d: 123}\n" "};"); verifyFormat("option (MyProto.options) = {\n" " field_a: OK\n" - " field_b{field_c: OK}\n" + " field_b {field_c: OK}\n" " field_d: OKOKOK\n" " field_e: OK\n" "}"); @@ -216,7 +216,7 @@ verifyFormat("option (MyProto.options) = {\n" " field_a: OK\n" - " field_b\n" + " field_b \n" " field_d: OKOKOK\n" " field_e: OK\n" "}"); @@ -255,7 +255,7 @@ verifyFormat("option (MyProto.options) = <\n" " field_a: \"OK\"\n" - " msg_field<\n" + " msg_field <\n" " field_b: OK\n" " field_c: OK\n" " field_d: OK\n" @@ -267,7 +267,7 @@ verifyFormat("option (MyProto.options) = <\n" " field_a: \"OK\"\n" - " msg_field<\n" + " msg_field <\n" " field_b: OK,\n" " field_c: OK,\n" " field_d: OK,\n" @@ -303,7 +303,7 @@ verifyFormat("option (MyProto.options) = <\n" " field_a: \"OK\"\n" - " msg_field{\n" + " msg_field {\n" " field_b: OK\n" " field_c: OK\n" " field_d: OK\n" @@ -315,7 +315,7 @@ verifyFormat("option (MyProto.options) = {\n" " field_a: \"OK\"\n" - " msg_field<\n" + " msg_field <\n" " field_b: OK\n" " field_c: OK\n" " field_d: OK\n" @@ -339,18 +339,18 @@ verifyFormat("option (MyProto.options) = <\n" " field_a: \"OK\"\n" - " msg_field{\n" + " msg_field {\n" " field_b: OK\n" " field_c: OK\n" " field_d: OK\n" - " msg_field<\n" + " msg_field <\n" " field_A: 1\n" " field_B: 2\n" " field_C: 3\n" " field_D: 4\n" " field_E: 5\n" " >\n" - " msg_field\n" + " msg_field \n" " field_e: OK\n" " field_f: OK\n" " }\n" Index: unittests/Format/FormatTestTextProto.cpp =================================================================== --- unittests/Format/FormatTestTextProto.cpp +++ unittests/Format/FormatTestTextProto.cpp @@ -61,13 +61,13 @@ " field_e: 23\n" "}"); - verifyFormat("msg_field{}"); + verifyFormat("msg_field {}"); - verifyFormat("msg_field{field_a: A}"); + verifyFormat("msg_field {field_a: A}"); - verifyFormat("msg_field{field_a: \"OK\" field_b: 123}"); + verifyFormat("msg_field {field_a: \"OK\" field_b: 123}"); - verifyFormat("msg_field{\n" + verifyFormat("msg_field {\n" " field_a: 1\n" " field_b: OK\n" " field_c: \"OK\"\n" @@ -78,12 +78,12 @@ " field_h: 1234.567e-89\n" "}"); - verifyFormat("msg_field: {msg_field{field_a: 1}}"); + verifyFormat("msg_field: {msg_field {field_a: 1}}"); verifyFormat("id: \"ala.bala\"\n" - "item{type: ITEM_A rank: 1 score: 90.0}\n" - "item{type: ITEM_B rank: 2 score: 70.5}\n" - "item{\n" + "item {type: ITEM_A rank: 1 score: 90.0}\n" + "item {type: ITEM_B rank: 2 score: 70.5}\n" + "item {\n" " type: ITEM_A\n" " rank: 3\n" " score: 20.0\n" @@ -113,13 +113,13 @@ verifyFormat("a: {\n" " field_a: OK\n" - " field_b{field_c: OK}\n" + " field_b {field_c: OK}\n" " field_d: OKOKOK\n" " field_e: OK\n" "}"); verifyFormat("field_a: OK,\n" - "field_b{field_c: OK},\n" + "field_b {field_c: OK},\n" "field_d: OKOKOK,\n" "field_e: OK"); } @@ -134,33 +134,33 @@ "}"); verifyFormat("field_a: OK\n" - "msg_field{\n" + "msg_field {\n" " field_b: OK // Comment\n" "}"); } TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) { // Single-line tests - verifyFormat("msg_field<>"); + verifyFormat("msg_field <>"); verifyFormat("msg_field: <>"); - verifyFormat("msg_field"); + verifyFormat("msg_field "); verifyFormat("msg_field: "); - verifyFormat("msg_field>"); - verifyFormat("msg_field>>"); - verifyFormat("msg_field: >>"); - verifyFormat("msg_field"); - verifyFormat("msg_field, field_c: OK>"); - verifyFormat("msg_field>"); + verifyFormat("msg_field >"); + verifyFormat("msg_field >>"); + verifyFormat("msg_field: >>"); + verifyFormat("msg_field "); + verifyFormat("msg_field , field_c: OK>"); + verifyFormat("msg_field >"); verifyFormat("msg_field: "); verifyFormat("msg_field: , field_c: OK>"); - verifyFormat("msg_field: >"); + verifyFormat("msg_field: >"); verifyFormat("field_a: \"OK\", msg_field: , field_c: {}"); - verifyFormat("field_a, msg_field: , field_c<>"); - verifyFormat("field_a msg_field: field_c<>"); - verifyFormat("field>, field<>> field: "); + verifyFormat("field_a , msg_field: , field_c <>"); + verifyFormat("field_a msg_field: field_c <>"); + verifyFormat("field >, field <>> field: "); // Multiple lines tests - verifyFormat("msg_field<\n" + verifyFormat("msg_field <\n" " field_a: OK\n" " field_b: \"OK\"\n" " field_c: 1\n" @@ -175,25 +175,25 @@ "msg_field: "); verifyFormat("field_a: OK,\n" - "field_b,\n" + "field_b ,\n" "field_d: <12.5>,\n" "field_e: OK"); verifyFormat("field_a: OK\n" - "field_b\n" + "field_b \n" "field_d: <12.5>\n" "field_e: OKOKOK"); - verifyFormat("msg_field<\n" + verifyFormat("msg_field <\n" " field_a: OK,\n" - " field_b,\n" + " field_b ,\n" " field_d: <12.5>,\n" " field_e: OK\n" ">"); - verifyFormat("msg_field<\n" + verifyFormat("msg_field <\n" " field_a: ,\n" - " field_b,\n" + " field_b ,\n" " field_d: <12.5>,\n" " field_e: OK,\n" ">"); @@ -206,7 +206,7 @@ " field_g: OK\n" ">"); - verifyFormat("field_a{\n" + verifyFormat("field_a {\n" " field_d: ok\n" " field_b: \n" " field_d: ok\n" @@ -221,16 +221,16 @@ "}"); verifyFormat("field_a: >\n" - "field_b<\n" + "field_b <\n" " field_b1: <>\n" " field_b2: ok,\n" " field_b3: <\n" - " field_x{} // Comment\n" + " field_x {} // Comment\n" " field_y: {field_z: 1}\n" " field_w: ok\n" " >\n" - " field{\n" - " field_x<> // Comment\n" + " field {\n" + " field_x <> // Comment\n" " field_y: \n" " field_w: ok\n" " msg_field: <\n" @@ -244,8 +244,7 @@ " }\n" ">\n" "field: OK,\n" - "field_c>>"); + "field_c >>"); } - } // end namespace tooling } // end namespace clang