ClangTools: prevent creating duplicated diagnostic marks

If we already have marks from the analysis for the open file we do not
need to create marks for the explicit analysis.

Fixes: QTCREATORBUG-24955
Change-Id: Id550566c6e9a2dbd4e4eb3e9b9460a7778e39a50
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2020-11-24 13:06:23 +01:00
parent ff74a945be
commit 8f4be88eea
5 changed files with 16 additions and 10 deletions

View File

@@ -821,7 +821,7 @@ void ClangTool::loadDiagnosticsFromFiles()
// Show imported
reset();
onNewDiagnosticsAvailable(diagnostics);
onNewDiagnosticsAvailable(diagnostics, /*generateMarks =*/ true);
setState(State::ImportFinished);
}
@@ -1125,10 +1125,10 @@ QSet<Diagnostic> ClangTool::diagnostics() const
});
}
void ClangTool::onNewDiagnosticsAvailable(const Diagnostics &diagnostics)
void ClangTool::onNewDiagnosticsAvailable(const Diagnostics &diagnostics, bool generateMarks)
{
QTC_ASSERT(m_diagnosticModel, return);
m_diagnosticModel->addDiagnostics(diagnostics);
m_diagnosticModel->addDiagnostics(diagnostics, generateMarks);
}
void ClangTool::updateForCurrentState()

View File

@@ -107,7 +107,7 @@ public:
const QString &name() const;
void onNewDiagnosticsAvailable(const Diagnostics &diagnostics);
void onNewDiagnosticsAvailable(const Diagnostics &diagnostics, bool generateMarks);
QAction *startAction() const { return m_startAction; }
QAction *startOnCurrentFileAction() const { return m_startOnCurrentFileAction; }

View File

@@ -364,8 +364,12 @@ void ClangToolRunWorker::onRunnerFinishedWithSuccess(const QString &filePath)
} else {
if (!m_filesNotAnalyzed.contains(filePath))
m_filesAnalyzed.insert(filePath);
if (!diagnostics.isEmpty())
tool()->onNewDiagnosticsAvailable(diagnostics);
if (!diagnostics.isEmpty()) {
// do not generate marks when we always analyze open files since marks from that
// analysis should be more up to date
const bool generateMarks = !m_runSettings.analyzeOpenFiles();
tool()->onNewDiagnosticsAvailable(diagnostics, generateMarks);
}
}
handleFinished();

View File

@@ -102,7 +102,7 @@ QDebug operator<<(QDebug debug, const Diagnostic &d)
;
}
void ClangToolsDiagnosticModel::addDiagnostics(const Diagnostics &diagnostics)
void ClangToolsDiagnosticModel::addDiagnostics(const Diagnostics &diagnostics, bool generateMarks)
{
const auto onFixitStatusChanged =
[this](const QModelIndex &index, FixitStatus oldStatus, FixitStatus newStatus) {
@@ -129,7 +129,7 @@ void ClangToolsDiagnosticModel::addDiagnostics(const Diagnostics &diagnostics)
// Add to file path item
qCDebug(LOG) << "Adding diagnostic:" << d;
filePathItem->appendChild(new DiagnosticItem(d, onFixitStatusChanged, this));
filePathItem->appendChild(new DiagnosticItem(d, onFixitStatusChanged, generateMarks, this));
}
}
@@ -284,11 +284,12 @@ static QString fullText(const Diagnostic &diagnostic)
DiagnosticItem::DiagnosticItem(const Diagnostic &diag,
const OnFixitStatusChanged &onFixitStatusChanged,
bool generateMark,
ClangToolsDiagnosticModel *parent)
: m_diagnostic(diag)
, m_onFixitStatusChanged(onFixitStatusChanged)
, m_parentModel(parent)
, m_mark(new DiagnosticMark(diag))
, m_mark(generateMark ? new DiagnosticMark(diag) : nullptr)
{
if (diag.hasFixits)
m_fixitStatus = FixitStatus::NotScheduled;

View File

@@ -70,6 +70,7 @@ public:
= std::function<void(const QModelIndex &index, FixitStatus oldStatus, FixitStatus newStatus)>;
DiagnosticItem(const Diagnostic &diag,
const OnFixitStatusChanged &onFixitStatusChanged,
bool generateMark,
ClangToolsDiagnosticModel *parent);
~DiagnosticItem() override;
@@ -112,7 +113,7 @@ class ClangToolsDiagnosticModel : public ClangToolsDiagnosticModelBase
public:
ClangToolsDiagnosticModel(QObject *parent = nullptr);
void addDiagnostics(const Diagnostics &diagnostics);
void addDiagnostics(const Diagnostics &diagnostics, bool generateMarks);
QSet<Diagnostic> diagnostics() const;
enum ItemRole {