From: Krasimir Georgiev Date: Mon, 12 Feb 2018 15:49:09 +0000 (+0000) Subject: [clang-format] Fix comment indentation in text protos X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed84871f7fdc613caa2430028a046fc84d056259;p=clang [clang-format] Fix comment indentation in text protos 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 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 109dd1749a..64d8bb7ed8 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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. diff --git a/unittests/Format/FormatTestTextProto.cpp b/unittests/Format/FormatTestTextProto.cpp index de9225d35a..84faccb2fb 100644 --- a/unittests/Format/FormatTestTextProto.cpp +++ b/unittests/Format/FormatTestTextProto.cpp @@ -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