Move clang diagnostics config settings to clangd settings page

It was confusing to have both "Clang Code Model" and "clangd" project
settings pages, so we merge them.
Along the way, a lot of code dropped off.

Change-Id: I780850b716195c3729403ae59f0794c11b5c556d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-05-19 14:48:09 +02:00
parent c117e3d3c9
commit 760cf632af
26 changed files with 145 additions and 1005 deletions

View File

@@ -25,8 +25,6 @@ add_qtc_plugin(ClangCodeModel
clangdlocatorfilters.cpp clangdlocatorfilters.h
clangmodelmanagersupport.cpp clangmodelmanagersupport.h
clangpreprocessorassistproposalitem.cpp clangpreprocessorassistproposalitem.h
clangprojectsettings.cpp clangprojectsettings.h
clangprojectsettingswidget.cpp clangprojectsettingswidget.h clangprojectsettingswidget.ui
clangtextmark.cpp clangtextmark.h
clanguiheaderondiskmanager.cpp clanguiheaderondiskmanager.h
clangutils.cpp clangutils.h

View File

@@ -50,11 +50,6 @@ QtcPlugin {
"clangmodelmanagersupport.h",
"clangpreprocessorassistproposalitem.cpp",
"clangpreprocessorassistproposalitem.h",
"clangprojectsettings.cpp",
"clangprojectsettings.h",
"clangprojectsettingswidget.cpp",
"clangprojectsettingswidget.h",
"clangprojectsettingswidget.ui",
"clangtextmark.cpp",
"clangtextmark.h",
"clanguiheaderondiskmanager.cpp",

View File

@@ -26,7 +26,6 @@
#include "clangcodemodelplugin.h"
#include "clangconstants.h"
#include "clangprojectsettingswidget.h"
#include "clangutils.h"
#ifdef WITH_TESTS
@@ -42,6 +41,7 @@
#include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <cppeditor/clangdiagnosticconfig.h>
#include <cppeditor/cppmodelmanager.h>
#include <projectexplorer/buildconfiguration.h>
@@ -58,16 +58,6 @@ using namespace Utils;
namespace ClangCodeModel {
namespace Internal {
static void addProjectPanelWidget()
{
auto panelFactory = new ProjectExplorer::ProjectPanelFactory();
panelFactory->setPriority(60);
panelFactory->setDisplayName(ClangProjectSettingsWidget::tr("Clang Code Model"));
panelFactory->setCreateWidgetFunction(
[&](ProjectExplorer::Project *project) { return new ClangProjectSettingsWidget(project); });
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
}
void ClangCodeModelPlugin::generateCompilationDB()
{
using namespace CppEditor;
@@ -80,13 +70,11 @@ void ClangCodeModelPlugin::generateCompilationDB()
if (!projectInfo)
return;
const CppEditor::ClangDiagnosticConfig warningsConfig
= warningsConfigForProject(target->project());
QFuture<GenerateCompilationDbResult> task
= Utils::runAsync(&Internal::generateCompilationDB, projectInfo,
projectInfo->buildRoot(), CompilationDbPurpose::Project,
warningsConfig,
optionsForProject(target->project(), warningsConfig),
warningsConfigForProject(target->project()),
globalClangOptions(),
FilePath());
Core::ProgressManager::addTask(task, tr("Generating Compilation DB"), "generate compilation db");
m_generatorWatcher.setFuture(task);
@@ -121,8 +109,6 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
CppEditor::CppModelManager::instance()->activateClangCodeModel(&m_modelManagerSupportProvider);
addProjectPanelWidget();
createCompilationDBButton();
return true;

View File

@@ -1163,13 +1163,12 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
QJsonObject initOptions;
const Utils::FilePath includeDir
= CppEditor::ClangdSettings(d->settings).clangdIncludePath();
const CppEditor::ClangDiagnosticConfig warningsConfig = warningsConfigForProject(nullptr);
CppEditor::CompilerOptionsBuilder optionsBuilder = clangOptionsBuilder(
*CppEditor::CppModelManager::instance()->fallbackProjectPart(),
warningsConfig, includeDir);
warningsConfigForProject(nullptr), includeDir);
const CppEditor::UsePrecompiledHeaders usePch = CppEditor::getPchUsage();
const QJsonArray projectPartOptions = fullProjectPartOptions(
optionsBuilder, optionsForProject(nullptr, warningsConfig));
optionsBuilder, globalClangOptions());
const QJsonArray clangOptions = clangOptionsForFile({}, optionsBuilder.projectPart(),
projectPartOptions, usePch);
initOptions.insert("fallbackFlags", clangOptions);
@@ -1608,13 +1607,12 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath,
return;
QJsonObject cdbChanges;
const Utils::FilePath includeDir = CppEditor::ClangdSettings(d->settings).clangdIncludePath();
const CppEditor::ClangDiagnosticConfig warningsConfig = warningsConfigForProject(project());
CppEditor::CompilerOptionsBuilder optionsBuilder = clangOptionsBuilder(
*projectPart, warningsConfig, includeDir);
*projectPart, warningsConfigForProject(project()), includeDir);
const CppEditor::ProjectFile file(filePath.toString(),
CppEditor::ProjectFile::classify(filePath.toString()));
const QJsonArray projectPartOptions = fullProjectPartOptions(
optionsBuilder, optionsForProject(project(), warningsConfig));
optionsBuilder, globalClangOptions());
addToCompilationDb(cdbChanges, *projectPart, CppEditor::getPchUsage(), projectPartOptions,
filePath.parentDir(), file);
QJsonObject settings;

View File

@@ -25,7 +25,6 @@
#include "clangeditordocumentprocessor.h"
#include "clangprojectsettings.h"
#include "clangdiagnostictooltipwidget.h"
#include "clangfixitoperation.h"
#include "clangmodelmanagersupport.h"

View File

@@ -30,7 +30,6 @@
#include "clangdquickfixfactory.h"
#include "clangeditordocumentprocessor.h"
#include "clangdlocatorfilters.h"
#include "clangprojectsettings.h"
#include "clangutils.h"
#include <coreplugin/documentmanager.h>
@@ -137,19 +136,12 @@ ClangModelManagerSupport::ClangModelManagerSupport()
});
auto *sessionManager = ProjectExplorer::SessionManager::instance();
connect(sessionManager, &ProjectExplorer::SessionManager::projectAdded,
this, &ClangModelManagerSupport::onProjectAdded);
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
this, &ClangModelManagerSupport::onAboutToRemoveProject);
connect(sessionManager, &ProjectExplorer::SessionManager::projectRemoved,
this, [this] { claimNonProjectSources(clientForProject(fallbackProject())); });
CppEditor::ClangdSettings::setDefaultClangdPath(Core::ICore::clangdExecutable(CLANG_BINDIR));
connect(&CppEditor::ClangdSettings::instance(), &CppEditor::ClangdSettings::changed,
this, &ClangModelManagerSupport::onClangdSettingsChanged);
CppEditor::CppCodeModelSettings *settings = CppEditor::codeModelSettings();
connect(settings, &CppEditor::CppCodeModelSettings::clangDiagnosticConfigsInvalidated,
this, &ClangModelManagerSupport::onDiagnosticConfigsInvalidated);
if (CppEditor::ClangdSettings::instance().useClangd())
createClient(nullptr, {});
@@ -160,7 +152,6 @@ ClangModelManagerSupport::ClangModelManagerSupport()
ClangModelManagerSupport::~ClangModelManagerSupport()
{
QTC_CHECK(m_projectSettings.isEmpty());
m_generatorSynchronizer.waitForFinished();
m_instance = nullptr;
}
@@ -427,11 +418,10 @@ void ClangModelManagerSupport::updateLanguageClient(
});
const Utils::FilePath includeDir = settings.clangdIncludePath();
const ClangDiagnosticConfig warningsConfig = warningsConfigForProject(project);
auto future = Utils::runAsync(&Internal::generateCompilationDB, projectInfo, jsonDbDir,
CompilationDbPurpose::CodeModel,
warningsConfig, optionsForProject(project, warningsConfig),
includeDir);
warningsConfigForProject(project),
globalClangOptions(), includeDir);
generatorWatcher->setFuture(future);
m_generatorSynchronizer.addFuture(future);
}
@@ -670,42 +660,6 @@ static ClangEditorDocumentProcessors clangProcessors()
return result;
}
static ClangEditorDocumentProcessors
clangProcessorsWithProject(const ProjectExplorer::Project *project)
{
return ::Utils::filtered(clangProcessors(), [project](ClangEditorDocumentProcessor *p) {
return p->hasProjectPart() && p->projectPart()->belongsToProject(project);
});
}
static void updateProcessors(const ClangEditorDocumentProcessors &processors)
{
CppEditor::CppModelManager *modelManager = cppModelManager();
for (ClangEditorDocumentProcessor *processor : processors)
modelManager->cppEditorDocument(processor->filePath())->resetProcessor();
modelManager->updateCppEditorDocuments(/*projectsUpdated=*/ false);
}
void ClangModelManagerSupport::onProjectAdded(ProjectExplorer::Project *project)
{
QTC_ASSERT(!m_projectSettings.value(project), return);
auto *settings = new Internal::ClangProjectSettings(project);
connect(settings, &Internal::ClangProjectSettings::changed, [project]() {
updateProcessors(clangProcessorsWithProject(project));
});
m_projectSettings.insert(project, settings);
}
void ClangModelManagerSupport::onAboutToRemoveProject(ProjectExplorer::Project *project)
{
ClangProjectSettings * const settings = m_projectSettings.value(project);
QTC_ASSERT(settings, return);
m_projectSettings.remove(project);
delete settings;
}
void ClangModelManagerSupport::onProjectPartsUpdated(ProjectExplorer::Project *project)
{
QTC_ASSERT(project, return);
@@ -765,19 +719,6 @@ void ClangModelManagerSupport::onClangdSettingsChanged()
}
}
static ClangEditorDocumentProcessors clangProcessorsWithDiagnosticConfig(
const QVector<::Utils::Id> &configIds)
{
return ::Utils::filtered(clangProcessors(), [configIds](ClangEditorDocumentProcessor *p) {
return configIds.contains(p->diagnosticConfigId());
});
}
void ClangModelManagerSupport::onDiagnosticConfigsInvalidated(const QVector<::Utils::Id> &configIds)
{
updateProcessors(clangProcessorsWithDiagnosticConfig(configIds));
}
static ClangEditorDocumentProcessors
clangProcessorsWithProjectParts(const QStringList &projectPartIds)
{
@@ -805,12 +746,6 @@ QString ClangModelManagerSupport::dummyUiHeaderOnDiskPath(const QString &filePat
return m_uiHeaderOnDiskManager.mapPath(filePath);
}
ClangProjectSettings &ClangModelManagerSupport::projectSettings(
ProjectExplorer::Project *project) const
{
return *m_projectSettings.value(project);
}
QString ClangModelManagerSupport::dummyUiHeaderOnDiskDirPath() const
{
return m_uiHeaderOnDiskManager.directoryPath();

View File

@@ -51,7 +51,6 @@ namespace ClangCodeModel {
namespace Internal {
class ClangdClient;
class ClangProjectSettings;
class ClangModelManagerSupport:
public QObject,
@@ -74,8 +73,6 @@ public:
QString dummyUiHeaderOnDiskDirPath() const;
QString dummyUiHeaderOnDiskPath(const QString &filePath) const;
ClangProjectSettings &projectSettings(ProjectExplorer::Project *project) const;
ClangdClient *clientForProject(const ProjectExplorer::Project *project) const;
ClangdClient *clientForFile(const Utils::FilePath &file) const;
@@ -111,15 +108,10 @@ private:
int lineNumber,
QMenu *menu);
void onProjectAdded(ProjectExplorer::Project *project);
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onProjectPartsUpdated(ProjectExplorer::Project *project);
void onProjectPartsRemoved(const QStringList &projectPartIds);
void onClangdSettingsChanged();
void onDiagnosticConfigsInvalidated(const QVector<::Utils::Id> &configIds);
void reinitializeBackendDocuments(const QStringList &projectPartIds);
void connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument);
@@ -134,7 +126,6 @@ private:
UiHeaderOnDiskManager m_uiHeaderOnDiskManager;
QHash<ProjectExplorer::Project *, ClangProjectSettings *> m_projectSettings;
Utils::FutureSynchronizer m_generatorSynchronizer;
QList<QPointer<ClangdClient>> m_clientsToRestart;
};

View File

@@ -1,147 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "clangprojectsettings.h"
#include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cpptoolsreuse.h>
#include <utils/qtcassert.h>
#include <utils/hostosinfo.h>
#include <QDebug>
namespace ClangCodeModel {
namespace Internal {
static QString useGlobalConfigKey()
{ return QStringLiteral("ClangCodeModel.UseGlobalConfig"); }
static QString warningConfigIdKey()
{ return QStringLiteral("ClangCodeModel.WarningConfigId"); }
static QString customCommandLineKey()
{ return QLatin1String("ClangCodeModel.CustomCommandLineKey"); }
static bool useGlobalConfigFromSettings(ProjectExplorer::Project *project)
{
const QVariant useGlobalConfigVariant = project->namedSettings(useGlobalConfigKey());
return useGlobalConfigVariant.isValid() ? useGlobalConfigVariant.toBool() : true;
}
static Utils::Id warningConfigIdFromSettings(ProjectExplorer::Project *project)
{
return Utils::Id::fromSetting(project->namedSettings(warningConfigIdKey()));
}
static QStringList customCommandLineFromSettings(ProjectExplorer::Project *project)
{
QStringList options = project->namedSettings(customCommandLineKey()).toStringList();
if (options.empty())
options = ClangProjectSettings::globalCommandLineOptions();
return options;
}
ClangProjectSettings::ClangProjectSettings(ProjectExplorer::Project *project)
: m_project(project)
{
load();
connect(project, &ProjectExplorer::Project::settingsLoaded,
this, &ClangProjectSettings::load);
connect(project, &ProjectExplorer::Project::aboutToSaveSettings,
this, &ClangProjectSettings::store);
}
Utils::Id ClangProjectSettings::warningConfigId() const
{
const CppEditor::ClangDiagnosticConfigsModel model = CppEditor::diagnosticConfigsModel();
if (!model.hasConfigWithId(m_warningConfigId))
return CppEditor::codeModelSettings()->defaultClangDiagnosticConfigId();
return m_warningConfigId;
}
void ClangProjectSettings::setWarningConfigId(const Utils::Id &customConfigId)
{
m_warningConfigId = customConfigId;
}
bool ClangProjectSettings::useGlobalConfig() const
{
return m_useGlobalConfig;
}
void ClangProjectSettings::setUseGlobalConfig(bool useGlobalConfig)
{
m_useGlobalConfig = useGlobalConfig;
}
QStringList ClangProjectSettings::commandLineOptions() const
{
return m_useGlobalConfig ? globalCommandLineOptions()
: m_customCommandLineOptions;
}
void ClangProjectSettings::setCommandLineOptions(const QStringList &options)
{
QTC_ASSERT(!m_useGlobalConfig, qDebug()
<< "setCommandLineOptions was called while using global project config");
m_customCommandLineOptions = options;
}
void ClangProjectSettings::load()
{
setUseGlobalConfig(useGlobalConfigFromSettings(m_project));
setWarningConfigId(warningConfigIdFromSettings(m_project));
m_customCommandLineOptions = customCommandLineFromSettings(m_project);
}
void ClangProjectSettings::store()
{
bool settingsChanged = false;
if (useGlobalConfig() != useGlobalConfigFromSettings(m_project))
settingsChanged = true;
if (warningConfigId() != warningConfigIdFromSettings(m_project))
settingsChanged = true;
if (commandLineOptions() != customCommandLineFromSettings(m_project))
settingsChanged = true;
m_project->setNamedSettings(useGlobalConfigKey(), useGlobalConfig());
m_project->setNamedSettings(warningConfigIdKey(), warningConfigId().toSetting());
m_project->setNamedSettings(customCommandLineKey(), m_customCommandLineOptions);
if (settingsChanged)
emit changed();
}
QStringList ClangProjectSettings::globalCommandLineOptions()
{
if (Utils::HostOsInfo::isWindowsHost())
return {QLatin1String{GlobalWindowsCmdOptions}};
return {};
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,75 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <projectexplorer/project.h>
#include <utils/id.h>
#include <QObject>
#include <QString>
namespace ClangCodeModel {
namespace Internal {
class ClangProjectSettings: public QObject
{
Q_OBJECT
public:
constexpr static const char* DelayedTemplateParsing = "-fdelayed-template-parsing";
constexpr static const char* NoDelayedTemplateParsing = "-fno-delayed-template-parsing";
constexpr static const char* GlobalWindowsCmdOptions = NoDelayedTemplateParsing;
ClangProjectSettings(ProjectExplorer::Project *project);
bool useGlobalConfig() const;
void setUseGlobalConfig(bool useGlobalConfig);
::Utils::Id warningConfigId() const;
void setWarningConfigId(const ::Utils::Id &warningConfigId);
QStringList commandLineOptions() const;
void setCommandLineOptions(const QStringList &options);
void load();
void store();
static QStringList globalCommandLineOptions();
signals:
void changed();
private:
ProjectExplorer::Project *m_project;
bool m_useGlobalConfig = true;
::Utils::Id m_warningConfigId;
QStringList m_customCommandLineOptions;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,159 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "clangprojectsettingswidget.h"
#include "clangmodelmanagersupport.h"
#include "clangprojectsettings.h"
#include <coreplugin/icore.h>
#include <cppeditor/clangdiagnosticconfig.h>
#include <cppeditor/clangdiagnosticconfigswidget.h>
#include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cpptoolsreuse.h>
#include <utils/hostosinfo.h>
namespace ClangCodeModel {
namespace Internal {
static Utils::Id configIdForProject(ClangProjectSettings &projectSettings)
{
if (projectSettings.useGlobalConfig())
return CppEditor::codeModelSettings()->clangDiagnosticConfigId();
return projectSettings.warningConfigId();
}
ClangProjectSettingsWidget::ClangProjectSettingsWidget(ProjectExplorer::Project *project)
: m_projectSettings(ClangModelManagerSupport::instance()->projectSettings(project))
{
m_ui.setupUi(this);
using namespace CppEditor;
m_ui.delayedTemplateParseCheckBox->setVisible(Utils::HostOsInfo::isWindowsHost());
// Links
connect(m_ui.gotoGlobalSettingsLabel, &QLabel::linkActivated, [](const QString &) {
Core::ICore::showOptionsDialog(CppEditor::Constants::CPP_CODE_MODEL_SETTINGS_ID);
});
connect(m_ui.clangDiagnosticConfigsSelectionWidget,
&ClangDiagnosticConfigsSelectionWidget::changed,
this,
[this]() {
// Save project's config id
const Utils::Id currentConfigId = m_ui.clangDiagnosticConfigsSelectionWidget
->currentConfigId();
m_projectSettings.setWarningConfigId(currentConfigId);
// Save global custom configs
const ClangDiagnosticConfigs configs = m_ui.clangDiagnosticConfigsSelectionWidget
->customConfigs();
CppEditor::codeModelSettings()->setClangCustomDiagnosticConfigs(configs);
CppEditor::codeModelSettings()->toSettings(Core::ICore::settings());
});
connect(m_ui.delayedTemplateParseCheckBox, &QCheckBox::toggled,
this, &ClangProjectSettingsWidget::onDelayedTemplateParseClicked);
connect(m_ui.globalOrCustomComboBox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &ClangProjectSettingsWidget::onGlobalCustomChanged);
connect(project, &ProjectExplorer::Project::aboutToSaveSettings,
this, &ClangProjectSettingsWidget::onAboutToSaveProjectSettings);
connect(&m_projectSettings, &ClangProjectSettings::changed,
this, &ClangProjectSettingsWidget::syncWidgets);
connect(CppEditor::codeModelSettings(), &CppEditor::CppCodeModelSettings::changed,
this, &ClangProjectSettingsWidget::syncOtherWidgetsToComboBox);
syncWidgets();
}
void ClangProjectSettingsWidget::onDelayedTemplateParseClicked(bool checked)
{
// Don't save it when we reset the global config in code
if (m_projectSettings.useGlobalConfig())
return;
const QLatin1String extraFlag{checked ? ClangProjectSettings::DelayedTemplateParsing
: ClangProjectSettings::NoDelayedTemplateParsing};
QStringList options = m_projectSettings.commandLineOptions();
options.removeAll(QLatin1String{ClangProjectSettings::DelayedTemplateParsing});
options.removeAll(QLatin1String{ClangProjectSettings::NoDelayedTemplateParsing});
options.append(extraFlag);
m_projectSettings.setCommandLineOptions(options);
}
void ClangProjectSettingsWidget::onGlobalCustomChanged(int index)
{
m_projectSettings.setUseGlobalConfig(index == 0 ? true : false);
syncOtherWidgetsToComboBox();
}
void ClangProjectSettingsWidget::onAboutToSaveProjectSettings()
{
CppEditor::codeModelSettings()->toSettings(Core::ICore::settings());
}
void ClangProjectSettingsWidget::syncWidgets()
{
syncGlobalCustomComboBox();
syncOtherWidgetsToComboBox();
}
void ClangProjectSettingsWidget::syncGlobalCustomComboBox()
{
m_ui.globalOrCustomComboBox->setCurrentIndex(m_projectSettings.useGlobalConfig() ? 0 : 1);
}
void ClangProjectSettingsWidget::syncOtherWidgetsToComboBox()
{
const QStringList options = m_projectSettings.commandLineOptions();
m_ui.delayedTemplateParseCheckBox->setChecked(
options.contains(QLatin1String{ClangProjectSettings::DelayedTemplateParsing}));
const bool isCustom = !m_projectSettings.useGlobalConfig();
m_ui.delayedTemplateParseCheckBox->setEnabled(isCustom);
for (int i = 0; i < m_ui.clangDiagnosticConfigsSelectionWidget->layout()->count(); ++i) {
QWidget *widget = m_ui.clangDiagnosticConfigsSelectionWidget->layout()->itemAt(i)->widget();
if (widget)
widget->setEnabled(isCustom);
}
m_ui.clangDiagnosticConfigsSelectionWidget
->refresh(CppEditor::diagnosticConfigsModel(),
configIdForProject(m_projectSettings),
[](const CppEditor::ClangDiagnosticConfigs &configs,
const Utils::Id &configToSelect) {
return new CppEditor::ClangDiagnosticConfigsWidget(configs, configToSelect);
});
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,61 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "ui_clangprojectsettingswidget.h"
#include "clangprojectsettings.h"
#include <QPointer>
namespace ProjectExplorer { class Project; }
namespace ClangCodeModel {
namespace Internal {
class ClangProjectSettingsWidget: public QWidget
{
Q_OBJECT
public:
explicit ClangProjectSettingsWidget(ProjectExplorer::Project *project);
private:
void onDelayedTemplateParseClicked(bool);
void onGlobalCustomChanged(int index);
void onAboutToSaveProjectSettings();
void syncWidgets();
void syncGlobalCustomComboBox();
void syncOtherWidgetsToComboBox();
private:
Ui::ClangProjectSettingsWidget m_ui;
ClangProjectSettings &m_projectSettings;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,98 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ClangCodeModel::Internal::ClangProjectSettingsWidget</class>
<widget class="QWidget" name="ClangCodeModel::Internal::ClangProjectSettingsWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>814</width>
<height>330</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="globalOrCustomComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Use Global Settings</string>
</property>
</item>
<item>
<property name="text">
<string>Use Customized Settings</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="gotoGlobalSettingsLabel">
<property name="text">
<string>&lt;a href=&quot;target&quot;&gt;Open Global Settings&lt;/a&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="delayedTemplateParseCheckBox">
<property name="toolTip">
<string>Parse templates in a MSVC-compliant way. This helps to parse headers for example from Active Template Library (ATL) or Windows Runtime Library (WRL).
However, using the relaxed and extended rules means also that no highlighting/completion can be provided within template functions.</string>
</property>
<property name="text">
<string>Enable MSVC-compliant template parsing</string>
</property>
</widget>
</item>
<item>
<widget class="CppEditor::ClangDiagnosticConfigsSelectionWidget" name="clangDiagnosticConfigsSelectionWidget" native="true"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>CppEditor::ClangDiagnosticConfigsSelectionWidget</class>
<extends>QWidget</extends>
<header>cppeditor/clangdiagnosticconfigsselectionwidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -30,7 +30,6 @@
#include "clangdiagnostictooltipwidget.h"
#include "clangeditordocumentprocessor.h"
#include "clangmodelmanagersupport.h"
#include "clangprojectsettings.h"
#include "clangutils.h"
#include <coreplugin/icore.h>
@@ -113,33 +112,18 @@ void disableDiagnosticInConfig(ClangDiagnosticConfig &config, const ClangDiagnos
}
}
ClangDiagnosticConfig diagnosticConfig(const ClangProjectSettings &projectSettings,
const CppCodeModelSettings &globalSettings)
ClangDiagnosticConfig diagnosticConfig()
{
Project *project = projectForCurrentEditor();
QTC_ASSERT(project, return {});
// Get config id
Id currentConfigId = projectSettings.warningConfigId();
if (projectSettings.useGlobalConfig())
currentConfigId = globalSettings.clangDiagnosticConfigId();
// Get config
ClangDiagnosticConfigsModel configsModel = CppEditor::diagnosticConfigsModel();
QTC_ASSERT(configsModel.hasConfigWithId(currentConfigId), return {});
return configsModel.configWithId(currentConfigId);
return warningsConfigForProject(project);
}
bool isDiagnosticConfigChangable(Project *project, const ClangDiagnostic &diagnostic)
{
if (!project)
return false;
ClangProjectSettings &projectSettings = ClangModelManagerSupport::instance()->projectSettings(
project);
const CppCodeModelSettings *globalSettings = codeModelSettings();
const ClangDiagnosticConfig config = diagnosticConfig(projectSettings, *globalSettings);
const ClangDiagnosticConfig config = diagnosticConfig();
if (config.clangTidyMode() == ClangDiagnosticConfig::TidyMode::UseConfigFile
&& diagnosticType(diagnostic) == DiagnosticType::Tidy) {
return false;
@@ -152,13 +136,8 @@ void disableDiagnosticInCurrentProjectConfig(const ClangDiagnostic &diagnostic)
Project *project = projectForCurrentEditor();
QTC_ASSERT(project, return );
// Get settings
ClangProjectSettings &projectSettings = ClangModelManagerSupport::instance()->projectSettings(
project);
CppCodeModelSettings *globalSettings = codeModelSettings();
// Get config
ClangDiagnosticConfig config = diagnosticConfig(projectSettings, *globalSettings);
ClangDiagnosticConfig config = diagnosticConfig();
ClangDiagnosticConfigsModel configsModel = CppEditor::diagnosticConfigsModel();
// Create copy if needed
@@ -174,14 +153,13 @@ void disableDiagnosticInCurrentProjectConfig(const ClangDiagnostic &diagnostic)
configsModel.appendOrUpdate(config);
// Set global settings
globalSettings->setClangCustomDiagnosticConfigs(configsModel.customConfigs());
globalSettings->toSettings(Core::ICore::settings());
ClangdSettings::setCustomDiagnosticConfigs(configsModel.customConfigs());
// Set project settings
if (projectSettings.useGlobalConfig())
projectSettings.setUseGlobalConfig(false);
projectSettings.setWarningConfigId(config.id());
projectSettings.store();
ClangdProjectSettings projectSettings(project);
if (projectSettings.useGlobalSettings())
projectSettings.setUseGlobalSettings(false);
projectSettings.setDiagnosticConfigId(config.id());
// Notify the user about changed project specific settings
const QString text

View File

@@ -25,13 +25,12 @@
#include "clangutils.h"
#include "clangeditordocumentprocessor.h"
#include "clangmodelmanagersupport.h"
#include "clangprojectsettings.h"
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cppeditor/baseeditordocumentparser.h>
#include <cppeditor/clangdiagnosticconfigsmodel.h>
#include <cppeditor/compileroptionsbuilder.h>
#include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cppmodelmanager.h>
@@ -276,14 +275,6 @@ QString DiagnosticTextInfo::clazyCheckName(const QString &option)
}
namespace {
static ClangProjectSettings &getProjectSettings(ProjectExplorer::Project *project)
{
QTC_CHECK(project);
return ClangModelManagerSupport::instance()->projectSettings(project);
}
} // namespace
QJsonArray clangOptionsForFile(const ProjectFile &file, const ProjectPart &projectPart,
const QJsonArray &generalOptions, UsePrecompiledHeaders usePch)
{
@@ -308,30 +299,12 @@ QJsonArray clangOptionsForFile(const ProjectFile &file, const ProjectPart &proje
ClangDiagnosticConfig warningsConfigForProject(Project *project)
{
if (project) {
ClangProjectSettings &projectSettings = ClangModelManagerSupport::instance()
->projectSettings(project);
if (!projectSettings.useGlobalConfig()) {
const Utils::Id warningConfigId = projectSettings.warningConfigId();
const CppEditor::ClangDiagnosticConfigsModel configsModel
= CppEditor::diagnosticConfigsModel();
if (configsModel.hasConfigWithId(warningConfigId))
return configsModel.configWithId(warningConfigId);
}
}
return CppEditor::codeModelSettings()->clangDiagnosticConfig();
return ClangdSettings(ClangdProjectSettings(project).settings()).diagnosticConfig();
}
const QStringList optionsForProject(ProjectExplorer::Project *project,
const ClangDiagnosticConfig &warningsConfig)
const QStringList globalClangOptions()
{
QStringList options = ClangDiagnosticConfigsModel::globalDiagnosticOptions();
if (!warningsConfig.useBuildSystemWarnings()) {
options += project
? getProjectSettings(project).commandLineOptions()
: ClangProjectSettings::globalCommandLineOptions();
}
return options;
return ClangDiagnosticConfigsModel::globalDiagnosticOptions();
}
// 7.3.3: using typename(opt) nested-name-specifier unqualified-id ;

View File

@@ -52,8 +52,7 @@ namespace ClangCodeModel {
namespace Internal {
CppEditor::ClangDiagnosticConfig warningsConfigForProject(ProjectExplorer::Project *project);
const QStringList optionsForProject(ProjectExplorer::Project *project,
const CppEditor::ClangDiagnosticConfig &warningsConfig);
const QStringList globalClangOptions();
CppEditor::CompilerOptionsBuilder clangOptionsBuilder(
const CppEditor::ProjectPart &projectPart,