diff --git a/src/plugins/clangformat/clangformatutils.cpp b/src/plugins/clangformat/clangformatutils.cpp index 00396e04a61..860ba6239de 100644 --- a/src/plugins/clangformat/clangformatutils.cpp +++ b/src/plugins/clangformat/clangformatutils.cpp @@ -307,12 +307,6 @@ QString configForFile(Utils::FilePath fileName) return configForFile(fileName, true); } -Utils::FilePath assumedPathForConfig(const QString &configFile) -{ - Utils::FilePath fileName = Utils::FilePath::fromString(configFile); - return fileName.parentDir().pathAppended("test.cpp"); -} - static clang::format::FormatStyle constructStyle(const QByteArray &baseStyle = QByteArray()) { if (!baseStyle.isEmpty()) { @@ -359,56 +353,6 @@ void createStyleFileIfNeeded(bool isGlobal) } } -static QByteArray configBaseStyleName(const QString &configFile) -{ - if (configFile.isEmpty()) - return QByteArray(); - - QFile config(configFile); - if (!config.open(QIODevice::ReadOnly)) - return QByteArray(); - - const QByteArray content = config.readAll(); - const char basedOnStyle[] = "BasedOnStyle:"; - int basedOnStyleIndex = content.indexOf(basedOnStyle); - if (basedOnStyleIndex < 0) - return QByteArray(); - - basedOnStyleIndex += sizeof(basedOnStyle) - 1; - const int endOfLineIndex = content.indexOf('\n', basedOnStyleIndex); - return content - .mid(basedOnStyleIndex, endOfLineIndex < 0 ? -1 : endOfLineIndex - basedOnStyleIndex) - .trimmed(); -} - -static clang::format::FormatStyle styleForFile(Utils::FilePath fileName, bool checkForSettings) -{ - QString configFile = configForFile(fileName, checkForSettings); - if (configFile.isEmpty()) { - // If no configuration is found create a global one (if it does not yet exist) and use it. - createStyleFileIfNeeded(true); - configFile = globalPath().pathAppended(Constants::SETTINGS_FILE_NAME).toString(); - } - - fileName = assumedPathForConfig(configFile); - Expected style = format::getStyle("file", - fileName.toString().toStdString(), - "none"); - if (style) - return *style; - - handleAllErrors(style.takeError(), [](const ErrorInfoBase &) { - // do nothing - }); - - return constructStyle(configBaseStyleName(configFile)); -} - -clang::format::FormatStyle styleForFile(Utils::FilePath fileName) -{ - return styleForFile(fileName, true); -} - void addQtcStatementMacros(clang::format::FormatStyle &style) { static const std::vector macros = {"Q_OBJECT", @@ -458,26 +402,4 @@ std::string readFile(const QString &path) return settings; } - -std::string currentProjectConfigText() -{ - const QString configPath = projectPath().pathAppended(Constants::SETTINGS_FILE_NAME).toString(); - return readFile(configPath); -} - -std::string currentGlobalConfigText() -{ - const QString configPath = globalPath().pathAppended(Constants::SETTINGS_FILE_NAME).toString(); - return readFile(configPath); -} - -clang::format::FormatStyle currentProjectStyle() -{ - return styleForFile(projectPath().pathAppended(Constants::SAMPLE_FILE_NAME), false); -} - -clang::format::FormatStyle currentGlobalStyle() -{ - return styleForFile(globalPath().pathAppended(Constants::SAMPLE_FILE_NAME), false); -} } // namespace ClangFormat diff --git a/src/plugins/clangformat/clangformatutils.h b/src/plugins/clangformat/clangformatutils.h index 4668b11e9ef..5e8ac3d9bb6 100644 --- a/src/plugins/clangformat/clangformatutils.h +++ b/src/plugins/clangformat/clangformatutils.h @@ -23,11 +23,6 @@ void createStyleFileIfNeeded(bool isGlobal); QString currentProjectUniqueId(); -std::string currentProjectConfigText(); -std::string currentGlobalConfigText(); - -clang::format::FormatStyle currentProjectStyle(); -clang::format::FormatStyle currentGlobalStyle(); std::string readFile(const QString &path); bool getProjectUseGlobalSettings(const ProjectExplorer::Project *project); @@ -41,7 +36,6 @@ ClangFormatSettings::Mode getCurrentIndentationOrFormattingSettings(const Utils: // Is the style from the matching .clang-format file or global one if it's not found. QString configForFile(Utils::FilePath fileName); -clang::format::FormatStyle styleForFile(Utils::FilePath fileName); void saveStyleToFile(clang::format::FormatStyle style, Utils::FilePath filePath); void addQtcStatementMacros(clang::format::FormatStyle &style);