diff options
author | Christian Kandeler <[email protected]> | 2019-02-25 17:45:39 +0100 |
---|---|---|
committer | Christian Kandeler <[email protected]> | 2019-03-04 09:52:13 +0000 |
commit | d0db212575909ca18244bdfc99b952dffcd0e902 (patch) | |
tree | f0fbfb40bc34b20a5f4539b6936c8854e78433ee /src/plugins | |
parent | b0e125ac11b1ad80717366a1270412d6b6b1be41 (diff) |
Resolve ambiguous results of searches for relative file paths
Qt Creator extracts file names from the output of external processes in
various places, for instance from compilers during the build. It often
happens that such file names are not absolute, so they cannot be
directly opened in an editor when the user clicks on their
representation in some widget. That's why they are processed by the
FileInProjectFinder facility first.
This patch enhances the FileInProjectFinder to be able to return more
than one candidate for a relative file path, and allows the user to
choose between these candidates where possible. This way, we won't open
a random file anymore when a project contains more than one file with
the same name.
Fixes: QTCREATORBUG-13623
Change-Id: Id19c9eace3e6b3dbde89f6528e6d02b55872d747
Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/debugger/console/consoleview.cpp | 3 | ||||
-rw-r--r-- | src/plugins/debugger/debuggerengine.cpp | 2 | ||||
-rw-r--r-- | src/plugins/perfprofiler/perfprofilertool.cpp | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/fileinsessionfinder.cpp | 9 | ||||
-rw-r--r-- | src/plugins/projectexplorer/fileinsessionfinder.h | 4 | ||||
-rw-r--r-- | src/plugins/projectexplorer/task.cpp | 9 | ||||
-rw-r--r-- | src/plugins/projectexplorer/task.h | 1 | ||||
-rw-r--r-- | src/plugins/projectexplorer/taskmodel.cpp | 8 | ||||
-rw-r--r-- | src/plugins/projectexplorer/taskwindow.cpp | 10 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qtsupport/qtoutputformatter.cpp | 11 |
11 files changed, 38 insertions, 23 deletions
diff --git a/src/plugins/debugger/console/consoleview.cpp b/src/plugins/debugger/console/consoleview.cpp index 9969bfb0f5c..c6387cc9e05 100644 --- a/src/plugins/debugger/console/consoleview.cpp +++ b/src/plugins/debugger/console/consoleview.cpp @@ -218,7 +218,8 @@ void ConsoleView::onRowActivated(const QModelIndex &index) if (!index.isValid()) return; - const QFileInfo fi(m_finder.findFile(model()->data(index, ConsoleItem::FileRole).toString())); + const QFileInfo fi = m_finder.findFile(model()->data(index, ConsoleItem::FileRole).toString()) + .first().toFileInfo(); if (fi.exists() && fi.isFile() && fi.isReadable()) { Core::EditorManager::openEditorAt(fi.canonicalFilePath(), model()->data(index, ConsoleItem::LineRole).toInt()); diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index 7399c99b7f9..3c9d5ce37f7 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -1828,7 +1828,7 @@ QString DebuggerEngine::toFileInProject(const QUrl &fileUrl) d->m_fileFinder.setAdditionalSearchDirectories(rp.additionalSearchDirectories); d->m_fileFinder.setSysroot(rp.sysRoot); - return d->m_fileFinder.findFile(fileUrl); + return d->m_fileFinder.findFile(fileUrl).first().toString(); } QString DebuggerEngine::expand(const QString &string) const diff --git a/src/plugins/perfprofiler/perfprofilertool.cpp b/src/plugins/perfprofiler/perfprofilertool.cpp index 57de5ce14ac..662e9ef5484 100644 --- a/src/plugins/perfprofiler/perfprofilertool.cpp +++ b/src/plugins/perfprofiler/perfprofilertool.cpp @@ -540,7 +540,7 @@ void PerfProfilerTool::gotoSourceLocation(QString filePath, int lineNumber, int QFileInfo fi(filePath); if (!fi.isAbsolute() || !fi.exists() || !fi.isReadable()) { - fi.setFile(m_fileFinder.findFile(filePath)); + fi.setFile(m_fileFinder.findFile(filePath).first().toString()); if (!fi.exists() || !fi.isReadable()) return; } diff --git a/src/plugins/projectexplorer/fileinsessionfinder.cpp b/src/plugins/projectexplorer/fileinsessionfinder.cpp index 15164f9fcc1..667cbdd22e5 100644 --- a/src/plugins/projectexplorer/fileinsessionfinder.cpp +++ b/src/plugins/projectexplorer/fileinsessionfinder.cpp @@ -29,7 +29,6 @@ #include "session.h" #include <utils/fileinprojectfinder.h> -#include <utils/fileutils.h> #include <QUrl> @@ -43,7 +42,7 @@ class FileInSessionFinder : public QObject public: FileInSessionFinder(); - FileName doFindFile(const FileName &filePath); + FileNameList doFindFile(const FileName &filePath); void invalidateFinder() { m_finderIsUpToDate = false; } private: @@ -65,7 +64,7 @@ FileInSessionFinder::FileInSessionFinder() }); } -FileName FileInSessionFinder::doFindFile(const FileName &filePath) +FileNameList FileInSessionFinder::doFindFile(const FileName &filePath) { if (!m_finderIsUpToDate) { m_finder.setProjectDirectory(SessionManager::startupProject() @@ -77,10 +76,10 @@ FileName FileInSessionFinder::doFindFile(const FileName &filePath) m_finder.setProjectFiles(allFiles); m_finderIsUpToDate = true; } - return FileName::fromString(m_finder.findFile(QUrl::fromLocalFile(filePath.toString()))); + return m_finder.findFile(QUrl::fromLocalFile(filePath.toString())); } -FileName findFileInSession(const FileName &filePath) +FileNameList findFileInSession(const FileName &filePath) { static FileInSessionFinder finder; return finder.doFindFile(filePath); diff --git a/src/plugins/projectexplorer/fileinsessionfinder.h b/src/plugins/projectexplorer/fileinsessionfinder.h index 8c31a876092..4f08e67d93d 100644 --- a/src/plugins/projectexplorer/fileinsessionfinder.h +++ b/src/plugins/projectexplorer/fileinsessionfinder.h @@ -25,12 +25,12 @@ #pragma once -namespace Utils { class FileName; } +#include <utils/fileutils.h> namespace ProjectExplorer { namespace Internal { -Utils::FileName findFileInSession(const Utils::FileName &filePath); +Utils::FileNameList findFileInSession(const Utils::FileName &filePath); } // namespace Internal } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/task.cpp b/src/plugins/projectexplorer/task.cpp index 83409fadd5a..4d334a78e8a 100644 --- a/src/plugins/projectexplorer/task.cpp +++ b/src/plugins/projectexplorer/task.cpp @@ -25,6 +25,7 @@ #include "task.h" +#include "fileinsessionfinder.h" #include "projectexplorerconstants.h" #include <app/app_version.h> @@ -34,6 +35,7 @@ #include <utils/utilsicons.h> #include <utils/qtcassert.h> +#include <QFileInfo> #include <QTextStream> namespace ProjectExplorer @@ -67,6 +69,13 @@ Task::Task(TaskType type_, const QString &description_, icon(icon.isNull() ? taskTypeIcon(type_) : icon) { ++s_nextId; + if (!file.isEmpty() && !file.toFileInfo().isAbsolute()) { + Utils::FileNameList possiblePaths = Internal::findFileInSession(file); + if (possiblePaths.length() == 1) + file = possiblePaths.first(); + else + fileCandidates = possiblePaths; + } } Task Task::compilerMissingTask() diff --git a/src/plugins/projectexplorer/task.h b/src/plugins/projectexplorer/task.h index f3e1b76c88b..b8b80784aa4 100644 --- a/src/plugins/projectexplorer/task.h +++ b/src/plugins/projectexplorer/task.h @@ -76,6 +76,7 @@ public: Options options = AddTextMark | FlashWorthy; QString description; Utils::FileName file; + Utils::FileNameList fileCandidates; int line = -1; int movedLine = -1; // contains a line number if the line was moved in the editor Core::Id category; diff --git a/src/plugins/projectexplorer/taskmodel.cpp b/src/plugins/projectexplorer/taskmodel.cpp index 1780bb4870a..1cae2b60a68 100644 --- a/src/plugins/projectexplorer/taskmodel.cpp +++ b/src/plugins/projectexplorer/taskmodel.cpp @@ -104,14 +104,8 @@ bool sortById(const Task &task, unsigned int id) return task.taskId < id; } -void TaskModel::addTask(const Task &t) +void TaskModel::addTask(const Task &task) { - Task task = t; - if (!task.file.isEmpty() && !task.file.toFileInfo().isAbsolute()) { - const Utils::FileName fullFilePath = findFileInSession(task.file); - if (!fullFilePath.isEmpty()) - task.file = fullFilePath; - } Q_ASSERT(m_categories.keys().contains(task.category)); CategoryData &data = m_categories[task.category]; CategoryData &global = m_categories[Core::Id()]; diff --git a/src/plugins/projectexplorer/taskwindow.cpp b/src/plugins/projectexplorer/taskwindow.cpp index 38c21fbdddc..95f3c081298 100644 --- a/src/plugins/projectexplorer/taskwindow.cpp +++ b/src/plugins/projectexplorer/taskwindow.cpp @@ -38,6 +38,7 @@ #include <coreplugin/icontext.h> #include <utils/algorithm.h> +#include <utils/fileinprojectfinder.h> #include <utils/qtcassert.h> #include <utils/itemviews.h> #include <utils/utilsicons.h> @@ -498,6 +499,15 @@ void TaskWindow::triggerDefaultHandler(const QModelIndex &index) if (task.isNull()) return; + if (!task.file.isEmpty() && !task.file.toFileInfo().isAbsolute() + && !task.fileCandidates.empty()) { + const Utils::FileName userChoice = Utils::chooseFileFromList(task.fileCandidates); + if (!userChoice.isEmpty()) { + task.file = userChoice; + updatedTaskFileName(task.taskId, task.file.toString()); + } + } + if (d->m_defaultHandler->canHandle(task)) { d->m_defaultHandler->handle(task); } else { diff --git a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp index e96a92623f8..cc97f7eb6a3 100644 --- a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp @@ -112,7 +112,7 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int typeId, QString QmlProfilerDetailsRewriter::getLocalFile(const QString &remoteFile) { - const QString localFile = m_projectFinder.findFile(remoteFile); + const QString localFile = m_projectFinder.findFile(remoteFile).first().toString(); const QFileInfo fileInfo(localFile); if (!fileInfo.exists() || !fileInfo.isReadable()) return QString(); diff --git a/src/plugins/qtsupport/qtoutputformatter.cpp b/src/plugins/qtsupport/qtoutputformatter.cpp index cb98654858c..f554c6e8946 100644 --- a/src/plugins/qtsupport/qtoutputformatter.cpp +++ b/src/plugins/qtsupport/qtoutputformatter.cpp @@ -211,13 +211,14 @@ void QtOutputFormatter::handleLink(const QString &href) ":(\\d+)$"); // column const QRegularExpressionMatch qmlLineColumnMatch = qmlLineColumnLink.match(href); + const auto getFileToOpen = [this](const QUrl &fileUrl) { + return chooseFileFromList(d->projectFinder.findFile(fileUrl)).toString(); + }; if (qmlLineColumnMatch.hasMatch()) { const QUrl fileUrl = QUrl(qmlLineColumnMatch.captured(1)); const int line = qmlLineColumnMatch.captured(2).toInt(); const int column = qmlLineColumnMatch.captured(3).toInt(); - - openEditor(d->projectFinder.findFile(fileUrl), line, column - 1); - + openEditor(getFileToOpen(fileUrl), line, column - 1); return; } @@ -228,7 +229,7 @@ void QtOutputFormatter::handleLink(const QString &href) if (qmlLineMatch.hasMatch()) { const QUrl fileUrl = QUrl(qmlLineMatch.captured(1)); const int line = qmlLineMatch.captured(2).toInt(); - openEditor(d->projectFinder.findFile(fileUrl), line); + openEditor(getFileToOpen(fileUrl), line); return; } @@ -257,7 +258,7 @@ void QtOutputFormatter::handleLink(const QString &href) } if (!fileName.isEmpty()) { - fileName = d->projectFinder.findFile(QUrl::fromLocalFile(fileName)); + fileName = getFileToOpen(QUrl::fromLocalFile(fileName)); openEditor(fileName, line); return; } |