From 0720042e1c4ca41ecdd9d6d5cd17d106efa2c6fe Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Tue, 27 Jun 2023 10:10:22 +0200 Subject: [PATCH] ClangFormat: Make the behavior of the braces tab clearer Fixes: QTCREATORBUG-29069 Change-Id: I078b7fbb6f98088f615d74a189cce00f8e5fa5fe Reviewed-by: Christian Kandeler --- src/plugins/clangformat/clangformatfile.cpp | 17 ++++++++++------- src/plugins/clangformat/clangformatutils.cpp | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/plugins/clangformat/clangformatfile.cpp b/src/plugins/clangformat/clangformatfile.cpp index 16209c30943..66eb58d6eaf 100644 --- a/src/plugins/clangformat/clangformatfile.cpp +++ b/src/plugins/clangformat/clangformatfile.cpp @@ -152,14 +152,17 @@ CppEditor::CppCodeStyleSettings ClangFormatFile::toCppCodeStyleSettings( // to be false settings.indentAccessSpecifiers = (style.AccessModifierOffset != -1 * int(style.IndentWidth)); - settings.indentNamespaceBody = style.NamespaceIndentation - == FormatStyle::NamespaceIndentationKind::NI_All; - settings.indentNamespaceBraces = settings.indentNamespaceBody; + if (style.NamespaceIndentation == FormatStyle::NamespaceIndentationKind::NI_All) { + settings.indentNamespaceBody = true; + settings.indentNamespaceBraces = settings.indentNamespaceBody; + } - settings.indentClassBraces = style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths; - settings.indentEnumBraces = settings.indentClassBraces; - settings.indentBlockBraces = settings.indentClassBraces; - settings.indentFunctionBraces = settings.indentClassBraces; + if (style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths) { + settings.indentClassBraces = true; + settings.indentEnumBraces = settings.indentClassBraces; + settings.indentBlockBraces = settings.indentClassBraces; + settings.indentFunctionBraces = settings.indentClassBraces; + } settings.indentSwitchLabels = style.IndentCaseLabels; #if LLVM_VERSION_MAJOR >= 11 diff --git a/src/plugins/clangformat/clangformatutils.cpp b/src/plugins/clangformat/clangformatutils.cpp index 735c0a03548..928d30d241e 100644 --- a/src/plugins/clangformat/clangformatutils.cpp +++ b/src/plugins/clangformat/clangformatutils.cpp @@ -201,13 +201,13 @@ void fromCppCodeStyleSettings(clang::format::FormatStyle &style, else style.AccessModifierOffset = -1 * style.IndentWidth; - if (settings.indentNamespaceBody || settings.indentNamespaceBraces) + if (settings.indentNamespaceBody && settings.indentNamespaceBraces) style.NamespaceIndentation = FormatStyle::NamespaceIndentationKind::NI_All; else style.NamespaceIndentation = FormatStyle::NamespaceIndentationKind::NI_None; - if (settings.indentClassBraces || settings.indentEnumBraces || settings.indentBlockBraces - || settings.indentFunctionBraces) + if (settings.indentClassBraces && settings.indentEnumBraces && settings.indentBlockBraces + && settings.indentFunctionBraces) style.BreakBeforeBraces = FormatStyle::BS_Whitesmiths; else style.BreakBeforeBraces = FormatStyle::BS_Custom;