forked from qt-creator/qt-creator
ClangFormat: Parse clang-format file when needed
Previously the .clang-format was parsed even if there is an override active. Fixed .clang-format to follow style-guide more closely. Change-Id: I39c5e5793cfe9e8a996e084e4ba169231a9bcebb Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -90,7 +90,7 @@ NamespaceIndentation: None
|
|||||||
ObjCBlockIndentWidth: 4
|
ObjCBlockIndentWidth: 4
|
||||||
ObjCSpaceAfterProperty: false
|
ObjCSpaceAfterProperty: false
|
||||||
ObjCSpaceBeforeProtocolList: true
|
ObjCSpaceBeforeProtocolList: true
|
||||||
PenaltyBreakAssignment: 150
|
PenaltyBreakAssignment: 88
|
||||||
PenaltyBreakBeforeFirstCallParameter: 300
|
PenaltyBreakBeforeFirstCallParameter: 300
|
||||||
PenaltyBreakComment: 500
|
PenaltyBreakComment: 500
|
||||||
PenaltyBreakFirstLessLess: 400
|
PenaltyBreakFirstLessLess: 400
|
||||||
|
@@ -8,9 +8,11 @@
|
|||||||
#include "llvmfilesystem.h"
|
#include "llvmfilesystem.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <projectexplorer/editorconfiguration.h>
|
#include <projectexplorer/editorconfiguration.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
|
|
||||||
#include <texteditor/icodestylepreferences.h>
|
#include <texteditor/icodestylepreferences.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
@@ -737,23 +739,13 @@ void ClangFormatBaseIndenter::autoIndent(const QTextCursor &cursor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clang::format::FormatStyle ClangFormatBaseIndenter::styleForFile() const
|
clang::format::FormatStyle overrideStyle(const ProjectExplorer::Project *projectForFile)
|
||||||
{
|
{
|
||||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder = clang::format::getStyle(
|
|
||||||
"file", m_fileName.toFSPathString().toStdString(), "none", "", &llvmFileSystemAdapter);
|
|
||||||
|
|
||||||
const ProjectExplorer::Project *projectForFile
|
|
||||||
= ProjectExplorer::SessionManager::projectForFile(m_fileName);
|
|
||||||
const bool overrideStyleFile
|
|
||||||
= projectForFile ? projectForFile->namedSettings(Constants::OVERRIDE_FILE_ID).toBool()
|
|
||||||
: ClangFormatSettings::instance().overrideDefaultFile();
|
|
||||||
const TextEditor::ICodeStylePreferences *preferences
|
const TextEditor::ICodeStylePreferences *preferences
|
||||||
= projectForFile
|
= projectForFile
|
||||||
? projectForFile->editorConfiguration()->codeStyle("Cpp")->currentPreferences()
|
? projectForFile->editorConfiguration()->codeStyle("Cpp")->currentPreferences()
|
||||||
: TextEditor::TextEditorSettings::codeStyle("Cpp")->currentPreferences();
|
: TextEditor::TextEditorSettings::codeStyle("Cpp")->currentPreferences();
|
||||||
|
|
||||||
if (!styleFromProjectFolder || overrideStyleFile
|
|
||||||
|| *styleFromProjectFolder == clang::format::getNoStyle()) {
|
|
||||||
Utils::FilePath filePath = filePathToCurrentSettings(preferences);
|
Utils::FilePath filePath = filePathToCurrentSettings(preferences);
|
||||||
|
|
||||||
if (!filePath.exists())
|
if (!filePath.exists())
|
||||||
@@ -771,6 +763,25 @@ clang::format::FormatStyle ClangFormatBaseIndenter::styleForFile() const
|
|||||||
return currentSettingsStyle;
|
return currentSettingsStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clang::format::FormatStyle ClangFormatBaseIndenter::styleForFile() const
|
||||||
|
{
|
||||||
|
const ProjectExplorer::Project *projectForFile
|
||||||
|
= ProjectExplorer::SessionManager::projectForFile(m_fileName);
|
||||||
|
|
||||||
|
const bool overrideStyleFile
|
||||||
|
= projectForFile ? projectForFile->namedSettings(Constants::OVERRIDE_FILE_ID).toBool()
|
||||||
|
: ClangFormatSettings::instance().overrideDefaultFile();
|
||||||
|
|
||||||
|
if (overrideStyleFile)
|
||||||
|
return overrideStyle(projectForFile);
|
||||||
|
|
||||||
|
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder
|
||||||
|
= clang::format::getStyle("file",
|
||||||
|
m_fileName.toFSPathString().toStdString(),
|
||||||
|
"none",
|
||||||
|
"",
|
||||||
|
&llvmFileSystemAdapter);
|
||||||
|
|
||||||
if (styleFromProjectFolder) {
|
if (styleFromProjectFolder) {
|
||||||
addQtcStatementMacros(*styleFromProjectFolder);
|
addQtcStatementMacros(*styleFromProjectFolder);
|
||||||
return *styleFromProjectFolder;
|
return *styleFromProjectFolder;
|
||||||
|
Reference in New Issue
Block a user