Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -696,7 +696,8 @@ ? std::max(State.Stack.back().Indent, State.FirstIndent + Style.ContinuationIndentWidth) : State.Stack.back().Indent) + - NextNonComment->LongestObjCSelectorName; + std::max(NextNonComment->LongestObjCSelectorName, + unsigned(NextNonComment->TokenText.size())); } } else if (State.Stack.back().AlignColons && State.Stack.back().ColonPos <= NextNonComment->ColumnWidth) { @@ -895,7 +896,8 @@ ? std::max(State.Stack.back().Indent, State.FirstIndent + Style.ContinuationIndentWidth) : State.Stack.back().Indent) + - NextNonComment->LongestObjCSelectorName - + std::max(NextNonComment->LongestObjCSelectorName, + unsigned(NextNonComment->TokenText.size())) - NextNonComment->ColumnWidth; } if (!State.Stack.back().AlignColons) Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -571,12 +571,12 @@ BeforePrevious->is(tok::r_square) || Contexts.back().LongestObjCSelectorName == 0) { Tok->Previous->Type = TT_SelectorName; - if (Tok->Previous->ColumnWidth > - Contexts.back().LongestObjCSelectorName) - Contexts.back().LongestObjCSelectorName = - Tok->Previous->ColumnWidth; if (!Contexts.back().FirstObjCSelectorName) Contexts.back().FirstObjCSelectorName = Tok->Previous; + else if (Tok->Previous->ColumnWidth > + Contexts.back().LongestObjCSelectorName) + Contexts.back().LongestObjCSelectorName = + Tok->Previous->ColumnWidth; } } else if (Contexts.back().ColonIsForRangeExpr) { Tok->Type = TT_RangeBasedForLoopColon; Index: unittests/Format/FormatTestObjC.cpp =================================================================== --- unittests/Format/FormatTestObjC.cpp +++ unittests/Format/FormatTestObjC.cpp @@ -652,8 +652,8 @@ // Formats pair-parameters. verifyFormat("[I drawRectOn:surface ofSize:aa:bbb atOrigin:cc:dd];"); verifyFormat("[I drawRectOn:surface //\n" - " ofSize:aa:bbb\n" - " atOrigin:cc:dd];"); + " ofSize:aa:bbb\n" + " atOrigin:cc:dd];"); Style.ColumnLimit = 70; verifyFormat( @@ -686,7 +686,19 @@ " backing:NSBackingStoreBuffered\n" " defer:NO]);\n" "}"); -} + + // Respect continuation indent and colon alignment (e.g. when object name is + // short, and first selector is the longest one) + Style = getLLVMStyle(); + Style.Language = FormatStyle::LK_ObjC; + Style.ContinuationIndentWidth = 8; + verifyFormat("[self performSelectorOnMainThread:@selector(loadAccessories)\n" + " withObject:nil\n" + " waitUntilDone:false];"); + verifyFormat("[self performSelector:@selector(loadAccessories)\n" + " withObjectOnMainThread:nil\n" + " waitUntilDone:false];"); + } TEST_F(FormatTestObjC, ObjCAt) { verifyFormat("@autoreleasepool");