Clang: Introduce warning configuration per project

Change-Id: I5b9a330274e6f72b0786259eb25aa454877d4eef
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2016-02-26 17:50:38 +01:00
parent b590642a85
commit 83e18c127c
17 changed files with 600 additions and 40 deletions

View File

@@ -29,6 +29,8 @@ SOURCES += \
clanghighlightingmarksreporter.cpp \
clangmodelmanagersupport.cpp \
clangpreprocessorassistproposalitem.cpp \
clangprojectsettings.cpp \
clangprojectsettingswidget.cpp \
clangtextmark.cpp \
clangutils.cpp
@@ -58,9 +60,13 @@ HEADERS += \
clangisdiagnosticrelatedtolocation.h \
clangmodelmanagersupport.h \
clangpreprocessorassistproposalitem.h \
clangprojectsettings.h \
clangprojectsettingswidget.h \
clangtextmark.h \
clangutils.h
FORMS += clangprojectsettingswidget.ui
RESOURCES += \
clangcodemodel.qrc

View File

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

View File

@@ -26,6 +26,7 @@
#include "clangcodemodelplugin.h"
#include "clangconstants.h"
#include "clangprojectsettingswidget.h"
#ifdef WITH_TESTS
# include "test/clangcodecompletion_test.h"
@@ -33,6 +34,10 @@
#include <cpptools/cppmodelmanager.h>
#include <projectexplorer/projectpanelfactory.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <texteditor/textmark.h>
namespace ClangCodeModel {
@@ -48,6 +53,15 @@ void initializeTextMarks()
Utils::Theme::ClangCodeModel_Error_TextMarkColor);
}
void addProjectPanelWidget()
{
auto panelFactory = new ProjectExplorer::ProjectPanelFactory();
panelFactory->setPriority(60);
panelFactory->setDisplayName(ClangProjectSettingsWidget::tr("Clang Code Model"));
panelFactory->setSimpleCreateWidgetFunction<ClangProjectSettingsWidget>(QIcon());
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
}
} // anonymous namespace
bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage)
@@ -58,6 +72,7 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
CppTools::CppModelManager::instance()->activateClangCodeModel(&m_modelManagerSupportProvider);
initializeTextMarks();
addProjectPanelWidget();
return true;
}

View File

@@ -30,11 +30,14 @@
#include "clangfixitoperation.h"
#include "clangfixitoperationsextractor.h"
#include "clanghighlightingmarksreporter.h"
#include "clangprojectsettings.h"
#include "clangutils.h"
#include <diagnosticcontainer.h>
#include <sourcelocationcontainer.h>
#include <cpptools/clangdiagnosticconfigsmodel.h>
#include <cpptools/clangdiagnosticconfigsmodel.h>
#include <cpptools/compileroptionsbuilder.h>
#include <cpptools/cppcodemodelsettings.h>
#include <cpptools/cppmodelmanager.h>
@@ -340,10 +343,25 @@ static QStringList languageOptions(const QString &filePath, CppTools::ProjectPar
return builder.options();
}
static QStringList warningOptions(CppTools::ProjectPart *projectPart)
{
if (projectPart && projectPart->project) {
ClangProjectSettings projectSettings(projectPart->project);
if (!projectSettings.useGlobalWarningConfig()) {
const Core::Id warningConfigId = projectSettings.warningConfigId();
const CppTools::ClangDiagnosticConfigsModel configsModel(
CppTools::codeModelSettings()->clangCustomDiagnosticConfigs());
if (configsModel.hasConfigWithId(warningConfigId))
return configsModel.configWithId(warningConfigId).commandLineOptions();
}
}
return CppTools::codeModelSettings()->clangDiagnosticConfig().commandLineOptions();
}
static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart *projectPart)
{
return languageOptions(filePath, projectPart)
+ CppTools::codeModelSettings()->clangDiagnosticConfig().commandLineOptions();
return languageOptions(filePath, projectPart) + warningOptions(projectPart);
}
ClangBackEnd::FileContainer

View File

@@ -0,0 +1,91 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "clangprojectsettings.h"
namespace ClangCodeModel {
namespace Internal {
static QString useGlobalWarningConfigKey()
{ return QStringLiteral("ClangCodeModel.UseGlobalWarningConfig"); }
static QString warningConfigIdKey()
{ return QStringLiteral("ClangCodeModel.WarningConfigId"); }
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);
}
Core::Id ClangProjectSettings::warningConfigId() const
{
return m_warningConfigId;
}
void ClangProjectSettings::setWarningConfigId(const Core::Id &customConfigId)
{
m_warningConfigId = customConfigId;
}
bool ClangProjectSettings::useGlobalWarningConfig() const
{
return m_useGlobalWarningConfig;
}
void ClangProjectSettings::setUseGlobalWarningConfig(bool useGlobalWarningConfig)
{
m_useGlobalWarningConfig = useGlobalWarningConfig;
}
void ClangProjectSettings::load()
{
const QVariant useGlobalConfigVariant = m_project->namedSettings(useGlobalWarningConfigKey());
const bool useGlobalConfig = useGlobalConfigVariant.isValid()
? useGlobalConfigVariant.toBool()
: true;
setUseGlobalWarningConfig(useGlobalConfig);
setWarningConfigId(Core::Id::fromSetting(m_project->namedSettings(warningConfigIdKey())));
}
void ClangProjectSettings::store()
{
m_project->setNamedSettings(useGlobalWarningConfigKey(), useGlobalWarningConfig());
m_project->setNamedSettings(warningConfigIdKey(), warningConfigId().toSetting());
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,66 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#pragma once
#include <coreplugin/id.h>
#include <projectexplorer/project.h>
#include <QObject>
#include <QString>
namespace ClangCodeModel {
namespace Internal {
class ClangProjectSettings: public QObject
{
Q_OBJECT
public:
ClangProjectSettings(ProjectExplorer::Project *project);
bool useGlobalWarningConfig() const;
void setUseGlobalWarningConfig(bool useGlobalWarningConfig);
Core::Id warningConfigId() const;
void setWarningConfigId(const Core::Id &warningConfigId);
public slots:
void load();
void store();
private:
ProjectExplorer::Project *m_project;
bool m_useGlobalWarningConfig = true;
Core::Id m_warningConfigId;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,160 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "clangprojectsettingswidget.h"
#include "clangprojectsettings.h"
#include <coreplugin/icore.h>
#include <cpptools/clangdiagnosticconfig.h>
#include <cpptools/clangdiagnosticconfigswidget.h>
#include <cpptools/cppcodemodelsettings.h>
#include <cpptools/cpptoolsreuse.h>
static const char GLOBAL_PROXY_CONFIG_ID[] = "globalProxyConfig";
namespace ClangCodeModel {
namespace Internal {
static CppTools::ClangDiagnosticConfig
createConfigRepresentingGlobalSetting(const CppTools::ClangDiagnosticConfig &baseConfig)
{
CppTools::ClangDiagnosticConfig config = baseConfig;
config.setId(GLOBAL_PROXY_CONFIG_ID);
QString displayName = config.displayName();
if (config.isReadOnly())
displayName = CppTools::ClangDiagnosticConfigsModel::displayNameWithBuiltinIndication(config);
displayName = ClangProjectSettingsWidget::tr("Global setting (%1)").arg(displayName);
config.setDisplayName(displayName);
config.setIsReadOnly(true);
return config;
}
static Core::Id globalConfigId(const CppTools::CppCodeModelSettings &settings,
const CppTools::ClangDiagnosticConfigsModel &model)
{
const Core::Id configId = settings.clangDiagnosticConfigId();
if (model.hasConfigWithId(configId))
return configId;
return model.at(0).id(); // Config saved in the settings was removed, fallback to first.
}
static CppTools::ClangDiagnosticConfigsModel
createConfigsModelWithGlobalProxyConfig(const CppTools::CppCodeModelSettings &settings)
{
using namespace CppTools;
ClangDiagnosticConfigsModel configsModel(settings.clangCustomDiagnosticConfigs());
const Core::Id globalId = globalConfigId(settings, configsModel);
const ClangDiagnosticConfig globalConfig = configsModel.configWithId(globalId);
const ClangDiagnosticConfig globalProxy
= createConfigRepresentingGlobalSetting(globalConfig);
configsModel.prepend(globalProxy);
return configsModel;
}
static Core::Id configIdForProject(const ClangProjectSettings &projectSettings)
{
return projectSettings.useGlobalWarningConfig()
? Core::Id(GLOBAL_PROXY_CONFIG_ID)
: projectSettings.warningConfigId();
}
ClangProjectSettingsWidget::ClangProjectSettingsWidget(ProjectExplorer::Project *project)
: m_projectSettings(project)
{
m_ui.setupUi(this);
using namespace CppTools;
m_diagnosticConfigWidget = new ClangDiagnosticConfigsWidget;
m_diagnosticConfigWidget->setConfigWithUndecoratedDisplayName(Core::Id(GLOBAL_PROXY_CONFIG_ID));
refreshDiagnosticConfigsWidgetFromSettings();
connectToCppCodeModelSettingsChanged();
connect(m_diagnosticConfigWidget.data(), &ClangDiagnosticConfigsWidget::currentConfigChanged,
this, &ClangProjectSettingsWidget::onCurrentWarningConfigChanged);
connect(m_diagnosticConfigWidget.data(), &ClangDiagnosticConfigsWidget::customConfigsChanged,
this, &ClangProjectSettingsWidget::onCustomWarningConfigsChanged);
m_ui.diagnosticConfigurationGroupBox->layout()->addWidget(m_diagnosticConfigWidget);
}
void ClangProjectSettingsWidget::onCurrentWarningConfigChanged(const Core::Id &currentConfigId)
{
const bool useGlobalConfig = currentConfigId == Core::Id(GLOBAL_PROXY_CONFIG_ID);
m_projectSettings.setUseGlobalWarningConfig(useGlobalConfig);
m_projectSettings.setWarningConfigId(currentConfigId);
m_projectSettings.store();
}
void ClangProjectSettingsWidget::onCustomWarningConfigsChanged(
const CppTools::ClangDiagnosticConfigs &customConfigs)
{
disconnectFromCppCodeModelSettingsChanged();
const QSharedPointer<CppTools::CppCodeModelSettings> codeModelSettings
= CppTools::codeModelSettings();
codeModelSettings->setClangCustomDiagnosticConfigs(customConfigs);
codeModelSettings->toSettings(Core::ICore::settings());
connectToCppCodeModelSettingsChanged();
}
void ClangProjectSettingsWidget::refreshDiagnosticConfigsWidgetFromSettings()
{
m_diagnosticConfigWidget->refresh(
createConfigsModelWithGlobalProxyConfig(*CppTools::codeModelSettings()),
configIdForProject(m_projectSettings));
}
void ClangProjectSettingsWidget::connectToCppCodeModelSettingsChanged()
{
connect(CppTools::codeModelSettings().data(), &CppTools::CppCodeModelSettings::changed,
this, &ClangProjectSettingsWidget::refreshDiagnosticConfigsWidgetFromSettings);
}
void ClangProjectSettingsWidget::disconnectFromCppCodeModelSettingsChanged()
{
disconnect(CppTools::codeModelSettings().data(), &CppTools::CppCodeModelSettings::changed,
this, &ClangProjectSettingsWidget::refreshDiagnosticConfigsWidgetFromSettings);
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,70 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#pragma once
#include "ui_clangprojectsettingswidget.h"
#include "clangprojectsettings.h"
#include <cpptools/clangdiagnosticconfigsmodel.h>
#include <QPointer>
namespace ProjectExplorer { class Project; }
namespace CppTools { class ClangDiagnosticConfigsWidget; }
namespace ClangCodeModel {
namespace Internal {
class ClangProjectSettingsWidget: public QWidget
{
Q_OBJECT
public:
explicit ClangProjectSettingsWidget(ProjectExplorer::Project *project);
private slots:
void onCurrentWarningConfigChanged(const Core::Id &currentConfigId);
void onCustomWarningConfigsChanged(const CppTools::ClangDiagnosticConfigs &customConfigs);
private:
void refreshDiagnosticConfigsWidgetFromSettings();
void connectToCppCodeModelSettingsChanged();
void disconnectFromCppCodeModelSettingsChanged();
private:
Ui::ClangProjectSettingsWidget m_ui;
ClangProjectSettings m_projectSettings;
QPointer<CppTools::ClangDiagnosticConfigsWidget> m_diagnosticConfigWidget;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,29 @@
<?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">
<item>
<widget class="QGroupBox" name="diagnosticConfigurationGroupBox">
<property name="title">
<string>Warnings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>