首页 > 解决方案 > 如何让 clang 格式优先于分解函数参数而不是将函数调用放在单独的行上

问题描述

我有一些看起来像这样的代码:

    NTSTATUS status = co_await stateManager_->RemoveAsync(
        transaction,
        stateProviderName,
        timeout,
        cancellationToken);

当我尝试使用 clang 格式对其进行格式化时,它会产生这样的结果

    NTSTATUS status = co_await stateManager_
                          ->RemoveAsync(transaction, stateProviderName, timeout, cancellationToken);

如何获得 clang 格式来阻止这种中断的发生并优先考虑打破论点?对于一些具有较长参数列表的函数,它会保留原始格式,但是对于这样的调用,我无法得到不同的结果。

我的 clang 格式文件如下所示:

---
BasedOnStyle:  Microsoft
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: true
BraceWrapping:
  AfterClass: true
  AfterControlStatement: true
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: true
  AfterObjCDeclaration: true
  AfterStruct: true
  AfterUnion: true
  BeforeCatch: true
  BeforeElse: true
  IndentBraces: true
  SplitEmptyFunction: true
  SplitEmptyNamespace: true
  SplitEmptyRecord: true
BreakAfterJavaFieldAnnotations: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeComma
BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DeriveLineEnding: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: false
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: false
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 3
NamespaceIndentation: All
PenaltyBreakAssignment: 3
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 330
PenaltyBreakFirstLessLess: 138
PenaltyBreakString: 800
PenaltyExcessCharacter: 1221339
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Middle
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 10
UseTab: Never
UseCRLF: true
...

标签: c++clangclang-format

解决方案


推荐阅读