From: Daniel Jasper Date: Wed, 22 Jan 2014 08:04:52 +0000 (+0000) Subject: clang-format: Treat "." in protos like namespace separators. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ebb8f4d9877a23a25b2253685b7c935f78cf302c;p=clang clang-format: Treat "." in protos like namespace separators. Before: optional really.really.long.and.qualified.type.aaaaaaa .aaaaaaaa another_fiiiiiiiiiiiiiiiiiiiiield = 2; After: optional really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa another_fiiiiiiiiiiiiiiiiiiiiield = 2; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199796 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 418a7c5048..1bb886c414 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1184,7 +1184,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 150; if (Left.Type == TT_CastRParen) return 100; - if (Left.is(tok::coloncolon)) + if (Left.is(tok::coloncolon) || + (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto)) return 500; if (Left.isOneOf(tok::kw_class, tok::kw_struct)) return 5000; diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index 7623e46db4..83e003465f 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -32,7 +32,9 @@ protected: } static std::string format(llvm::StringRef Code) { - return format(Code, 0, Code.size(), getGoogleProtoStyle()); + FormatStyle Style = getGoogleProtoStyle(); + Style.ColumnLimit = 60; // To make writing tests easier. + return format(Code, 0, Code.size(), Style); } static void verifyFormat(llvm::StringRef Code) { @@ -48,6 +50,14 @@ TEST_F(FormatTestProto, FormatsMessages) { " required int32 field1 = 1;\n" " optional string field2 = 2 [default = \"2\"]\n" "}"); + + verifyFormat("message SomeMessage {\n" + " optional really.really.long.and.qualified.type.aaaaaaa\n" + " fiiiiiiiiiiiiiiiiiiiiiiiiield = 1;\n" + " optional\n" + " really.really.long.and.qualified.type.aaaaaaa.aaaaaaaa\n" + " another_fiiiiiiiiiiiiiiiiiiiiield = 2;\n" + "}"); } TEST_F(FormatTestProto, FormatsEnums) {