Clang-Format 不能正确分配函数参数

Clang-Format does not properly allign function arguments

本文关键字:函数 参数 分配 不能 Clang-Format      更新时间:2023-10-16

我正在尝试以这种方式格式化我的代码:

int foo(int a,
int b,
int c)
{
}

但是,我所有的尝试都导致了这个结果:

int foo(int a,
int b,
int c)
{
}

这是我在 Manjaro 上运行的 clang 格式配置:

# Under Visual studio, the plugin https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.ClangFormat makes the use of the clang formatter easier.
Language: Cpp
AccessModifierOffset: -4 
AlignAfterOpenBracket: Align #AlwaysBreak 
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true 
AlignEscapedNewlines: Left 
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always 
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All 
AllowShortIfStatementsOnASingleLine: Always 
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true 
BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: None 
BreakBeforeBraces: Allman 
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon 
BreakInheritanceList: AfterColon 
BreakStringLiterals: true
ColumnLimit: 120
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IndentCaseLabels: false
IndentPPDirectives: BeforeHash   
IndentWidth: 4
IndentWrappedFunctionNames: false

KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner 
PointerAlignment: Middle 
ReflowComments: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

TabWidth: 4
UseTab: Never 
## Penalites: This decides what order things should be done if a line is too long. 
## For instance, using the policies specified here:  https://stackoverflow.com/questions/26635370/in-clang-format-what-do-the-penalties-do
PenaltyBreakAssignment: 5
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyBreakTemplateDeclaration : 30
PenaltyExcessCharacter: 30
PenaltyReturnTypeOnItsOwnLine: 30

有谁知道如何强制这种对齐?

仅供参考,已经尝试过:叮当格式:对齐函数参数名称和叮当格式:中断函数参数

多谢

干杯

正如我所说,我已经尝试了这些解决方案但没有成功......将对齐连续声明设置为 true 会生成

Scene(const std::filesystem::path           scene_directory,
Object3D *                            parent,
Magnum::SceneGraph::DrawableGroup3D * group);

编辑1:找出问题!由于某些未知原因,它是由我的IDE引起的。复制粘贴到文本编辑器中显示格式正确。感谢您的帮助!