r325513 - [clang-format] Fix text proto extension scope opening detection

Krasimir Georgiev via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 19 08:00:21 PST 2018


Author: krasimir
Date: Mon Feb 19 08:00:21 2018
New Revision: 325513

URL: http://llvm.org/viewvc/llvm-project?rev=325513&view=rev
Log:
[clang-format] Fix text proto extension scope opening detection

Summary:
This fixes the detection of scope openers in text proto extensions; previously
they were not detected correctly leading to instances like:
```
msg {
  [aa.bb
] {
key: value
}
}
```

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D43469

Modified:
    cfe/trunk/lib/Format/FormatToken.h
    cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=325513&r1=325512&r2=325513&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Mon Feb 19 08:00:21 2018
@@ -478,6 +478,7 @@ struct FormatToken {
     if (is(TT_TemplateString) && opensScope())
       return true;
     return is(TT_ArrayInitializerLSquare) ||
+           is(TT_ProtoExtensionLSquare) ||
            (is(tok::l_brace) &&
             (BlockKind == BK_Block || is(TT_DictLiteral) ||
              (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||

Modified: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestTextProto.cpp?rev=325513&r1=325512&r2=325513&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp Mon Feb 19 08:00:21 2018
@@ -389,6 +389,14 @@ TEST_F(FormatTestTextProto, FormatsExten
                "    keyyyyyyyyyyyyyy: valuuuuuuuuuuuuuuuuuuuuuuuuue\n"
                "  }\n"
                "}");
+  verifyFormat(
+      "aaaaaaaaaaaaaaa {\n"
+      "  bbbbbb {\n"
+      "    [a.b/cy] {\n"
+      "      eeeeeeeeeeeee: \"The lazy coo cat jumps over the lazy hot dog\"\n"
+      "    }\n"
+      "  }\n"
+      "}");
 }
 
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {




More information about the cfe-commits mailing list