diff --git a/src/libs/utils/link.cpp b/src/libs/utils/link.cpp index 1a4b4f9f9af..8c3be84eef0 100644 --- a/src/libs/utils/link.cpp +++ b/src/libs/utils/link.cpp @@ -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 diff --git a/src/libs/utils/link.h b/src/libs/utils/link.h index 57fb4c896fd..f00a0b5b397 100644 --- a/src/libs/utils/link.h +++ b/src/libs/utils/link.h @@ -7,6 +7,7 @@ #include "filepath.h" +#include #include #include @@ -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 diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp index 0cee8dd7e94..8536f5f8ea0 100644 --- a/src/plugins/clangtools/clangtool.cpp +++ b/src/plugins/clangtools/clangtool.cpp @@ -228,7 +228,7 @@ public: ApplyFixIts(const QVector &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 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)); }); } diff --git a/src/plugins/clangtools/clangtoolsdiagnostic.cpp b/src/plugins/clangtools/clangtoolsdiagnostic.cpp index d889adf4b33..a6ed6f3cf59 100644 --- a/src/plugins/clangtools/clangtoolsdiagnostic.cpp +++ b/src/plugins/clangtools/clangtoolsdiagnostic.cpp @@ -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) diff --git a/src/plugins/clangtools/clangtoolsdiagnostic.h b/src/plugins/clangtools/clangtoolsdiagnostic.h index 70f1197f32a..267f44c9217 100644 --- a/src/plugins/clangtools/clangtoolsdiagnostic.h +++ b/src/plugins/clangtools/clangtoolsdiagnostic.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include @@ -22,8 +22,8 @@ public: } QString message; - Debugger::DiagnosticLocation location; - QVector 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 explainingSteps; bool hasFixits = false; }; diff --git a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp index dc4cc690cc4..9e175614adb 100644 --- a/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp +++ b/src/plugins/clangtools/clangtoolsdiagnosticmodel.cpp @@ -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 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 &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(parent())->diagnostic().location.filePath; + = static_cast(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(); + const auto leftLoc = sourceModel()->data(l, role).value(); const auto leftText = sourceModel()->data(l, ClangToolsDiagnosticModel::TextRole).toString(); - const auto rightLoc = sourceModel()->data(r, role).value(); + const auto rightLoc = sourceModel()->data(r, role).value(); 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)); diff --git a/src/plugins/clangtools/clangtoolsdiagnosticview.cpp b/src/plugins/clangtools/clangtoolsdiagnosticview.cpp index 47d891ae3bc..65c2cdde649 100644 --- a/src/plugins/clangtools/clangtoolsdiagnosticview.cpp +++ b/src/plugins/clangtools/clangtoolsdiagnosticview.cpp @@ -17,8 +17,6 @@ #include #include -#include - #include #include #include @@ -36,7 +34,7 @@ #include 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(); - if (loc.isValid()) - Core::EditorManager::openEditorAt(Utils::Link(loc.filePath, loc.line, loc.column - 1)); + Link loc = v.value(); + if (loc.hasValidTarget()) { + --loc.targetColumn; // FIXME: Move this to the model side. + Core::EditorManager::openEditorAt(loc); + } } } // namespace Internal diff --git a/src/plugins/clangtools/clangtoolslogfilereader.cpp b/src/plugins/clangtools/clangtoolslogfilereader.cpp index 2f6473bb05d..13831a5b51d 100644 --- a/src/plugins/clangtools/clangtoolslogfilereader.cpp +++ b/src/plugins/clangtools/clangtoolslogfilereader.cpp @@ -15,6 +15,8 @@ #include +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 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()); - return {startLoc.toDiagnosticLocation(), endLoc.toDiagnosticLocation()}; + return {startLoc.toLink(), endLoc.toLink()}; } private: @@ -207,7 +208,7 @@ void parseDiagnostics(QPromise> &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> &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> &promise, ExplainingStep step; step.message = asString(noteNode["Message"]); - step.location = loc.toDiagnosticLocation(); + step.location = loc.toLink(); diag.explainingSteps.append(step); } diff --git a/src/plugins/clangtools/clangtoolsprojectsettings.cpp b/src/plugins/clangtools/clangtoolsprojectsettings.cpp index 3b5d7da0375..c23ea26e25c 100644 --- a/src/plugins/clangtools/clangtoolsprojectsettings.cpp +++ b/src/plugins/clangtools/clangtoolsprojectsettings.cpp @@ -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()) { diff --git a/src/plugins/clangtools/clangtoolsutils.cpp b/src/plugins/clangtools/clangtoolsutils.cpp index 5f144c97e92..bb636fadccd 100644 --- a/src/plugins/clangtools/clangtoolsutils.cpp +++ b/src/plugins/clangtools/clangtoolsutils.cpp @@ -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 += "
"; 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() diff --git a/src/plugins/clangtools/clangtoolsutils.h b/src/plugins/clangtools/clangtoolsutils.h index 36bcc75ff29..8758365f315 100644 --- a/src/plugins/clangtools/clangtoolsutils.h +++ b/src/plugins/clangtools/clangtoolsutils.h @@ -12,8 +12,11 @@ #include 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(); diff --git a/src/plugins/clangtools/diagnosticconfigswidget.cpp b/src/plugins/clangtools/diagnosticconfigswidget.cpp index 6ecc765efc8..dbea6156e17 100644 --- a/src/plugins/clangtools/diagnosticconfigswidget.cpp +++ b/src/plugins/clangtools/diagnosticconfigswidget.cpp @@ -1282,7 +1282,7 @@ void disableChecks(const QList &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(); diff --git a/src/plugins/clangtools/diagnosticmark.cpp b/src/plugins/clangtools/diagnosticmark.cpp index 9eba17965f4..9503038c4b3 100644 --- a/src/plugins/clangtools/diagnosticmark.cpp +++ b/src/plugins/clangtools/diagnosticmark.cpp @@ -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(); diff --git a/src/plugins/clangtools/documentclangtoolrunner.cpp b/src/plugins/clangtools/documentclangtoolrunner.cpp index 7c7e63b8c11..1f4ff124157 100644 --- a/src/plugins/clangtools/documentclangtoolrunner.cpp +++ b/src/plugins/clangtools/documentclangtoolrunner.cpp @@ -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); } diff --git a/src/plugins/clangtools/documentquickfixfactory.cpp b/src/plugins/clangtools/documentquickfixfactory.cpp index 1344325882c..be20950527e 100644 --- a/src/plugins/clangtools/documentquickfixfactory.cpp +++ b/src/plugins/clangtools/documentquickfixfactory.cpp @@ -11,6 +11,8 @@ #include #include +using namespace Utils; + namespace ClangTools { namespace Internal { @@ -29,13 +31,13 @@ private: }; using Range = TextEditor::RefactoringFile::Range; -using DiagnosticRange = QPair; +using DiagnosticRange = QPair; 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); diff --git a/src/plugins/clangtools/readexporteddiagnosticstest.cpp b/src/plugins/clangtools/readexporteddiagnosticstest.cpp index e6242713d3a..36e41b922e9 100644 --- a/src/plugins/clangtools/readexporteddiagnosticstest.cpp +++ b/src/plugins/clangtools/readexporteddiagnosticstest.cpp @@ -6,6 +6,7 @@ #include "clangtoolslogfilereader.h" #include + #include #include #include @@ -13,7 +14,6 @@ #include using namespace CppEditor::Tests; -using namespace Debugger; using namespace Utils; namespace ClangTools::Internal { diff --git a/src/plugins/cppcheck/cppcheckdiagnosticsmodel.cpp b/src/plugins/cppcheck/cppcheckdiagnosticsmodel.cpp index 39452f172f3..e9bed2af5bb 100644 --- a/src/plugins/cppcheck/cppcheckdiagnosticsmodel.cpp +++ b/src/plugins/cppcheck/cppcheckdiagnosticsmodel.cpp @@ -5,13 +5,12 @@ #include "cppchecktr.h" -#include - #include #include +#include #include -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: diff --git a/src/plugins/cppcheck/cppcheckdiagnosticview.cpp b/src/plugins/cppcheck/cppcheckdiagnosticview.cpp index 2976fffbb10..be2ed950538 100644 --- a/src/plugins/cppcheck/cppcheckdiagnosticview.cpp +++ b/src/plugins/cppcheck/cppcheckdiagnosticview.cpp @@ -7,9 +7,9 @@ #include -#include +#include -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(); - if (loc.isValid()) - Core::EditorManager::openEditorAt(Utils::Link(loc.filePath, loc.line, loc.column - 1)); + Link loc = v.value(); + if (loc.hasValidTarget()) { + --loc.targetColumn; // FIXME: Move adjustment to model side. + Core::EditorManager::openEditorAt(loc); + } } void DiagnosticView::mouseDoubleClickEvent(QMouseEvent *event) diff --git a/src/plugins/debugger/CMakeLists.txt b/src/plugins/debugger/CMakeLists.txt index 53395a32efa..7775304e26e 100644 --- a/src/plugins/debugger/CMakeLists.txt +++ b/src/plugins/debugger/CMakeLists.txt @@ -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 diff --git a/src/plugins/debugger/analyzer/detailederrorview.cpp b/src/plugins/debugger/analyzer/detailederrorview.cpp index 06941ac1148..d232632946c 100644 --- a/src/plugins/debugger/analyzer/detailederrorview.cpp +++ b/src/plugins/debugger/analyzer/detailederrorview.cpp @@ -4,10 +4,10 @@ #include "detailederrorview.h" #include "../debuggertr.h" -#include "diagnosticlocation.h" #include +#include #include #include #include @@ -21,6 +21,8 @@ #include #include +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(); - if (loc.isValid()) - Core::EditorManager::openEditorAt(Utils::Link(loc.filePath, loc.line, loc.column - 1)); + Link loc = index.model()->data(index, DetailedErrorView::LocationRole).value(); + 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); diff --git a/src/plugins/debugger/analyzer/detailederrorview.h b/src/plugins/debugger/analyzer/detailederrorview.h index e2e854a1858..d5df906a235 100644 --- a/src/plugins/debugger/analyzer/detailederrorview.h +++ b/src/plugins/debugger/analyzer/detailederrorview.h @@ -8,9 +8,9 @@ #include #include -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; diff --git a/src/plugins/debugger/analyzer/diagnosticlocation.cpp b/src/plugins/debugger/analyzer/diagnosticlocation.cpp deleted file mode 100644 index 75d84f32e3b..00000000000 --- a/src/plugins/debugger/analyzer/diagnosticlocation.cpp +++ /dev/null @@ -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 - diff --git a/src/plugins/debugger/analyzer/diagnosticlocation.h b/src/plugins/debugger/analyzer/diagnosticlocation.h deleted file mode 100644 index f4d4a4cc348..00000000000 --- a/src/plugins/debugger/analyzer/diagnosticlocation.h +++ /dev/null @@ -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 - -#include - -#include -#include -#include - -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) diff --git a/src/plugins/debugger/debugger.qbs b/src/plugins/debugger/debugger.qbs index c45adb3e320..ecf05cac439 100644 --- a/src/plugins/debugger/debugger.qbs +++ b/src/plugins/debugger/debugger.qbs @@ -235,8 +235,6 @@ QtcPlugin { "analyzerutils.h", "detailederrorview.cpp", "detailederrorview.h", - "diagnosticlocation.cpp", - "diagnosticlocation.h", ] } diff --git a/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp b/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp index 96bf9023eec..57acb8296bc 100644 --- a/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp +++ b/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp @@ -7,13 +7,14 @@ #include "stack.h" #include "../valgrindtr.h" -#include - +#include #include #include #include +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); }