]> granicus.if.org Git - clang/commitdiff
[clang-format] Fix comment indentation in text protos
authorKrasimir Georgiev <krasimir@google.com>
Mon, 12 Feb 2018 15:49:09 +0000 (15:49 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Mon, 12 Feb 2018 15:49:09 +0000 (15:49 +0000)
Summary: This patch fixes a bug where the comment indent of comments in text protos gets messed up because by default paren states get created with AlignColons = true (which makes snese for ObjC).

Subscribers: klimek, cfe-commits

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

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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestTextProto.cpp

index 109dd1749ab36f7c0783c7982b047edc7fb2aa10..64d8bb7ed802bbc294c5df48b1be1fa935b222e0 100644 (file)
@@ -200,6 +200,7 @@ LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
     // global scope.
     State.Stack.back().AvoidBinPacking = true;
     State.Stack.back().BreakBeforeParameter = true;
+    State.Stack.back().AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.
index de9225d35aa202c6619e168160fbcb966965488a..84faccb2fbba485181c7ff6f48850236bd77e250 100644 (file)
@@ -313,5 +313,17 @@ TEST_F(FormatTestTextProto, KeepsLongStringLiteralsOnSameLine) {
       "  text: \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaaaaaaaa\"\n"
       "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
+  verifyFormat("aaaaaaaaaa: 100\n"
+               "bbbbbbbbbbbbbbbbbbbbbbbbbbb: 200\n"
+               "# Single line comment for stuff here.\n"
+               "cccccccccccccccccccccccc: 3849\n"
+               "# Multiline comment for stuff here.\n"
+               "# Multiline comment for stuff here.\n"
+               "# Multiline comment for stuff here.\n"
+               "cccccccccccccccccccccccc: 3849");
+}
+
 } // end namespace tooling
 } // end namespace clang