2018-01-17 15:08:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2018 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 "clangtool.h"
|
|
|
|
|
2018-05-02 14:51:05 +02:00
|
|
|
#include "clangselectablefilesdialog.h"
|
2018-01-17 15:08:30 +01:00
|
|
|
#include "clangtoolsconstants.h"
|
|
|
|
#include "clangtoolsdiagnostic.h"
|
|
|
|
#include "clangtoolsdiagnosticmodel.h"
|
2018-05-02 14:51:05 +02:00
|
|
|
#include "clangtoolsutils.h"
|
2018-01-17 15:08:30 +01:00
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2019-08-23 15:25:57 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
2018-05-02 14:51:05 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
|
|
|
|
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>
|
|
|
|
|
2019-02-11 14:53:21 +01:00
|
|
|
#include <utils/algorithm.h>
|
2018-01-17 15:08:30 +01:00
|
|
|
#include <utils/fancymainwindow.h>
|
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QToolButton>
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
using namespace Debugger;
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
namespace ClangTools {
|
|
|
|
namespace Internal {
|
|
|
|
|
2018-05-02 14:51:05 +02:00
|
|
|
static FileInfos sortedFileInfos(const QVector<CppTools::ProjectPart::Ptr> &projectParts)
|
|
|
|
{
|
|
|
|
FileInfos fileInfos;
|
|
|
|
|
|
|
|
for (CppTools::ProjectPart::Ptr projectPart : projectParts) {
|
|
|
|
QTC_ASSERT(projectPart, continue);
|
|
|
|
if (!projectPart->selectedForBuilding)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (const CppTools::ProjectFile &file : projectPart->files) {
|
|
|
|
QTC_ASSERT(file.kind != CppTools::ProjectFile::Unclassified, continue);
|
|
|
|
QTC_ASSERT(file.kind != CppTools::ProjectFile::Unsupported, continue);
|
|
|
|
if (file.path == CppTools::CppModelManager::configurationFileName())
|
|
|
|
continue;
|
|
|
|
|
2019-01-04 09:07:55 +01:00
|
|
|
if (file.active && CppTools::ProjectFile::isSource(file.kind)) {
|
2019-05-28 13:49:26 +02:00
|
|
|
fileInfos.emplace_back(Utils::FilePath::fromString(file.path),
|
2019-01-04 09:07:55 +01:00
|
|
|
file.kind,
|
|
|
|
projectPart);
|
2018-05-02 14:51:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::sort(fileInfos, &FileInfo::file);
|
2018-06-28 10:16:48 +02:00
|
|
|
fileInfos.erase(std::unique(fileInfos.begin(), fileInfos.end()), fileInfos.end());
|
2018-05-02 14:51:05 +02:00
|
|
|
|
|
|
|
return fileInfos;
|
|
|
|
}
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
ClangTool::ClangTool(const QString &name)
|
|
|
|
: m_name(name)
|
|
|
|
{
|
|
|
|
m_diagnosticModel = new ClangToolsDiagnosticModel(this);
|
|
|
|
|
2019-08-23 15:25:57 +02:00
|
|
|
const Utils::Icon RUN_FILE_OVERLAY(
|
|
|
|
{{":/utils/images/run_file.png", Utils::Theme::IconsBaseColor}});
|
|
|
|
|
|
|
|
const Utils::Icon RUN_SELECTED_OVERLAY(
|
|
|
|
{{":/utils/images/runselected_boxes.png", Utils::Theme::BackgroundColorDark},
|
|
|
|
{":/utils/images/runselected_tickmarks.png", Utils::Theme::IconsBaseColor}});
|
|
|
|
|
|
|
|
auto action = new QAction(tr("Analyze Project..."), this);
|
|
|
|
Utils::Icon runSelectedIcon = Utils::Icons::RUN_SMALL_TOOLBAR;
|
|
|
|
for (const Utils::IconMaskAndColor &maskAndColor : RUN_SELECTED_OVERLAY)
|
|
|
|
runSelectedIcon.append(maskAndColor);
|
|
|
|
action->setIcon(runSelectedIcon.icon());
|
|
|
|
m_startAction = action;
|
|
|
|
|
|
|
|
action = new QAction(tr("Analyze Current File"), this);
|
|
|
|
Utils::Icon runFileIcon = Utils::Icons::RUN_SMALL_TOOLBAR;
|
|
|
|
for (const Utils::IconMaskAndColor &maskAndColor : RUN_FILE_OVERLAY)
|
|
|
|
runFileIcon.append(maskAndColor);
|
|
|
|
action->setIcon(runFileIcon.icon());
|
|
|
|
m_startOnCurrentFileAction = action;
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
m_stopAction = Debugger::createStopAction();
|
|
|
|
}
|
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
ClangTool::~ClangTool()
|
|
|
|
{
|
|
|
|
delete m_diagnosticView;
|
|
|
|
}
|
2018-07-31 16:13:11 +02:00
|
|
|
|
2019-08-23 15:25:57 +02:00
|
|
|
FileInfos ClangTool::collectFileInfos(Project *project, FileSelection fileSelection) const
|
2018-05-02 14:51:05 +02:00
|
|
|
{
|
|
|
|
auto projectInfo = CppTools::CppModelManager::instance()->projectInfo(project);
|
|
|
|
QTC_ASSERT(projectInfo.isValid(), return FileInfos());
|
|
|
|
|
|
|
|
const FileInfos allFileInfos = sortedFileInfos(projectInfo.projectParts());
|
|
|
|
|
2019-08-23 15:25:57 +02:00
|
|
|
if (fileSelection == FileSelection::AllFiles)
|
|
|
|
return allFileInfos;
|
|
|
|
|
|
|
|
if (fileSelection == FileSelection::AskUser) {
|
2018-05-02 14:51:05 +02:00
|
|
|
SelectableFilesDialog dialog(projectInfo, allFileInfos);
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
return FileInfos();
|
|
|
|
return dialog.filteredFileInfos();
|
|
|
|
}
|
2019-08-23 15:25:57 +02:00
|
|
|
|
|
|
|
if (fileSelection == FileSelection::CurrentFile) {
|
|
|
|
if (const IDocument *document = EditorManager::currentDocument()) {
|
|
|
|
const Utils::FilePath filePath = document->filePath();
|
|
|
|
if (!filePath.isEmpty()) {
|
|
|
|
const FileInfo fileInfo = Utils::findOrDefault(allFileInfos,
|
|
|
|
[&](const FileInfo &fi) {
|
|
|
|
return fi.file == filePath;
|
|
|
|
});
|
|
|
|
if (!fileInfo.file.isEmpty())
|
|
|
|
return {fileInfo};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
2018-05-02 14:51:05 +02:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:08:30 +01:00
|
|
|
const QString &ClangTool::name() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClangTool::initDiagnosticView()
|
|
|
|
{
|
|
|
|
m_diagnosticView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
m_diagnosticView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
m_diagnosticView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
m_diagnosticView->setAutoScroll(false);
|
|
|
|
}
|
|
|
|
|
2019-01-22 12:04:51 +01:00
|
|
|
QSet<Diagnostic> ClangTool::diagnostics() const
|
2018-01-17 15:08:30 +01:00
|
|
|
{
|
2019-02-11 14:53:21 +01:00
|
|
|
return Utils::filtered(m_diagnosticModel->diagnostics(), [](const Diagnostic &diagnostic) {
|
|
|
|
using CppTools::ProjectFile;
|
|
|
|
return ProjectFile::isSource(ProjectFile::classify(diagnostic.location.filePath));
|
|
|
|
});
|
2018-01-17 15:08:30 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 10:04:01 +02:00
|
|
|
void ClangTool::onNewDiagnosticsAvailable(const Diagnostics &diagnostics)
|
2018-01-17 15:08:30 +01:00
|
|
|
{
|
|
|
|
QTC_ASSERT(m_diagnosticModel, return);
|
|
|
|
m_diagnosticModel->addDiagnostics(diagnostics);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClangTool::setToolBusy(bool busy)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(m_diagnosticView, return);
|
|
|
|
QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor);
|
|
|
|
m_diagnosticView->setCursor(cursor);
|
|
|
|
m_toolBusy = busy;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
} // namespace ClangTools
|