Axivion: Improve path mapping

If the linked project is not the top level project our
path mappings did not work.
Try to get the correct file path by using QC internal
find functionality.
This helps for opening files by activating issues inside
the issues table or when clicking links of the issue
details.
Unfortunately this does not help for the inline
annotations or respective marks.

Change-Id: Ie34e1b20ff8b1b2b37e9f04c1d41bc2a4c33f260
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2024-03-22 11:26:04 +01:00
parent 34eeda4b05
commit 99aed851ef
3 changed files with 24 additions and 4 deletions

View File

@@ -235,7 +235,7 @@ public:
}).link;
Project *project = ProjectManager::startupProject();
FilePath baseDir = project ? project->projectDirectory() : FilePath{};
link.targetFilePath = baseDir.resolvePath(link.targetFilePath);
link.targetFilePath = findFileForIssuePath(link.targetFilePath);
if (link.targetFilePath.exists())
EditorManager::openEditorAt(link);
}

View File

@@ -36,6 +36,7 @@
#include <utils/async.h>
#include <utils/checkablemessagebox.h>
#include <utils/environment.h>
#include <utils/fileinprojectfinder.h>
#include <utils/networkaccessmanager.h>
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>
@@ -236,6 +237,7 @@ public:
TaskTreeRunner m_taskTreeRunner;
std::unordered_map<IDocument *, std::unique_ptr<TaskTree>> m_docMarksTrees;
TaskTreeRunner m_issueInfoRunner;
FileInProjectFinder m_fileFinder; // FIXME maybe obsolete when path mapping is implemented
};
static AxivionPluginPrivate *dd = nullptr;
@@ -337,10 +339,17 @@ void AxivionPluginPrivate::onStartupProjectChanged(Project *project)
m_currentProjectInfo = {};
updateDashboard();
if (!m_project)
if (!m_project) {
m_fileFinder.setProjectDirectory({});
m_fileFinder.setProjectFiles({});
return;
}
connect(m_project, &Project::fileListChanged, this, &AxivionPluginPrivate::handleOpenedDocs);
m_fileFinder.setProjectDirectory(m_project->projectDirectory());
connect(m_project, &Project::fileListChanged, this, [this]{
m_fileFinder.setProjectFiles(m_project->files(Project::AllFiles));
handleOpenedDocs();
});
const AxivionProjectSettings *projSettings = AxivionProjectSettings::projectSettings(m_project);
fetchProjectInfo(projSettings->dashboardProjectName());
}
@@ -961,7 +970,7 @@ void AxivionPluginPrivate::handleAnchorClicked(const QUrl &url)
return;
Link link;
if (const QString path = query.queryItemValue("filename", QUrl::FullyDecoded); !path.isEmpty())
link.targetFilePath = m_project->projectDirectory().pathAppended(path);
link.targetFilePath = findFileForIssuePath(FilePath::fromUserInput(path));
if (const QString line = query.queryItemValue("line"); !line.isEmpty())
link.targetLine = line.toInt();
// column entry is wrong - so, ignore it
@@ -1040,6 +1049,15 @@ const std::optional<DashboardInfo> currentDashboardInfo()
return dd->m_dashboardInfo;
}
Utils::FilePath findFileForIssuePath(const Utils::FilePath &issuePath)
{
QTC_ASSERT(dd, return {});
const FilePaths result = dd->m_fileFinder.findFile(QUrl::fromLocalFile(issuePath.toString()));
if (result.size() == 1)
return dd->m_project->projectDirectory().resolvePath(result.first());
return {};
}
} // Axivion::Internal
#include "axivionplugin.moc"

View File

@@ -79,5 +79,7 @@ void fetchIssueInfo(const QString &id);
const std::optional<DashboardInfo> currentDashboardInfo();
Utils::FilePath findFileForIssuePath(const Utils::FilePath &issuePath);
} // Axivion::Internal