forked from qt-creator/qt-creator
ClangTools: Do not show text marks for suppressed diagnostics
Do not generate marks for automatic runs and hide them for the explicitly invoked analyzes. Change-Id: Ic48e7b13c424c51e7e1759c588c94bbd45e6d1bb Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -629,8 +629,10 @@ bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
|
||||
const Diagnostic &diag = diagnosticItem->diagnostic();
|
||||
|
||||
// Filtered out?
|
||||
if (m_filterOptions && !m_filterOptions->checks.contains(diag.name))
|
||||
if (m_filterOptions && !m_filterOptions->checks.contains(diag.name)) {
|
||||
diagnosticItem->textMark()->setVisible(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Explicitly suppressed?
|
||||
foreach (const SuppressedDiagnostic &d, m_suppressedDiagnostics) {
|
||||
@@ -640,10 +642,12 @@ bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
|
||||
QFileInfo fi(filePath);
|
||||
if (fi.isRelative())
|
||||
filePath = m_lastProjectDirectory.toString() + QLatin1Char('/') + filePath;
|
||||
if (filePath == diag.location.filePath)
|
||||
if (filePath == diag.location.filePath) {
|
||||
diagnosticItem->textMark()->setVisible(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
diagnosticItem->textMark()->setVisible(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
~DiagnosticItem() override;
|
||||
|
||||
const Diagnostic &diagnostic() const { return m_diagnostic; }
|
||||
TextEditor::TextMark *textMark() { return m_mark; }
|
||||
|
||||
FixitStatus fixItStatus() const { return m_fixitStatus; }
|
||||
void setFixItStatus(const FixitStatus &status);
|
||||
|
||||
@@ -194,6 +194,9 @@ void DocumentClangToolRunner::run()
|
||||
const RunSettings &runSettings = projectSettings->useGlobalSettings()
|
||||
? ClangToolsSettings::instance()->runSettings()
|
||||
: projectSettings->runSettings();
|
||||
|
||||
m_suppressed = projectSettings->suppressedDiagnostics();
|
||||
m_lastProjectDirectory = project->projectDirectory();
|
||||
m_projectSettingsUpdate = connect(projectSettings.data(),
|
||||
&ClangToolsProjectSettings::changed,
|
||||
this,
|
||||
@@ -293,6 +296,9 @@ void DocumentClangToolRunner::onSuccess()
|
||||
TextEditor::RefactorMarkers markers;
|
||||
|
||||
for (const Diagnostic &diagnostic : diagnostics) {
|
||||
if (isSuppressed(diagnostic))
|
||||
continue;
|
||||
|
||||
auto mark = new DiagnosticMark(diagnostic);
|
||||
mark->source = m_currentRunner->name();
|
||||
|
||||
@@ -351,6 +357,20 @@ void DocumentClangToolRunner::cancel()
|
||||
}
|
||||
}
|
||||
|
||||
bool DocumentClangToolRunner::isSuppressed(const Diagnostic &diagnostic) const
|
||||
{
|
||||
auto equalsSuppressed = [this, &diagnostic](const SuppressedDiagnostic &suppressed) {
|
||||
if (suppressed.description != diagnostic.description)
|
||||
return false;
|
||||
QString filePath = suppressed.filePath.toString();
|
||||
QFileInfo fi(filePath);
|
||||
if (fi.isRelative())
|
||||
filePath = m_lastProjectDirectory.toString() + QLatin1Char('/') + filePath;
|
||||
return filePath == diagnostic.location.filePath;
|
||||
};
|
||||
return Utils::anyOf(m_suppressed, equalsSuppressed);
|
||||
}
|
||||
|
||||
const CppTools::ClangDiagnosticConfig DocumentClangToolRunner::getDiagnosticConfig(ProjectExplorer::Project *project)
|
||||
{
|
||||
const auto projectSettings = ClangToolsProjectSettings::getSettings(project);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "clangfileinfo.h"
|
||||
#include "clangtoolsdiagnostic.h"
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
@@ -67,6 +68,7 @@ private:
|
||||
|
||||
void cancel();
|
||||
|
||||
bool isSuppressed(const Diagnostic &diagnostic) const;
|
||||
|
||||
const CppTools::ClangDiagnosticConfig getDiagnosticConfig(ProjectExplorer::Project *project);
|
||||
template<class T>
|
||||
@@ -82,6 +84,8 @@ private:
|
||||
FileInfo m_fileInfo;
|
||||
QMetaObject::Connection m_projectSettingsUpdate;
|
||||
QSet<TextEditor::TextEditorWidget *> m_editorsWithMarkers;
|
||||
SuppressedDiagnosticsList m_suppressed;
|
||||
Utils::FilePath m_lastProjectDirectory;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user