From e544d56f34a589cd618c699cd9edc9569c85a99d Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 17 Mar 2014 14:32:47 +0000 Subject: [PATCH] clang-format: Indent from dict literal labels. Before: @{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : regularFont, }; After: @{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : regularFont, }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204041 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 5 +++-- unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 17af2fa5f2..380532a47c 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -426,8 +426,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, } else if (NextNonComment->Type == TT_StartOfName || Previous.isOneOf(tok::coloncolon, tok::equal)) { State.Column = ContinuationIndent; - } else if (PreviousNonComment && - PreviousNonComment->Type == TT_ObjCMethodExpr) { + } else if (PreviousNonComment && PreviousNonComment->is(tok::colon) && + (PreviousNonComment->Type == TT_ObjCMethodExpr || + PreviousNonComment->Type == TT_DictLiteral)) { State.Column = ContinuationIndent; // FIXME: This is hacky, find a better way. The problem is that in an ObjC // method expression, the block should be aligned to the line starting it, diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 5d4c1172c1..5bd0822281 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6011,6 +6011,11 @@ TEST_F(FormatTest, ObjCDictLiterals) { " NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : " "regularFont,\n" "};"); + verifyFormat( + "@{\n" + " NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :\n" + " reeeeeeeeeeeeeeeeeeeeeeeegularFont,\n" + "};"); // We should try to be robust in case someone forgets the "@". verifyFormat( -- 2.40.0