-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Add support for aligning BlockComments in declarations #109497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
3833349
4514cf2
d48cad3
c573b3c
526a16a
cd798d2
d68ab08
7121d23
5a43a9e
4dfa598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1005,6 +1005,12 @@ void WhitespaceManager::alignConsecutiveTableGenDefinitions() { | |
| TT_InheritanceColon); | ||
| } | ||
|
|
||
| static bool shouldAlignBlockComment(const FormatToken &Tok) { | ||
| return Tok.is(TT_BlockComment) && Tok.Previous && | ||
| !Tok.Previous->isOneOf(TT_StartOfName, TT_BlockComment) && Tok.Next && | ||
| Tok.Next->isOneOf(tok::comma, tok::r_paren, TT_BlockComment); | ||
| } | ||
|
|
||
| void WhitespaceManager::alignConsecutiveDeclarations() { | ||
| if (!Style.AlignConsecutiveDeclarations.Enabled) | ||
| return; | ||
|
|
@@ -1022,7 +1028,10 @@ void WhitespaceManager::alignConsecutiveDeclarations() { | |
| if (C.Tok->is(TT_FunctionDeclarationName)) | ||
| return true; | ||
| if (C.Tok->isNot(TT_StartOfName)) | ||
| return false; | ||
| if (!Style.AlignConsecutiveDeclarations.AlignBlockComments || | ||
| !shouldAlignBlockComment(*C.Tok)) { | ||
| return false; | ||
| } | ||
|
Comment on lines
1030
to
+1034
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fold the nested |
||
| if (C.Tok->Previous && | ||
| C.Tok->Previous->is(TT_StatementAttributeLikeMacro)) | ||
| return false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20018,6 +20018,52 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { | |
| BracedAlign); | ||
| } | ||
|
|
||
| TEST_F(FormatTest, AlignConsecutiveDeclarationsBlockComments) { | ||
| FormatStyle Style = getLLVMStyleWithColumns(80); | ||
JessehMSFT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Style.AlignConsecutiveDeclarations.Enabled = true; | ||
| Style.AlignConsecutiveDeclarations.AlignBlockComments = true; | ||
| Style.BinPackParameters = FormatStyle::BPPS_OnePerLine; | ||
| Style.BinPackArguments = false; | ||
JessehMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| verifyFormat( | ||
| "bool SomeLongMethodName(int longParameterNameA,\n" | ||
| " bool /*longParameterNameB*/,\n" | ||
| " const std::string &longParameterNameC);", | ||
| "bool SomeLongMethodName(int longParameterNameA,\n" | ||
| " bool /*longParameterNameB*/,\n" | ||
| " const std::string &longParameterNameC);", | ||
| Style); | ||
|
|
||
| verifyFormat( | ||
| "const bool ret = SomeLongMethodName(4 /*parameterNameA*/,\n" | ||
| " true /*longParameterNameB*/,\n" | ||
| " str /*longestParameterNameC*/);", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @owenca , did you have a suggestion? I thought mostly the argument alignment would follow the declaration parameter alignment for consistency. |
||
| "const bool ret = SomeLongMethodName(4 /*parameterNameA*/,\n" | ||
| " true /*longParameterNameB*/,\n" | ||
| " str /*longestParameterNameC*/);", | ||
| Style); | ||
|
|
||
| verifyNoChange("/*,\n" | ||
| "This is a multi-line block comment.\n" | ||
| "That is not part of a function declaration.\n" | ||
| "*/\n" | ||
| "static void SomeLongMethodName()", | ||
| Style); | ||
|
|
||
| verifyNoChange("static const unsigned int c_cMediaEntranceEntries = 31;\n" | ||
| "static const unsigned int c_cMediaEmphasisEntries = 4 /* " | ||
| "media effects */ + 12;\n" | ||
| "static const unsigned int c_cMediaExitEntries = 32;", | ||
| Style); | ||
|
|
||
| verifyNoChange( | ||
| "static bool SomeLongMethodName(int longParameterNameA,\n" | ||
| " bool longParameterNameB " | ||
| "/*=false*/,\n" | ||
| " std::string &longParameterNameC);", | ||
| Style); | ||
| } | ||
|
|
||
| TEST_F(FormatTest, AlignConsecutiveShortCaseStatements) { | ||
| FormatStyle Alignment = getLLVMStyle(); | ||
| Alignment.AllowShortCaseLabelsOnASingleLine = true; | ||
|
|
@@ -20259,7 +20305,8 @@ TEST_F(FormatTest, AlignWithLineBreaks) { | |
| FormatStyle::AlignConsecutiveStyle( | ||
| {/*Enabled=*/false, /*AcrossEmptyLines=*/false, | ||
| /*AcrossComments=*/false, /*AlignCompound=*/false, | ||
| /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); | ||
| /*AlignFunctionPointers=*/false, /*PadOperators=*/true, | ||
| /*AlignBlockComments=*/false})); | ||
| EXPECT_EQ(Style.AlignConsecutiveDeclarations, | ||
| FormatStyle::AlignConsecutiveStyle({})); | ||
| verifyFormat("void foo() {\n" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.