Skip to content

Commit

Permalink
[clang-format] Fix aligning with linebreaks #2
Browse files Browse the repository at this point in the history
This amends c5243c63cda3c740d6e9c7e501f6518c21688da3 to fix formatting
continued function calls with BinPacking = false.

Differential Revision: https://reviews.llvm.org/D106773
  • Loading branch information
HazardyKnusperkeks authored and memfrob committed Oct 4, 2022
1 parent db75e2c commit 54a080e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
if (ScopeStart > Start + 1 &&
Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
Changes[ScopeStart - 1].Tok->is(tok::l_paren))
return true;
return Style.BinPackArguments;

// Ternary operator
if (Changes[i].Tok->is(TT_ConditionalExpr))
Expand Down
31 changes: 31 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16419,6 +16419,37 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
"}",
Style);
// clang-format on

Style = getLLVMStyleWithColumns(120);
Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive;
Style.ContinuationIndentWidth = 4;
Style.IndentWidth = 4;

// clang-format off
verifyFormat("void SomeFunc() {\n"
" newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec),\n"
" seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
" newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec),\n"
" seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
" newWatcher.max = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec),\n"
" seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
"}",
Style);
// clang-format on

Style.BinPackArguments = false;

// clang-format off
verifyFormat("void SomeFunc() {\n"
" newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(\n"
" FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec), seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
" newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(\n"
" FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec), seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
" newWatcher.max = ToLegacyTimestamp(GetMaxAge(\n"
" FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec), seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n"
"}",
Style);
// clang-format on
}

TEST_F(FormatTest, AlignWithInitializerPeriods) {
Expand Down

0 comments on commit 54a080e

Please sign in to comment.