2018-01-17 15:08:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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 https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "clangtidyclazytool.h"
|
|
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
#include "clangfixitsrefactoringchanges.h"
|
2018-05-02 14:51:05 +02:00
|
|
|
#include "clangselectablefilesdialog.h"
|
2018-01-17 15:08:30 +01:00
|
|
|
#include "clangtoolsconstants.h"
|
|
|
|
|
#include "clangtoolsdiagnosticmodel.h"
|
|
|
|
|
#include "clangtoolslogfilereader.h"
|
|
|
|
|
#include "clangtidyclazyruncontrol.h"
|
2018-05-08 17:33:29 +02:00
|
|
|
#include "clangtoolsdiagnosticview.h"
|
2018-05-14 11:40:40 +02:00
|
|
|
#include "clangtoolsprojectsettings.h"
|
|
|
|
|
#include "clangtoolssettings.h"
|
2018-01-17 15:08:30 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
|
2018-05-14 11:40:40 +02:00
|
|
|
#include <cpptools/clangdiagnosticconfigsmodel.h>
|
|
|
|
|
#include <cpptools/cppcodemodelsettings.h>
|
2018-05-02 14:51:05 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2018-05-14 11:40:40 +02:00
|
|
|
#include <cpptools/cpptoolsreuse.h>
|
2018-05-02 14:51:05 +02:00
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <debugger/analyzer/analyzermanager.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
2018-05-15 11:27:14 +02:00
|
|
|
#include <utils/fancylineedit.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
2018-05-15 14:31:48 +02:00
|
|
|
#include <QToolButton>
|
2018-01-17 15:08:30 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
2018-05-14 11:40:40 +02:00
|
|
|
using namespace CppTools;
|
2018-01-17 15:08:30 +01:00
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace ClangTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
static ClangTidyClazyTool *s_instance;
|
|
|
|
|
|
2018-05-16 14:49:12 +02:00
|
|
|
class ApplyFixIts
|
2018-05-15 14:31:48 +02:00
|
|
|
{
|
2018-05-16 14:49:12 +02:00
|
|
|
public:
|
|
|
|
|
class RefactoringFileInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-05-24 09:03:44 +02:00
|
|
|
bool isValid() const { return file.isValid(); }
|
2018-05-16 14:49:12 +02:00
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
FixitsRefactoringFile file;
|
2018-05-16 14:49:12 +02:00
|
|
|
QVector<DiagnosticItem *> diagnosticItems;
|
|
|
|
|
bool hasScheduledFixits = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApplyFixIts(const QVector<DiagnosticItem *> &diagnosticItems)
|
|
|
|
|
{
|
|
|
|
|
for (DiagnosticItem *diagnosticItem : diagnosticItems) {
|
|
|
|
|
const QString &filePath = diagnosticItem->diagnostic().location.filePath;
|
|
|
|
|
QTC_ASSERT(!filePath.isEmpty(), continue);
|
|
|
|
|
|
|
|
|
|
// Get or create refactoring file
|
|
|
|
|
RefactoringFileInfo &fileInfo = m_refactoringFileInfos[filePath];
|
|
|
|
|
if (!fileInfo.isValid())
|
2018-05-24 09:03:44 +02:00
|
|
|
fileInfo.file = FixitsRefactoringFile(filePath);
|
2018-05-16 14:49:12 +02:00
|
|
|
|
|
|
|
|
// Append item
|
|
|
|
|
fileInfo.diagnosticItems += diagnosticItem;
|
|
|
|
|
if (diagnosticItem->fixItStatus() == FixitStatus::Scheduled)
|
|
|
|
|
fileInfo.hasScheduledFixits = true;
|
2018-05-15 14:31:48 +02:00
|
|
|
}
|
2018-05-16 14:49:12 +02:00
|
|
|
}
|
2018-05-15 14:31:48 +02:00
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
static void addFixitOperations(DiagnosticItem *diagnosticItem,
|
|
|
|
|
const FixitsRefactoringFile &file, bool apply)
|
2018-05-16 14:49:12 +02:00
|
|
|
{
|
2018-05-24 09:03:44 +02:00
|
|
|
// Did we already created the fixit operations?
|
|
|
|
|
ReplacementOperations currentOps = diagnosticItem->fixitOperations();
|
|
|
|
|
if (!currentOps.isEmpty()) {
|
|
|
|
|
for (ReplacementOperation *op : currentOps)
|
|
|
|
|
op->apply = apply;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Collect/construct the fixit operations
|
|
|
|
|
ReplacementOperations replacements;
|
|
|
|
|
|
|
|
|
|
for (const ExplainingStep &step : diagnosticItem->diagnostic().explainingSteps) {
|
2018-05-16 14:49:12 +02:00
|
|
|
if (!step.isFixIt)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const Debugger::DiagnosticLocation start = step.ranges.first();
|
|
|
|
|
const Debugger::DiagnosticLocation end = step.ranges.last();
|
2018-06-27 15:29:14 +02:00
|
|
|
const int startPos = file.position(start.filePath, start.line, start.column);
|
|
|
|
|
const int endPos = file.position(start.filePath, end.line, end.column);
|
2018-05-24 09:03:44 +02:00
|
|
|
|
|
|
|
|
auto op = new ReplacementOperation;
|
|
|
|
|
op->pos = startPos;
|
|
|
|
|
op->length = endPos - startPos;
|
|
|
|
|
op->text = step.message;
|
2018-06-27 15:29:14 +02:00
|
|
|
op->fileName = start.filePath;
|
2018-05-24 09:03:44 +02:00
|
|
|
op->apply = apply;
|
|
|
|
|
|
|
|
|
|
replacements += op;
|
2018-05-15 14:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
diagnosticItem->setFixitOperations(replacements);
|
2018-05-15 14:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-16 14:49:12 +02:00
|
|
|
void apply()
|
|
|
|
|
{
|
2018-05-24 09:03:44 +02:00
|
|
|
for (auto it = m_refactoringFileInfos.begin(); it != m_refactoringFileInfos.end(); ++it) {
|
|
|
|
|
RefactoringFileInfo &fileInfo = it.value();
|
2018-05-16 14:49:12 +02:00
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
QVector<DiagnosticItem *> itemsScheduledOrSchedulable;
|
|
|
|
|
QVector<DiagnosticItem *> itemsScheduled;
|
|
|
|
|
QVector<DiagnosticItem *> itemsSchedulable;
|
2018-05-16 14:49:12 +02:00
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
// Construct refactoring operations
|
2018-05-16 14:49:12 +02:00
|
|
|
for (DiagnosticItem *diagnosticItem : fileInfo.diagnosticItems) {
|
|
|
|
|
const FixitStatus fixItStatus = diagnosticItem->fixItStatus();
|
2018-05-24 09:03:44 +02:00
|
|
|
|
|
|
|
|
const bool isScheduled = fixItStatus == FixitStatus::Scheduled;
|
|
|
|
|
const bool isSchedulable = fileInfo.hasScheduledFixits
|
|
|
|
|
&& fixItStatus == FixitStatus::NotScheduled;
|
|
|
|
|
|
|
|
|
|
if (isScheduled || isSchedulable) {
|
|
|
|
|
addFixitOperations(diagnosticItem, fileInfo.file, isScheduled);
|
|
|
|
|
itemsScheduledOrSchedulable += diagnosticItem;
|
|
|
|
|
if (isScheduled)
|
|
|
|
|
itemsScheduled += diagnosticItem;
|
|
|
|
|
else
|
|
|
|
|
itemsSchedulable += diagnosticItem;
|
2018-05-16 14:49:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
// Collect replacements
|
|
|
|
|
ReplacementOperations ops;
|
|
|
|
|
for (DiagnosticItem *item : itemsScheduledOrSchedulable)
|
|
|
|
|
ops += item->fixitOperations();
|
|
|
|
|
|
2018-05-16 14:49:12 +02:00
|
|
|
// Apply file
|
2018-05-24 09:03:44 +02:00
|
|
|
QVector<DiagnosticItem *> itemsApplied;
|
|
|
|
|
QVector<DiagnosticItem *> itemsFailedToApply;
|
|
|
|
|
QVector<DiagnosticItem *> itemsInvalidated;
|
|
|
|
|
|
|
|
|
|
fileInfo.file.setReplacements(ops);
|
|
|
|
|
if (fileInfo.file.apply()) {
|
|
|
|
|
itemsApplied = itemsScheduled;
|
|
|
|
|
} else {
|
|
|
|
|
itemsFailedToApply = itemsScheduled;
|
|
|
|
|
itemsInvalidated = itemsSchedulable;
|
2018-05-16 14:49:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update DiagnosticItem state
|
2018-05-24 09:03:44 +02:00
|
|
|
for (DiagnosticItem *diagnosticItem : itemsScheduled)
|
2018-05-16 14:49:12 +02:00
|
|
|
diagnosticItem->setFixItStatus(FixitStatus::Applied);
|
2018-05-24 09:03:44 +02:00
|
|
|
for (DiagnosticItem *diagnosticItem : itemsFailedToApply)
|
2018-05-16 14:49:12 +02:00
|
|
|
diagnosticItem->setFixItStatus(FixitStatus::FailedToApply);
|
|
|
|
|
for (DiagnosticItem *diagnosticItem : itemsInvalidated)
|
|
|
|
|
diagnosticItem->setFixItStatus(FixitStatus::Invalidated);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QMap<QString, RefactoringFileInfo> m_refactoringFileInfos;
|
|
|
|
|
};
|
2018-05-15 14:31:48 +02:00
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
ClangTidyClazyTool::ClangTidyClazyTool()
|
|
|
|
|
: ClangTool("Clang-Tidy and Clazy")
|
|
|
|
|
{
|
|
|
|
|
setObjectName("ClangTidyClazyTool");
|
|
|
|
|
s_instance = this;
|
|
|
|
|
|
2018-05-08 17:33:29 +02:00
|
|
|
m_diagnosticFilterModel = new DiagnosticFilterModel(this);
|
2018-05-08 17:02:40 +02:00
|
|
|
m_diagnosticFilterModel->setSourceModel(m_diagnosticModel);
|
|
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
m_diagnosticView = new DiagnosticView;
|
2018-01-17 15:08:30 +01:00
|
|
|
initDiagnosticView();
|
2018-05-08 17:02:40 +02:00
|
|
|
m_diagnosticView->setModel(m_diagnosticFilterModel);
|
2018-01-17 15:08:30 +01:00
|
|
|
m_diagnosticView->setObjectName(QLatin1String("ClangTidyClazyIssuesView"));
|
|
|
|
|
m_diagnosticView->setWindowTitle(tr("Clang-Tidy and Clazy Issues"));
|
|
|
|
|
|
2018-05-08 17:02:40 +02:00
|
|
|
foreach (auto * const model,
|
|
|
|
|
QList<QAbstractItemModel *>() << m_diagnosticModel << m_diagnosticFilterModel) {
|
|
|
|
|
connect(model, &QAbstractItemModel::rowsInserted,
|
|
|
|
|
this, &ClangTidyClazyTool::handleStateUpdate);
|
|
|
|
|
connect(model, &QAbstractItemModel::rowsRemoved,
|
|
|
|
|
this, &ClangTidyClazyTool::handleStateUpdate);
|
|
|
|
|
connect(model, &QAbstractItemModel::modelReset,
|
|
|
|
|
this, &ClangTidyClazyTool::handleStateUpdate);
|
|
|
|
|
connect(model, &QAbstractItemModel::layoutChanged, // For QSortFilterProxyModel::invalidate()
|
|
|
|
|
this, &ClangTidyClazyTool::handleStateUpdate);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 10:12:11 +02:00
|
|
|
// Go to previous diagnostic
|
|
|
|
|
auto action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
|
|
|
|
action->setIcon(Utils::Icons::PREV_TOOLBAR.icon());
|
|
|
|
|
action->setToolTip(tr("Go to previous diagnostic."));
|
2018-08-02 10:21:05 +02:00
|
|
|
connect(action, &QAction::triggered, m_diagnosticView, &DetailedErrorView::goBack);
|
2018-05-11 10:12:11 +02:00
|
|
|
m_goBack = action;
|
|
|
|
|
|
|
|
|
|
// Go to next diagnostic
|
|
|
|
|
action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
|
|
|
|
action->setIcon(Utils::Icons::NEXT_TOOLBAR.icon());
|
|
|
|
|
action->setToolTip(tr("Go to next diagnostic."));
|
2018-08-02 10:21:05 +02:00
|
|
|
connect(action, &QAction::triggered, m_diagnosticView, &DetailedErrorView::goNext);
|
2018-05-11 10:12:11 +02:00
|
|
|
m_goNext = action;
|
|
|
|
|
|
2018-05-15 11:27:14 +02:00
|
|
|
// Filter line edit
|
|
|
|
|
m_filterLineEdit = new Utils::FancyLineEdit();
|
|
|
|
|
m_filterLineEdit->setFiltering(true);
|
|
|
|
|
m_filterLineEdit->setHistoryCompleter("CppTools.ClangTidyClazyIssueFilter", true);
|
|
|
|
|
connect(m_filterLineEdit, &Utils::FancyLineEdit::filterChanged, [this](const QString &filter) {
|
|
|
|
|
m_diagnosticFilterModel->setFilterRegExp(
|
|
|
|
|
QRegExp(filter, Qt::CaseSensitive, QRegExp::WildcardUnix));
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-15 14:31:48 +02:00
|
|
|
// Apply fixits button
|
|
|
|
|
m_applyFixitsButton = new QToolButton;
|
|
|
|
|
m_applyFixitsButton->setText(tr("Apply Fixits"));
|
2018-05-16 13:07:10 +02:00
|
|
|
m_applyFixitsButton->setEnabled(false);
|
|
|
|
|
connect(m_diagnosticModel,
|
|
|
|
|
&ClangToolsDiagnosticModel::fixItsToApplyCountChanged,
|
2018-06-21 13:53:41 +02:00
|
|
|
[this](int c) {
|
|
|
|
|
m_applyFixitsButton->setEnabled(c);
|
2018-08-02 10:21:05 +02:00
|
|
|
static_cast<DiagnosticView *>(m_diagnosticView.data())->setSelectedFixItsCount(c);
|
2018-06-21 13:53:41 +02:00
|
|
|
});
|
2018-05-15 14:31:48 +02:00
|
|
|
connect(m_applyFixitsButton, &QToolButton::clicked, [this]() {
|
2018-05-16 14:49:12 +02:00
|
|
|
QVector<DiagnosticItem *> diagnosticItems;
|
|
|
|
|
m_diagnosticModel->rootItem()->forChildrenAtLevel(1, [&](TreeItem *item){
|
|
|
|
|
diagnosticItems += static_cast<DiagnosticItem *>(item);
|
|
|
|
|
});
|
2018-05-15 14:31:48 +02:00
|
|
|
|
2018-05-16 14:49:12 +02:00
|
|
|
ApplyFixIts(diagnosticItems).apply();
|
2018-05-15 14:31:48 +02:00
|
|
|
});
|
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
|
|
|
|
|
const QString toolTip = tr("Clang-Tidy and Clazy use a customized Clang executable from the "
|
|
|
|
|
"Clang project to search for errors and warnings.");
|
|
|
|
|
|
2018-08-13 09:34:47 +02:00
|
|
|
auto perspective = new Perspective(ClangTidyClazyPerspectiveId, tr("Clang-Tidy and Clazy"));
|
2018-08-02 10:21:05 +02:00
|
|
|
perspective->addWindow(m_diagnosticView, Perspective::SplitVertical, nullptr);
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2018-05-11 10:12:11 +02:00
|
|
|
action = new QAction(tr("Clang-Tidy and Clazy..."), this);
|
2018-01-17 15:08:30 +01:00
|
|
|
action->setToolTip(toolTip);
|
|
|
|
|
menu->addAction(ActionManager::registerAction(action, "ClangTidyClazy.Action"),
|
|
|
|
|
Debugger::Constants::G_ANALYZER_TOOLS);
|
2018-05-02 14:51:05 +02:00
|
|
|
QObject::connect(action, &QAction::triggered, this, [this]() { startTool(true); });
|
2018-01-17 15:08:30 +01:00
|
|
|
QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered);
|
|
|
|
|
QObject::connect(m_startAction, &QAction::changed, action, [action, this] {
|
|
|
|
|
action->setEnabled(m_startAction->isEnabled());
|
|
|
|
|
});
|
|
|
|
|
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
perspective->addToolBarAction(m_startAction);
|
|
|
|
|
perspective->addToolBarAction(m_stopAction);
|
|
|
|
|
perspective->addToolBarAction(m_goBack);
|
|
|
|
|
perspective->addToolBarAction(m_goNext);
|
|
|
|
|
perspective->addToolBarWidget(m_filterLineEdit);
|
|
|
|
|
perspective->addToolBarWidget(m_applyFixitsButton);
|
2018-08-01 17:33:41 +02:00
|
|
|
|
2018-08-13 09:34:47 +02:00
|
|
|
Debugger::registerPerspective(perspective);
|
2018-01-17 15:08:30 +01:00
|
|
|
|
|
|
|
|
updateRunActions();
|
|
|
|
|
|
|
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
|
|
|
|
|
this, &ClangTidyClazyTool::updateRunActions);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangTidyClazyTool *ClangTidyClazyTool::instance()
|
|
|
|
|
{
|
|
|
|
|
return s_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 11:40:40 +02:00
|
|
|
static ClangDiagnosticConfig getDiagnosticConfig(Project *project)
|
|
|
|
|
{
|
|
|
|
|
ClangToolsProjectSettings *projectSettings = ClangToolsProjectSettingsManager::getSettings(
|
|
|
|
|
project);
|
|
|
|
|
|
|
|
|
|
Core::Id diagnosticConfigId;
|
|
|
|
|
if (projectSettings->useGlobalSettings())
|
|
|
|
|
diagnosticConfigId = ClangToolsSettings::instance()->savedDiagnosticConfigId();
|
|
|
|
|
else
|
|
|
|
|
diagnosticConfigId = projectSettings->diagnosticConfig();
|
|
|
|
|
|
|
|
|
|
const ClangDiagnosticConfigsModel configsModel(
|
|
|
|
|
CppTools::codeModelSettings()->clangCustomDiagnosticConfigs());
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(configsModel.hasConfigWithId(diagnosticConfigId), return ClangDiagnosticConfig());
|
|
|
|
|
return configsModel.configWithId(diagnosticConfigId);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 14:51:05 +02:00
|
|
|
void ClangTidyClazyTool::startTool(bool askUserForFileSelection)
|
2018-01-17 15:08:30 +01:00
|
|
|
{
|
|
|
|
|
auto runControl = new RunControl(nullptr, Constants::CLANGTIDYCLAZY_RUN_MODE);
|
|
|
|
|
runControl->setDisplayName(tr("Clang-Tidy and Clazy"));
|
|
|
|
|
runControl->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL_TOOLBAR);
|
|
|
|
|
|
|
|
|
|
Project *project = SessionManager::startupProject();
|
|
|
|
|
QTC_ASSERT(project, return);
|
|
|
|
|
|
2018-05-02 14:51:05 +02:00
|
|
|
const FileInfos fileInfos = collectFileInfos(project, askUserForFileSelection);
|
2018-06-28 10:16:48 +02:00
|
|
|
if (fileInfos.empty())
|
2018-05-02 14:51:05 +02:00
|
|
|
return;
|
|
|
|
|
|
2018-05-14 11:40:40 +02:00
|
|
|
auto clangTool = new ClangTidyClazyRunControl(runControl,
|
|
|
|
|
project->activeTarget(),
|
|
|
|
|
getDiagnosticConfig(project),
|
|
|
|
|
fileInfos);
|
2018-01-17 15:08:30 +01:00
|
|
|
|
|
|
|
|
m_stopAction->disconnect();
|
|
|
|
|
connect(m_stopAction, &QAction::triggered, runControl, [runControl] {
|
|
|
|
|
runControl->appendMessage(tr("Clang-Tidy and Clazy tool stopped by user."),
|
|
|
|
|
NormalMessageFormat);
|
|
|
|
|
runControl->initiateStop();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(runControl, &RunControl::stopped, this, [this, clangTool] {
|
|
|
|
|
bool success = clangTool->success();
|
|
|
|
|
setToolBusy(false);
|
|
|
|
|
m_running = false;
|
|
|
|
|
handleStateUpdate();
|
|
|
|
|
updateRunActions();
|
|
|
|
|
emit finished(success);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Debugger::selectPerspective(ClangTidyClazyPerspectiveId);
|
|
|
|
|
|
|
|
|
|
m_diagnosticModel->clear();
|
|
|
|
|
setToolBusy(true);
|
2018-05-08 17:02:40 +02:00
|
|
|
m_diagnosticFilterModel->setProject(project);
|
2018-01-17 15:08:30 +01:00
|
|
|
m_running = true;
|
|
|
|
|
handleStateUpdate();
|
|
|
|
|
updateRunActions();
|
|
|
|
|
|
|
|
|
|
ProjectExplorerPlugin::startRunControl(runControl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangTidyClazyTool::updateRunActions()
|
|
|
|
|
{
|
|
|
|
|
if (m_toolBusy) {
|
|
|
|
|
m_startAction->setEnabled(false);
|
|
|
|
|
QString tooltipText = tr("Clang-Tidy and Clazy are still running.");
|
|
|
|
|
m_startAction->setToolTip(tooltipText);
|
|
|
|
|
m_stopAction->setEnabled(true);
|
|
|
|
|
} else {
|
|
|
|
|
QString toolTip = tr("Start Clang-Tidy and Clazy.");
|
|
|
|
|
Project *project = SessionManager::startupProject();
|
|
|
|
|
Target *target = project ? project->activeTarget() : nullptr;
|
|
|
|
|
const Core::Id cxx = ProjectExplorer::Constants::CXX_LANGUAGE_ID;
|
|
|
|
|
bool canRun = target && project->projectLanguages().contains(cxx)
|
|
|
|
|
&& ToolChainKitInformation::toolChain(target->kit(), cxx);
|
|
|
|
|
if (!canRun)
|
|
|
|
|
toolTip = tr("This is not a C++ project.");
|
|
|
|
|
|
|
|
|
|
m_startAction->setToolTip(toolTip);
|
|
|
|
|
m_startAction->setEnabled(canRun);
|
|
|
|
|
m_stopAction->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangTidyClazyTool::handleStateUpdate()
|
|
|
|
|
{
|
2018-05-11 10:12:11 +02:00
|
|
|
QTC_ASSERT(m_goBack, return);
|
|
|
|
|
QTC_ASSERT(m_goNext, return);
|
2018-01-17 15:08:30 +01:00
|
|
|
QTC_ASSERT(m_diagnosticModel, return);
|
2018-05-11 10:12:11 +02:00
|
|
|
QTC_ASSERT(m_diagnosticFilterModel, return);
|
2018-01-17 15:08:30 +01:00
|
|
|
|
2018-05-29 12:30:59 +02:00
|
|
|
const int issuesFound = m_diagnosticModel->diagnosticsCount();
|
2018-05-11 10:12:11 +02:00
|
|
|
const int issuesVisible = m_diagnosticFilterModel->rowCount();
|
|
|
|
|
m_goBack->setEnabled(issuesVisible > 1);
|
|
|
|
|
m_goNext->setEnabled(issuesVisible > 1);
|
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
QString message;
|
|
|
|
|
if (m_running)
|
|
|
|
|
message = tr("Clang-Tidy and Clazy are running.");
|
|
|
|
|
else
|
|
|
|
|
message = tr("Clang-Tidy and Clazy finished.");
|
|
|
|
|
|
|
|
|
|
message += QLatin1Char(' ');
|
|
|
|
|
if (issuesFound == 0)
|
|
|
|
|
message += tr("No issues found.");
|
|
|
|
|
else
|
|
|
|
|
message += tr("%n issues found.", nullptr, issuesFound);
|
|
|
|
|
|
|
|
|
|
Debugger::showPermanentStatusMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Diagnostic> ClangTidyClazyTool::read(const QString &filePath,
|
|
|
|
|
const QString &logFilePath,
|
|
|
|
|
QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
return LogFileReader::readSerialized(filePath, logFilePath, errorMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangTools
|
|
|
|
|
|