Index: cfe/trunk/lib/Format/TokenAnnotator.cpp =================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -2968,6 +2968,9 @@ return false; return true; } + if (Right.is(tok::r_square) && Right.MatchingParen && + Right.MatchingParen->is(TT_ProtoExtensionLSquare)) + return false; if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_ObjCMethodExpr))) return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls. Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestTextProto.cpp +++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp @@ -392,10 +392,12 @@ " .long/longg.longlong] { key: value }"); verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/\n" " bbbbbbbbbbbbbb] { key: value }"); - verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - "] { key: value }"); - verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - "] {\n" + // These go over the column limit intentionally, since the alternative + // [aa..a\n] is worse. + verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] {\n" + " key: value\n" + "}"); + verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] {\n" " [type.type] {\n" " keyyyyyyyyyyyyyy: valuuuuuuuuuuuuuuuuuuuuuuuuue\n" " }\n" @@ -475,5 +477,20 @@ " \"str2\"\n"); } +TEST_F(FormatTestTextProto, PutsMultipleEntriesInExtensionsOnNewlines) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto); + verifyFormat("pppppppppp: {\n" + " ssssss: \"http://example.com/blahblahblah\"\n" + " ppppppp: \"sssss/MMMMMMMMMMMM\"\n" + " [ns.sssss.eeeeeeeee.eeeeeeeeeeeeeee] { begin: 24 end: 252 }\n" + " [ns.sssss.eeeeeeeee.eeeeeeeeeeeeeee] {\n" + " begin: 24\n" + " end: 252\n" + " key: value\n" + " key: value\n" + " }\n" + "}", Style); +} + } // end namespace tooling } // end namespace clang