forked from qt-creator/qt-creator
Clang: Add tooltip action to remove specific warnings/checks
...from the diagnostic configuration. If no custom diagnostic configuration is set in Projects Mode > Clang, one is created and set for the current project. Otherwise the current custom diagnostic set in the project settings is modified. Change-Id: I5c48280c90f0e807e7333122d504dda302a8b0a9 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "clangdiagnosticconfigsmodel.h"
|
||||
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
@@ -73,7 +74,6 @@ constexpr const char *DEFAULT_TIDY_CHECKS = "-*,"
|
||||
"-readability-braces-around-statements,"
|
||||
"-readability-implicit-bool-conversion,"
|
||||
"-readability-named-parameter";
|
||||
constexpr const char *DEFAULT_CLAZY_CHECKS = "level0";
|
||||
|
||||
static void addConfigForAlmostEveryWarning(ClangDiagnosticConfigsModel &model)
|
||||
{
|
||||
@@ -141,7 +141,7 @@ static void addConfigForClazy(ClangDiagnosticConfigsModel &model)
|
||||
"Clazy level0 checks"));
|
||||
config.setIsReadOnly(true);
|
||||
config.setClangOptions(QStringList{QStringLiteral("-w")});
|
||||
config.setClazyChecks(QString::fromUtf8(DEFAULT_CLAZY_CHECKS));
|
||||
config.setClazyChecks(clazyChecksForLevel(0));
|
||||
|
||||
model.appendOrUpdate(config);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ static void addConfigForTidyAndClazy(ClangDiagnosticConfigsModel &model)
|
||||
config.setClangTidyMode(ClangDiagnosticConfig::TidyMode::ChecksPrefixList);
|
||||
|
||||
config.setClangTidyChecks(QString::fromUtf8(DEFAULT_TIDY_CHECKS));
|
||||
config.setClazyChecks(QString::fromUtf8(DEFAULT_CLAZY_CHECKS));
|
||||
config.setClazyChecks(clazyChecksForLevel(0));
|
||||
|
||||
model.appendOrUpdate(config);
|
||||
}
|
||||
|
||||
@@ -319,16 +319,6 @@ public:
|
||||
m_root->checked = Qt::Unchecked;
|
||||
propagateDown(index(0, 0, QModelIndex()));
|
||||
|
||||
// <= Qt Creator 4.8 settings provide specific levels: {"level0"}
|
||||
if (checks.size() == 1 && checks.first().startsWith("level")) {
|
||||
bool ok = false;
|
||||
const int level = checks.first().mid(5).toInt(&ok);
|
||||
QTC_ASSERT(ok, return);
|
||||
enableChecksByLevel(level);
|
||||
return;
|
||||
}
|
||||
|
||||
// >= Qt Creator 4.9 settings provide specific checks: {c1, c2, ...}
|
||||
for (const QString &check : checks) {
|
||||
const QModelIndex index = indexForCheck(check);
|
||||
if (!index.isValid())
|
||||
@@ -437,23 +427,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void enableChecksByLevel(int level)
|
||||
{
|
||||
if (level < 0)
|
||||
return;
|
||||
|
||||
ClazyChecksTree *node = m_levelNodes.value(level);
|
||||
QTC_ASSERT(node, return);
|
||||
const QModelIndex index = indexForTree(node);
|
||||
QTC_ASSERT(index.isValid(), return);
|
||||
|
||||
node->checked = Qt::Checked;
|
||||
propagateUp(index);
|
||||
propagateDown(index);
|
||||
|
||||
enableChecksByLevel(--level);
|
||||
}
|
||||
|
||||
QModelIndex indexForCheck(const QString &check) const {
|
||||
if (check == "*")
|
||||
return index(0, 0, QModelIndex());
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "clangdiagnosticconfigsmodel.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -79,6 +80,24 @@ static QString skipIndexingBigFilesKey()
|
||||
static QString indexerFileSizeLimitKey()
|
||||
{ return QLatin1String(Constants::CPPTOOLS_INDEXER_FILE_SIZE_LIMIT); }
|
||||
|
||||
static QString convertToNewClazyChecksFormat(const QString &checks)
|
||||
{
|
||||
// Before Qt Creator 4.9 valid values for checks were: "", "levelN".
|
||||
// Starting with Qt Creator 4.9, checks are a comma-separated string of checks: "x,y,z".
|
||||
|
||||
if (checks.isEmpty())
|
||||
return checks;
|
||||
|
||||
if (checks.size() == 6 && checks.startsWith("level")) {
|
||||
bool ok = false;
|
||||
const int level = checks.mid(5).toInt(&ok);
|
||||
QTC_ASSERT(ok, return QString());
|
||||
return clazyChecksForLevel(level);
|
||||
}
|
||||
|
||||
return checks;
|
||||
}
|
||||
|
||||
static ClangDiagnosticConfigs customDiagnosticConfigsFromSettings(QSettings *s)
|
||||
{
|
||||
QTC_ASSERT(s->group() == QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP),
|
||||
@@ -98,7 +117,9 @@ static ClangDiagnosticConfigs customDiagnosticConfigsFromSettings(QSettings *s)
|
||||
s->value(clangDiagnosticConfigsArrayClangTidyModeKey()).toInt()));
|
||||
config.setClangTidyChecks(
|
||||
s->value(clangDiagnosticConfigsArrayClangTidyChecksKey()).toString());
|
||||
config.setClazyChecks(s->value(clangDiagnosticConfigsArrayClazyChecksKey()).toString());
|
||||
|
||||
const QString clazyChecks = s->value(clangDiagnosticConfigsArrayClazyChecksKey()).toString();
|
||||
config.setClazyChecks(convertToNewClazyChecksFormat(clazyChecks));
|
||||
configs.append(config);
|
||||
}
|
||||
s->endArray();
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "cppcodemodelsettings.h"
|
||||
#include "cpptoolsplugin.h"
|
||||
#include "cpptools_clazychecks.h"
|
||||
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -287,4 +288,14 @@ UsePrecompiledHeaders getPchUsage()
|
||||
return UsePrecompiledHeaders::Yes;
|
||||
}
|
||||
|
||||
QString clazyChecksForLevel(int level)
|
||||
{
|
||||
QStringList checks;
|
||||
for (const Constants::ClazyCheckInfo &check : Constants::CLAZY_CHECKS) {
|
||||
if (check.level == level)
|
||||
checks << check.name;
|
||||
}
|
||||
return checks.join(',');
|
||||
}
|
||||
|
||||
} // CppTools
|
||||
|
||||
@@ -80,4 +80,6 @@ UsePrecompiledHeaders CPPTOOLS_EXPORT getPchUsage();
|
||||
int indexerFileSizeLimitInMb();
|
||||
bool fileSizeExceedsLimit(const QFileInfo &fileInfo, int sizeLimitInMb);
|
||||
|
||||
QString clazyChecksForLevel(int level);
|
||||
|
||||
} // CppTools
|
||||
|
||||
Reference in New Issue
Block a user