forked from qt-creator/qt-creator
Clang: Warn of potentially expensive checks
...for the code model. If a diagnostic configuration with potentially expensive checks is selected in Options/Preferences > C++ > Code Model, show a warning below the combo box. Change-Id: I52c5c2e229fd50c0fd82f70154fb5b727726ba31 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
namespace ClangTools {
|
||||
namespace Constants {
|
||||
|
||||
const char SETTINGS_PAGE_ID[] = "Analyzer.ClangTools.Settings";
|
||||
const char SETTINGS_ID[] = "ClangTools";
|
||||
const char CLANGTIDYCLAZY_RUN_MODE[] = "ClangTidyClazy.RunMode";
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class ClangToolsOptionsPage : public Core::IOptionsPage
|
||||
public:
|
||||
explicit ClangToolsOptionsPage()
|
||||
{
|
||||
setId("Analyzer.ClangTools.Settings");
|
||||
setId(Constants::SETTINGS_PAGE_ID);
|
||||
setDisplayName(QCoreApplication::translate(
|
||||
"ClangTools::Internal::ClangToolsOptionsPage",
|
||||
"Clang Tools"));
|
||||
|
||||
@@ -28,10 +28,13 @@
|
||||
#include "clangdiagnosticconfigswidget.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "ui_cppcodemodelsettingspage.h"
|
||||
|
||||
#include <clangtools/clangtoolsconstants.h> // for opening the respective options page
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
@@ -43,6 +46,12 @@ CppCodeModelSettingsWidget::CppCodeModelSettingsWidget(QWidget *parent)
|
||||
, m_ui(new Ui::CppCodeModelSettingsPage)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->expensiveChecksHintIcon->setPixmap(Utils::Icons::WARNING.pixmap());
|
||||
m_ui->expensiveChecksHintIcon->setVisible(false);
|
||||
m_ui->expensiveChecksHintText->setVisible(false);
|
||||
connect(m_ui->expensiveChecksHintText, &QLabel::linkActivated, [](const QString &){
|
||||
Core::ICore::showOptionsDialog(ClangTools::Constants::SETTINGS_PAGE_ID);
|
||||
});
|
||||
}
|
||||
|
||||
CppCodeModelSettingsWidget::~CppCodeModelSettingsWidget()
|
||||
@@ -69,6 +78,20 @@ void CppCodeModelSettingsWidget::applyToSettings() const
|
||||
m_settings->toSettings(Core::ICore::settings());
|
||||
}
|
||||
|
||||
static bool hasConfigExpensiveChecks(const Core::Id &configId)
|
||||
{
|
||||
if (!configId.isValid())
|
||||
return false;
|
||||
|
||||
const ClangDiagnosticConfig config
|
||||
= ClangDiagnosticConfigsModel(
|
||||
codeModelSettings()->clangCustomDiagnosticConfigs())
|
||||
.configWithId(configId);
|
||||
|
||||
return !config.clazyChecks().isEmpty()
|
||||
|| config.clangTidyMode() != ClangDiagnosticConfig::TidyMode::Disabled;
|
||||
}
|
||||
|
||||
void CppCodeModelSettingsWidget::setupClangCodeModelWidgets()
|
||||
{
|
||||
const bool isClangActive = CppModelManager::instance()->isClangCodeModelActive();
|
||||
@@ -88,6 +111,17 @@ void CppCodeModelSettingsWidget::setupClangCodeModelWidgets()
|
||||
if (applyClangCodeModelWidgetsToSettings())
|
||||
m_settings->toSettings(Core::ICore::settings());
|
||||
});
|
||||
|
||||
const auto checkForExpensiveChecks = [this](const Core::Id &configId) {
|
||||
const bool visible = hasConfigExpensiveChecks(configId);
|
||||
m_ui->expensiveChecksHintIcon->setVisible(visible);
|
||||
m_ui->expensiveChecksHintText->setVisible(visible);
|
||||
};
|
||||
|
||||
checkForExpensiveChecks(m_ui->clangDiagnosticConfigsSelectionWidget->currentConfigId());
|
||||
connect(m_ui->clangDiagnosticConfigsSelectionWidget,
|
||||
&ClangDiagnosticConfigsSelectionWidget::currentConfigChanged,
|
||||
checkForExpensiveChecks);
|
||||
}
|
||||
|
||||
void CppCodeModelSettingsWidget::setupGeneralWidgets()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>629</width>
|
||||
<width>647</width>
|
||||
<height>440</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -106,6 +106,40 @@
|
||||
<item>
|
||||
<widget class="CppTools::ClangDiagnosticConfigsSelectionWidget" name="clangDiagnosticConfigsSelectionWidget" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="expensiveChecksHintIcon">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="expensiveChecksHintText">
|
||||
<property name="text">
|
||||
<string>The selected configuration has potentially expensive Clang-Tidy or Clazy checks enabled.<br/>Consider to run these in a separate <a href="target">Clang-Tidy and Clazy analyzer</a> run.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user