ClangFormat: Use pre-existing code style settings

Instead using of default code style settings, this commit
modifies the ClangFormat plugin to use the code style
settings that were set before applying ClangFormat.
By doing so, we preserve the previously defined code style.

Fixes: QTCREATORBUG-29185
Change-Id: I347d44d5ed49a2c50e130a983b62c844c8964391
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Artem Sokolovskii
2023-06-07 16:17:29 +02:00
parent 2edaf459bd
commit 6a20e588bf
6 changed files with 117 additions and 75 deletions

View File

@@ -7,15 +7,16 @@
#include <coreplugin/icore.h>
#include <cppeditor/cppcodestylepreferences.h>
#include <projectexplorer/editorconfiguration.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectmanager.h>
#include <texteditor/icodestylepreferences.h>
#include <texteditor/tabsettings.h>
#include <texteditor/texteditorsettings.h>
#include <clang/Tooling/Core/Replacement.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
@@ -24,6 +25,8 @@
#include <QDebug>
#include <QTextDocument>
#include <clang/Tooling/Core/Replacement.h>
namespace ClangFormat {
Internal::LlvmFileSystemAdapter llvmFileSystemAdapter = {};
@@ -760,7 +763,7 @@ clang::format::FormatStyle overrideStyle(const Utils::FilePath &fileName)
Utils::FilePath filePath = filePathToCurrentSettings(preferences);
if (!filePath.exists())
return qtcStyle();
return currentQtStyle(preferences);
clang::format::FormatStyle currentSettingsStyle;
currentSettingsStyle.Language = clang::format::FormatStyle::LK_Cpp;
@@ -769,7 +772,7 @@ clang::format::FormatStyle overrideStyle(const Utils::FilePath &fileName)
.toStdString(),
&currentSettingsStyle);
QTC_ASSERT(error.value() == static_cast<int>(clang::format::ParseError::Success),
return qtcStyle());
return currentQtStyle(preferences));
return currentSettingsStyle;
}