]> granicus.if.org Git - clang/commitdiff
clang-format: Fix formatting of custom proto options.
authorDaniel Jasper <djasper@google.com>
Wed, 29 Jan 2014 18:43:40 +0000 (18:43 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 29 Jan 2014 18:43:40 +0000 (18:43 +0000)
Before:
  repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {
                              aaaaaaaaaaaaaaaaa : AAAAAAAA
                            }];

After:
  repeated double value = 1
      [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa : AAAAAAAA}];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200405 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6e82b19148c36718d1311d8b1a76629d76a22240..a0edae51a722bccdd4d2772d43433829ff8cada1 100644 (file)
@@ -1469,7 +1469,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
     // deliberate choice and might have aligned the contents of the string
     // literal accordingly. Thus, we try keep existing line breaks.
     return Right.NewlinesBefore > 0;
-  } else if (Right.Previous->is(tok::l_brace) &&
+  } else if (Right.Previous->is(tok::l_brace) && Right.NestingLevel == 1 &&
              Style.Language == FormatStyle::LK_Proto) {
     // Don't enums onto single lines in protocol buffers.
     return true;
index 6304d9688fdce28e79321747ebac58d28fd4a717..443c3e10159a09bedfb223688ef63b87c58ea04b 100644 (file)
@@ -80,6 +80,8 @@ TEST_F(FormatTestProto, MessageFieldAttributes) {
                "     deprecated = true];");
   verifyFormat("optional LongMessageType long_proto_field = 1\n"
                "    [default = REALLY_REALLY_LONG_CONSTANT_VALUE];");
+  verifyFormat("repeated double value = 1\n"
+               "    [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa : AAAAAAAA}];");
 }
 
 TEST_F(FormatTestProto, FormatsOptions) {