]> granicus.if.org Git - clang/commitdiff
clang-format: Treat "." in protos like namespace separators.
authorDaniel Jasper <djasper@google.com>
Wed, 22 Jan 2014 08:04:52 +0000 (08:04 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 22 Jan 2014 08:04:52 +0000 (08:04 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestProto.cpp

index 418a7c50480b17176f22b85a7772cd58f2d36243..1bb886c41433915289f546bba88b72008d3ce5a7 100644 (file)
@@ -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;
index 7623e46db44a1f7275e2473ab9fd7fc51bcaadf5..83e003465fa2d6befa4bd0d80a369368f406530f 100644 (file)
@@ -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) {