Debugger: Replace DiagnosticsLocation with Utils::Link

Change-Id: I41166d4f54468e0953fd3231af9fd52560b7c74c
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2025-02-18 18:08:02 +01:00
parent aab000e222
commit a40e803503
25 changed files with 144 additions and 192 deletions

View File

@@ -32,4 +32,18 @@ Link Link::fromString(const QString &filePathWithNumbers, bool canContainLineNum
return link;
}
bool operator<(const Link &first, const Link &second)
{
return std::tie(first.targetFilePath, first.targetLine, first.targetColumn)
< std::tie(second.targetFilePath, second.targetLine, second.targetColumn);
}
QDebug operator<<(QDebug dbg, const Link &link)
{
dbg.nospace() << "Link(" << link.targetFilePath << ", "
<< link.targetLine << ", "
<< link.targetColumn << ')';
return dbg.space();
}
} // namespace Utils

View File

@@ -7,6 +7,7 @@
#include "filepath.h"
#include <QDebug>
#include <QMetaType>
#include <QString>
@@ -44,6 +45,9 @@ public:
}
bool operator!=(const Link &other) const { return !(*this == other); }
QTCREATOR_UTILS_EXPORT friend bool operator<(const Link &first, const Link &second);
QTCREATOR_UTILS_EXPORT friend QDebug operator<<(QDebug dbg, const Link &link);
bool hasSameLocation(const Link &other) const
{
return targetFilePath == other.targetFilePath

View File

@@ -228,7 +228,7 @@ public:
ApplyFixIts(const QVector<DiagnosticItem *> &diagnosticItems)
{
for (DiagnosticItem *diagnosticItem : diagnosticItems) {
const FilePath &filePath = diagnosticItem->diagnostic().location.filePath;
const FilePath &filePath = diagnosticItem->diagnostic().location.targetFilePath;
QTC_ASSERT(!filePath.isEmpty(), continue);
// Get or create refactoring file
@@ -262,16 +262,20 @@ public:
if (!step.isFixIt)
continue;
const DiagnosticLocation start = step.ranges.first();
const DiagnosticLocation end = step.ranges.last();
const int startPos = file.position(start.filePath, start.line, start.column);
const int endPos = file.position(start.filePath, end.line, end.column);
const Link start = step.ranges.first();
const Link end = step.ranges.last();
const int startPos = file.position(start.targetFilePath,
start.targetLine,
start.targetColumn);
const int endPos = file.position(start.targetFilePath,
end.targetLine,
end.targetColumn);
auto op = new ReplacementOperation;
op->pos = startPos;
op->length = endPos - startPos;
op->text = step.message;
op->filePath = start.filePath;
op->filePath = start.targetFilePath;
op->apply = apply;
replacements += op;
@@ -1244,7 +1248,7 @@ void ClangTool::setState(State state)
QSet<Diagnostic> ClangTool::diagnostics() const
{
return Utils::filtered(m_diagnosticModel->diagnostics(), [](const Diagnostic &diagnostic) {
return ProjectFile::isSource(ProjectFile::classify(diagnostic.location.filePath));
return ProjectFile::isSource(ProjectFile::classify(diagnostic.location.targetFilePath));
});
}

View File

@@ -10,7 +10,7 @@ namespace Internal {
bool ExplainingStep::isValid() const
{
return location.isValid() && !ranges.isEmpty() && !message.isEmpty();
return location.hasValidTarget() && !ranges.isEmpty() && !message.isEmpty();
}
bool operator==(const ExplainingStep &lhs, const ExplainingStep &rhs)
@@ -44,9 +44,9 @@ size_t qHash(const Diagnostic &diagnostic)
{
return qHash(diagnostic.name)
^ qHash(diagnostic.description)
^ qHash(diagnostic.location.filePath)
^ diagnostic.location.line
^ diagnostic.location.column;
^ qHash(diagnostic.location.targetFilePath)
^ diagnostic.location.targetLine
^ diagnostic.location.targetColumn;
}
bool operator==(const Diagnostic &lhs, const Diagnostic &rhs)

View File

@@ -3,7 +3,7 @@
#pragma once
#include <debugger/analyzer/diagnosticlocation.h>
#include <utils/link.h>
#include <QMetaType>
#include <QString>
@@ -22,8 +22,8 @@ public:
}
QString message;
Debugger::DiagnosticLocation location;
QVector<Debugger::DiagnosticLocation> ranges;
Utils::Link location;
Utils::Links ranges;
bool isFixIt = false;
};
@@ -40,7 +40,7 @@ public:
QString description;
QString category;
QString type;
Debugger::DiagnosticLocation location;
Utils::Link location;
QVector<ExplainingStep> explainingSteps;
bool hasFixits = false;
};

View File

@@ -25,6 +25,8 @@
static Q_LOGGING_CATEGORY(LOG, "qtc.clangtools.model", QtWarningMsg)
using namespace Utils;
namespace ClangTools {
namespace Internal {
@@ -101,7 +103,7 @@ void ClangToolsDiagnosticModel::addDiagnostics(const Diagnostics &diagnostics, b
}
// Create file path item if necessary
const Utils::FilePath &filePath = d.location.filePath;
const FilePath &filePath = d.location.targetFilePath;
FilePathItem *&filePathItem = m_filePathToItem[filePath];
if (!filePathItem) {
filePathItem = new FilePathItem(filePath);
@@ -166,7 +168,7 @@ void ClangToolsDiagnosticModel::clearAndSetupCache()
void ClangToolsDiagnosticModel::onFileChanged(const QString &path)
{
forItemsAtLevel<2>([&](DiagnosticItem *item){
if (item->diagnostic().location.filePath == Utils::FilePath::fromString(path))
if (item->diagnostic().location.targetFilePath == FilePath::fromString(path))
item->setFixItStatus(FixitStatus::Invalidated);
});
m_filesWatcher->removeFile(path);
@@ -193,9 +195,9 @@ std::unique_ptr<InlineSuppressedDiagnostics> ClangToolsDiagnosticModel::createIn
QTC_ASSERT(false, return {});
}
static QString lineColumnString(const Debugger::DiagnosticLocation &location)
static QString lineColumnString(const Link &location)
{
return QString("%1:%2").arg(QString::number(location.line), QString::number(location.column));
return QString("%1:%2").arg(location.targetLine).arg(location.targetColumn);
}
static QString createExplainingStepToolTipString(const ExplainingStep &step)
@@ -227,10 +229,10 @@ static QString createExplainingStepToolTipString(const ExplainingStep &step)
return html;
}
static QString createLocationString(const Debugger::DiagnosticLocation &location)
static QString createLocationString(const Link &location)
{
const QString filePath = location.filePath.toUserOutput();
const QString lineNumber = QString::number(location.line);
const QString filePath = location.targetFilePath.toUserOutput();
const QString lineNumber = QString::number(location.targetLine);
const QString fileAndLine = filePath + QLatin1Char(':') + lineNumber;
return QLatin1String("in ") + fileAndLine;
}
@@ -253,7 +255,7 @@ static QString createExplainingStepString(const ExplainingStep &explainingStep,
static QString fullText(const Diagnostic &diagnostic)
{
QString text = diagnostic.location.filePath.toUserOutput() + QLatin1Char(':');
QString text = diagnostic.location.targetFilePath.toUserOutput() + QLatin1Char(':');
text += lineColumnString(diagnostic.location) + QLatin1String(": ");
if (!diagnostic.category.isEmpty())
text += diagnostic.category + QLatin1String(": ");
@@ -441,7 +443,7 @@ ExplainingStepItem::ExplainingStepItem(const ExplainingStep &step, int index)
, m_index(index)
{}
static QString rangeString(const QVector<Debugger::DiagnosticLocation> &ranges)
static QString rangeString(const Links &ranges)
{
return QString("%1-%2").arg(lineColumnString(ranges[0]), lineColumnString(ranges[1]));
}
@@ -455,7 +457,7 @@ QVariant ExplainingStepItem::data(int column, int role) const
return QVariant::fromValue(m_step.location);
case Debugger::DetailedErrorView::FullTextRole: {
return QString("%1:%2: %3")
.arg(m_step.location.filePath.toUserOutput(),
.arg(m_step.location.targetFilePath.toUserOutput(),
lineColumnString(m_step.location),
m_step.message);
}
@@ -467,11 +469,11 @@ QVariant ExplainingStepItem::data(int column, int role) const
return parent()->data(column, role);
case Qt::DisplayRole: {
const Utils::FilePath mainFilePath
= static_cast<DiagnosticItem *>(parent())->diagnostic().location.filePath;
= static_cast<DiagnosticItem *>(parent())->diagnostic().location.targetFilePath;
const QString locationString
= m_step.location.filePath == mainFilePath
= m_step.location.targetFilePath == mainFilePath
? lineColumnString(m_step.location)
: QString("%1:%2").arg(m_step.location.filePath.fileName(),
: QString("%1:%2").arg(m_step.location.targetFilePath.fileName(),
lineColumnString(m_step.location));
if (m_step.isFixIt) {
@@ -654,7 +656,7 @@ bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
Utils::FilePath filePath = d.filePath;
if (d.filePath.toFileInfo().isRelative())
filePath = m_lastProjectDirectory.resolvePath(filePath);
if (filePath == diag.location.filePath) {
if (filePath == diag.location.targetFilePath) {
diagnosticItem->setTextMarkVisible(false);
return false;
}
@@ -676,19 +678,18 @@ bool DiagnosticFilterModel::lessThan(const QModelIndex &l, const QModelIndex &r)
if (sortColumn() == Debugger::DetailedErrorView::DiagnosticColumn && isComparingDiagnostics) {
bool result = false;
if (itemLeft->level() == 2) {
using Debugger::DiagnosticLocation;
const int role = Debugger::DetailedErrorView::LocationRole;
const auto leftLoc = sourceModel()->data(l, role).value<DiagnosticLocation>();
const auto leftLoc = sourceModel()->data(l, role).value<Link>();
const auto leftText
= sourceModel()->data(l, ClangToolsDiagnosticModel::TextRole).toString();
const auto rightLoc = sourceModel()->data(r, role).value<DiagnosticLocation>();
const auto rightLoc = sourceModel()->data(r, role).value<Link>();
const auto rightText
= sourceModel()->data(r, ClangToolsDiagnosticModel::TextRole).toString();
result = std::tie(leftLoc.line, leftLoc.column, leftText)
< std::tie(rightLoc.line, rightLoc.column, rightText);
result = std::tie(leftLoc.targetLine, leftLoc.targetColumn, leftText)
< std::tie(rightLoc.targetLine, rightLoc.targetColumn, rightText);
} else if (itemLeft->level() == 3) {
Utils::TreeItem *itemRight = model->itemForIndex(r);
QTC_ASSERT(itemRight, QSortFilterProxyModel::lessThan(l, r));

View File

@@ -17,8 +17,6 @@
#include <cppeditor/cppmodelmanager.h>
#include <cppeditor/cpprefactoringchanges.h>
#include <debugger/analyzer/diagnosticlocation.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
@@ -36,7 +34,7 @@
#include <set>
using namespace CppEditor;
using namespace Debugger;
using namespace Utils;
namespace ClangTools {
namespace Internal {
@@ -210,9 +208,8 @@ void DiagnosticView::suppressCurrentDiagnostic()
diags << diag;
continue;
}
Utils::FilePath filePath = diag.location.filePath;
const Utils::FilePath relativeFilePath
= filePath.relativeChildPath(project->projectDirectory());
FilePath filePath = diag.location.targetFilePath;
const FilePath relativeFilePath = filePath.relativeChildPath(project->projectDirectory());
if (!relativeFilePath.isEmpty())
filePath = relativeFilePath;
const SuppressedDiagnostic supDiag(filePath, diag.description,
@@ -242,7 +239,9 @@ void DiagnosticView::suppressCurrentDiagnosticInline()
if (!isApplicable)
continue;
diagnosticsPerFileAndLine[diag.location.filePath][diag.location.line] << diag.name;
diagnosticsPerFileAndLine[diag.location.targetFilePath][diag.location.targetLine]
<< diag.name;
diags << diag;
}
@@ -485,9 +484,11 @@ void DiagnosticView::mouseDoubleClickEvent(QMouseEvent *event)
void DiagnosticView::openEditorForCurrentIndex()
{
const QVariant v = model()->data(currentIndex(), Debugger::DetailedErrorView::LocationRole);
const auto loc = v.value<Debugger::DiagnosticLocation>();
if (loc.isValid())
Core::EditorManager::openEditorAt(Utils::Link(loc.filePath, loc.line, loc.column - 1));
Link loc = v.value<Link>();
if (loc.hasValidTarget()) {
--loc.targetColumn; // FIXME: Move this to the model side.
Core::EditorManager::openEditorAt(loc);
}
}
} // namespace Internal

View File

@@ -15,6 +15,8 @@
#include <yaml-cpp/yaml.h>
using namespace Utils;
namespace ClangTools {
namespace Internal {
@@ -127,7 +129,7 @@ public:
Utils::FilePath filePath() const { return m_filePath; }
Debugger::DiagnosticLocation toDiagnosticLocation() const
Link toLink() const
{
FileCache::Item &cacheItem = m_fileCache.item(m_filePath.toUserOutput());
const QByteArray fileContents = cacheItem.fileContents();
@@ -155,16 +157,15 @@ public:
if (data != fileContents.data())
lineStartOffset += cachedLineInfo.lineStartOffset;
cachedLineInfo = FileCache::LineInfo{info->line, lineStartOffset};
return Debugger::DiagnosticLocation{m_filePath, info->line, info->column};
return Link{m_filePath, info->line, info->column};
}
static QVector<Debugger::DiagnosticLocation> toRange(const YAML::Node &node,
FileCache &fileCache)
static Links toRange(const YAML::Node &node, FileCache &fileCache)
{
// The Replacements nodes use "Offset" instead of "FileOffset" as the key name.
auto startLoc = Location(node, fileCache, "Offset");
auto endLoc = Location(node, fileCache, "Offset", node["Length"].as<int>());
return {startLoc.toDiagnosticLocation(), endLoc.toDiagnosticLocation()};
return {startLoc.toLink(), endLoc.toLink()};
}
private:
@@ -207,7 +208,7 @@ void parseDiagnostics(QPromise<Utils::expected_str<Diagnostics>> &promise,
continue;
Diagnostic diag;
diag.location = loc.toDiagnosticLocation();
diag.location = loc.toLink();
diag.type = "warning";
diag.name = asString(diagNode["DiagnosticName"]);
diag.description = asString(node["Message"]) + " [" + diag.name + "]";
@@ -221,7 +222,7 @@ void parseDiagnostics(QPromise<Utils::expected_str<Diagnostics>> &promise,
step.ranges = Location::toRange(replacementNode, fileCache);
step.location = step.ranges[0];
if (step.location.isValid())
if (step.location.hasValidTarget())
diag.explainingSteps.append(step);
}
diag.hasFixits = !diag.explainingSteps.isEmpty();
@@ -239,7 +240,7 @@ void parseDiagnostics(QPromise<Utils::expected_str<Diagnostics>> &promise,
ExplainingStep step;
step.message = asString(noteNode["Message"]);
step.location = loc.toDiagnosticLocation();
step.location = loc.toLink();
diag.explainingSteps.append(step);
}

View File

@@ -210,7 +210,7 @@ ClangToolsProjectSettings::ClangToolsProjectSettingsPtr
}
SuppressedDiagnostic::SuppressedDiagnostic(const Diagnostic &diag)
: filePath(diag.location.filePath)
: filePath(diag.location.targetFilePath)
, description(diag.description)
, uniquifier(diag.explainingSteps.count())
{

View File

@@ -29,9 +29,9 @@ using namespace Utils;
namespace ClangTools {
namespace Internal {
static QString lineColumnString(const Debugger::DiagnosticLocation &location)
static QString lineColumnString(const Link &link)
{
return QString("%1:%2").arg(QString::number(location.line), QString::number(location.column));
return QString("%1:%2").arg(link.targetLine).arg(link.targetColumn);
}
static QString fixitStatus(FixitStatus status)
@@ -91,7 +91,7 @@ QString createDiagnosticToolTipString(
if (!steps.second.isEmpty())
steps.second += "<br>";
steps.second += QString("%1:%2: %3")
.arg(step.location.filePath.toUserOutput(),
.arg(step.location.targetFilePath.toUserOutput(),
lineColumnString(step.location),
step.message);
}
@@ -121,10 +121,11 @@ QString createDiagnosticToolTipString(
return html;
}
QString createFullLocationString(const Debugger::DiagnosticLocation &location)
QString createFullLocationString(const Link &location)
{
return location.filePath.toUserOutput() + QLatin1Char(':') + QString::number(location.line)
+ QLatin1Char(':') + QString::number(location.column);
return location.targetFilePath.toUserOutput()
+ QLatin1Char(':') + QString::number(location.targetLine)
+ QLatin1Char(':') + QString::number(location.targetColumn);
}
QString hintAboutBuildBeforeAnalysis()

View File

@@ -12,8 +12,11 @@
#include <optional>
namespace CppEditor { class ClangDiagnosticConfigsModel; }
namespace Debugger { class DiagnosticLocation; }
namespace Utils { class FilePath; }
namespace Utils {
class FilePath;
class Link;
} // Utils
namespace ClangTools {
namespace Internal {
@@ -39,7 +42,7 @@ QString createDiagnosticToolTipString(const Diagnostic &diagnostic,
CppEditor::ClangDiagnosticConfig builtinConfig();
QString createFullLocationString(const Debugger::DiagnosticLocation &location);
QString createFullLocationString(const Utils::Link &location);
QString hintAboutBuildBeforeAnalysis();
void showHintAboutBuildBeforeAnalysis();

View File

@@ -1282,7 +1282,7 @@ void disableChecks(const QList<Diagnostic> &diagnostics)
ClangToolsProjectSettings::ClangToolsProjectSettingsPtr projectSettings;
if (ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::projectForFile(
diagnostics.first().location.filePath)) {
diagnostics.first().location.targetFilePath)) {
projectSettings = ClangToolsProjectSettings::getSettings(project);
if (!projectSettings->useGlobalSettings())
activeConfigId = projectSettings->runSettings().diagnosticConfigId();

View File

@@ -26,14 +26,16 @@ static TextMarkCategory clangToolsCategory()
}
DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic, TextDocument *document)
: TextMark(document, diagnostic.location.line, clangToolsCategory())
: TextMark(document, diagnostic.location.targetLine, clangToolsCategory())
, m_diagnostic(diagnostic)
{
initialize();
}
DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic)
: TextMark(diagnostic.location.filePath, diagnostic.location.line, clangToolsCategory())
: TextMark(diagnostic.location.targetFilePath,
diagnostic.location.targetLine,
clangToolsCategory())
, m_diagnostic(diagnostic)
{
initialize();

View File

@@ -246,9 +246,9 @@ void DocumentClangToolRunner::run()
m_taskTreeRunner.start({parallel, tasks});
}
static void updateLocation(Debugger::DiagnosticLocation &location)
static void updateLocation(Link &location)
{
location.filePath = vfso().originalFilePath(location.filePath);
location.targetFilePath = vfso().originalFilePath(location.targetFilePath);
}
void DocumentClangToolRunner::onDone(const AnalyzeOutputData &output)
@@ -264,7 +264,7 @@ void DocumentClangToolRunner::onDone(const AnalyzeOutputData &output)
updateLocation(diag.location);
for (ExplainingStep &explainingStep : diag.explainingSteps) {
updateLocation(explainingStep.location);
for (Debugger::DiagnosticLocation &rangeLocation : explainingStep.ranges)
for (Link &rangeLocation : explainingStep.ranges)
updateLocation(rangeLocation);
}
}
@@ -293,8 +293,8 @@ void DocumentClangToolRunner::onDone(const AnalyzeOutputData &output)
marker.tooltip = diagnostic.description;
QTextCursor cursor(doc->document());
cursor.setPosition(Text::positionInText(doc->document(),
diagnostic.location.line,
diagnostic.location.column));
diagnostic.location.targetLine,
diagnostic.location.targetColumn));
cursor.movePosition(QTextCursor::EndOfLine);
marker.cursor = cursor;
marker.type = Constants::CLANG_TOOL_FIXIT_AVAILABLE_MARKER_ID;
@@ -333,7 +333,7 @@ bool DocumentClangToolRunner::isSuppressed(const Diagnostic &diagnostic) const
FilePath filePath = suppressed.filePath;
if (filePath.toFileInfo().isRelative())
filePath = m_lastProjectDirectory.resolvePath(filePath);
return filePath == diagnostic.location.filePath;
return filePath == diagnostic.location.targetFilePath;
};
return Utils::anyOf(m_suppressed, equalsSuppressed);
}

View File

@@ -11,6 +11,8 @@
#include <utils/qtcassert.h>
#include <utils/textutils.h>
using namespace Utils;
namespace ClangTools {
namespace Internal {
@@ -29,13 +31,13 @@ private:
};
using Range = TextEditor::RefactoringFile::Range;
using DiagnosticRange = QPair<Debugger::DiagnosticLocation, Debugger::DiagnosticLocation>;
using DiagnosticRange = QPair<Link, Link>;
static Range toRange(const QTextDocument *doc, DiagnosticRange locations)
{
Range range;
range.start = Utils::Text::positionInText(doc, locations.first.line, locations.first.column);
range.end = Utils::Text::positionInText(doc, locations.second.line, locations.second.column);
range.start = Text::positionInText(doc, locations.first.targetLine, locations.first.targetColumn);
range.end = Text::positionInText(doc, locations.second.targetLine, locations.second.targetColumn);
return range;
}
@@ -47,9 +49,10 @@ void ClangToolQuickFixOperation::perform()
for (const ExplainingStep &step : m_diagnostic.explainingSteps) {
if (!step.isFixIt)
continue;
TextEditor::RefactoringFilePtr &refactoringFile = refactoringFiles[step.location.filePath];
TextEditor::RefactoringFilePtr &refactoringFile =
refactoringFiles[step.location.targetFilePath];
if (refactoringFile.isNull())
refactoringFile = changes.file(step.location.filePath);
refactoringFile = changes.file(step.location.targetFilePath);
Utils::ChangeSet changeSet = refactoringFile->changeSet();
Range range = toRange(refactoringFile->document(), {step.ranges.first(), step.ranges.last()});
changeSet.replace(range, step.message);

View File

@@ -6,6 +6,7 @@
#include "clangtoolslogfilereader.h"
#include <cppeditor/cpptoolstestcase.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
@@ -13,7 +14,6 @@
#include <QtTest>
using namespace CppEditor::Tests;
using namespace Debugger;
using namespace Utils;
namespace ClangTools::Internal {

View File

@@ -5,13 +5,12 @@
#include "cppchecktr.h"
#include <debugger/analyzer/diagnosticlocation.h>
#include <utils/algorithm.h>
#include <utils/fsengine/fileiconprovider.h>
#include <utils/link.h>
#include <utils/utilsicons.h>
using namespace Debugger;
using namespace Utils;
namespace Cppcheck::Internal {
@@ -57,12 +56,8 @@ QVariant DiagnosticItem::data(int column, int role) const
{
if (column == DiagnosticsModel::DiagnosticColumn) {
switch (role) {
case DetailedErrorView::LocationRole: {
const auto location = DiagnosticLocation(m_diagnostic.fileName,
m_diagnostic.lineNumber,
0);
return QVariant::fromValue(location);
}
case Debugger::DetailedErrorView::LocationRole:
return QVariant::fromValue(Link(m_diagnostic.fileName, m_diagnostic.lineNumber, 0));
case Qt::DisplayRole:
return QString("%1: %2").arg(m_diagnostic.lineNumber).arg(m_diagnostic.message);
case Qt::ToolTipRole:

View File

@@ -7,9 +7,9 @@
#include <coreplugin/editormanager/editormanager.h>
#include <debugger/analyzer/diagnosticlocation.h>
#include <utils/link.h>
using namespace Debugger;
using namespace Utils;
namespace Cppcheck::Internal {
@@ -80,9 +80,11 @@ DiagnosticView::~DiagnosticView() = default;
void DiagnosticView::openEditorForCurrentIndex()
{
const QVariant v = model()->data(currentIndex(), Debugger::DetailedErrorView::LocationRole);
const auto loc = v.value<Debugger::DiagnosticLocation>();
if (loc.isValid())
Core::EditorManager::openEditorAt(Utils::Link(loc.filePath, loc.line, loc.column - 1));
Link loc = v.value<Link>();
if (loc.hasValidTarget()) {
--loc.targetColumn; // FIXME: Move adjustment to model side.
Core::EditorManager::openEditorAt(loc);
}
}
void DiagnosticView::mouseDoubleClickEvent(QMouseEvent *event)

View File

@@ -10,7 +10,6 @@ add_qtc_plugin(Debugger
analyzer/analyzericons.h
analyzer/analyzerutils.cpp analyzer/analyzerutils.h
analyzer/detailederrorview.cpp analyzer/detailederrorview.h
analyzer/diagnosticlocation.cpp analyzer/diagnosticlocation.h
breakhandler.cpp breakhandler.h
breakpoint.cpp breakpoint.h
cdb/cdbengine.cpp cdb/cdbengine.h

View File

@@ -4,10 +4,10 @@
#include "detailederrorview.h"
#include "../debuggertr.h"
#include "diagnosticlocation.h"
#include <coreplugin/editormanager/editormanager.h>
#include <utils/link.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/utilsicons.h>
@@ -21,6 +21,8 @@
#include <QMenu>
#include <QPainter>
using namespace Utils;
namespace Debugger {
DetailedErrorView::DetailedErrorView(QWidget *parent) :
@@ -42,10 +44,11 @@ DetailedErrorView::DetailedErrorView(QWidget *parent) :
});
connect(this, &QAbstractItemView::clicked, [](const QModelIndex &index) {
if (index.column() == LocationColumn) {
const auto loc = index.model()->data(index, DetailedErrorView::LocationRole)
.value<DiagnosticLocation>();
if (loc.isValid())
Core::EditorManager::openEditorAt(Utils::Link(loc.filePath, loc.line, loc.column - 1));
Link loc = index.model()->data(index, DetailedErrorView::LocationRole).value<Link>();
if (loc.hasValidTarget()) {
--loc.targetColumn; // FIXME: Move adjustment to model side.
Core::EditorManager::openEditorAt(loc);
}
}
});
@@ -95,19 +98,20 @@ void DetailedErrorView::selectIndex(const QModelIndex &index)
| QItemSelectionModel::Rows);
}
QVariant DetailedErrorView::locationData(int role, const DiagnosticLocation &location)
QVariant DetailedErrorView::locationData(int role, const Link &location)
{
switch (role) {
case Debugger::DetailedErrorView::LocationRole:
return QVariant::fromValue(location);
case Qt::DisplayRole:
return location.isValid() ? QString::fromLatin1("%1:%2:%3")
.arg(location.filePath.fileName())
.arg(location.line)
.arg(location.column)
return location.hasValidTarget() ? QString::fromLatin1("%1:%2:%3")
.arg(location.targetFilePath.fileName())
.arg(location.targetLine)
.arg(location.targetColumn)
: QString();
case Qt::ToolTipRole:
return location.filePath.isEmpty() ? QVariant() : QVariant(location.filePath.toUserOutput());
return location.targetFilePath.isEmpty()
? QVariant() : QVariant(location.targetFilePath.toUserOutput());
case Qt::FontRole: {
QFont font = QApplication::font();
font.setUnderline(true);

View File

@@ -8,9 +8,9 @@
#include <QTreeView>
#include <QStyledItemDelegate>
namespace Debugger {
namespace Utils { class Link; }
class DiagnosticLocation;
namespace Debugger {
class DEBUGGER_EXPORT DetailedErrorView : public QTreeView
{
@@ -33,7 +33,7 @@ public:
LocationColumn,
};
static QVariant locationData(int role, const DiagnosticLocation &location);
static QVariant locationData(int role, const Utils::Link &location);
private:
void contextMenuEvent(QContextMenuEvent *e) override;

View File

@@ -1,42 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "diagnosticlocation.h"
namespace Debugger {
DiagnosticLocation::DiagnosticLocation() = default;
DiagnosticLocation::DiagnosticLocation(const Utils::FilePath &filePath, int line, int column)
: filePath(filePath), line(line), column(column)
{
}
bool DiagnosticLocation::isValid() const
{
return !filePath.isEmpty();
}
bool operator==(const DiagnosticLocation &first, const DiagnosticLocation &second)
{
return first.filePath == second.filePath
&& first.line == second.line
&& first.column == second.column;
}
bool operator<(const DiagnosticLocation &first, const DiagnosticLocation &second)
{
return std::tie(first.filePath, first.line, first.column)
< std::tie(second.filePath, second.line, second.column);
}
QDebug operator<<(QDebug dbg, const DiagnosticLocation &location)
{
dbg.nospace() << "Location(" << location.filePath << ", "
<< location.line << ", "
<< location.column << ')';
return dbg.space();
}
} // namespace Debugger

View File

@@ -1,37 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <debugger/debugger_global.h>
#include <utils/filepath.h>
#include <QDebug>
#include <QMetaType>
#include <QString>
namespace Debugger {
class DEBUGGER_EXPORT DiagnosticLocation
{
public:
DiagnosticLocation();
DiagnosticLocation(const Utils::FilePath &filePath, int line, int column);
bool isValid() const;
DEBUGGER_EXPORT friend bool operator==(const DiagnosticLocation &first, const DiagnosticLocation &second);
DEBUGGER_EXPORT friend bool operator<(const DiagnosticLocation &first, const DiagnosticLocation &second);
DEBUGGER_EXPORT friend QDebug operator<<(QDebug dbg, const DiagnosticLocation &location);
Utils::FilePath filePath;
// Both values start at 1.
int line = 0;
int column = 0;
};
} // namespace Debugger
Q_DECLARE_METATYPE(Debugger::DiagnosticLocation)

View File

@@ -235,8 +235,6 @@ QtcPlugin {
"analyzerutils.h",
"detailederrorview.cpp",
"detailederrorview.h",
"diagnosticlocation.cpp",
"diagnosticlocation.h",
]
}

View File

@@ -7,13 +7,14 @@
#include "stack.h"
#include "../valgrindtr.h"
#include <debugger/analyzer/diagnosticlocation.h>
#include <utils/link.h>
#include <utils/qtcassert.h>
#include <QDir>
#include <QList>
using namespace Utils;
namespace Valgrind::XmlProtocol {
class ErrorItem : public Utils::TreeItem
@@ -150,9 +151,7 @@ ErrorItem::ErrorItem(const ErrorListModel *model, const Error &error)
static QVariant locationData(int role, const Frame &frame)
{
const Debugger::DiagnosticLocation location(Utils::FilePath::fromString(frame.filePath()),
frame.line(),
0);
const Link location(FilePath::fromString(frame.filePath()), frame.line(), 0);
return Debugger::DetailedErrorView::locationData(role, location);
}