From f876a71fa1ddd9cd385c13f8ef55e153127c67e6 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Tue, 13 Nov 2018 08:04:30 +0100 Subject: [PATCH] ClangFormat: Improve current style detection Check first if the current project already has .clang-format configuration file. Change-Id: Ic8cb5d37c32cd5b0c04485589caea95de933c264 Reviewed-by: Nikolai Kosjar --- src/plugins/clangformat/clangformatutils.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/clangformat/clangformatutils.cpp b/src/plugins/clangformat/clangformatutils.cpp index 9302e15361b..39ebe5366d3 100644 --- a/src/plugins/clangformat/clangformatutils.cpp +++ b/src/plugins/clangformat/clangformatutils.cpp @@ -172,10 +172,17 @@ clang::format::FormatStyle currentGlobalStyle() return currentStyle(true); } +static bool isCurrentStyleGlobal() +{ + Utils::FileName path = projectStylePath(); + if (path.appendPath(".clang-format").exists()) + return false; + return !CppCodeStyleSettings::currentProjectCodeStyle().has_value(); +} + clang::format::FormatStyle currentStyle() { - const bool isGlobal = !CppCodeStyleSettings::currentProjectCodeStyle().has_value(); - return currentStyle(isGlobal); + return currentStyle(isCurrentStyleGlobal()); } }