forked from qt-creator/qt-creator
qmljs: (QString -> Utils::FilePath)++
convert more QString containing paths to Utils::FilePath Change-Id: I1219d7d147993e48cfa641dc9bea72ab38c90f51 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
committed by
Tim Jenssen
parent
0bb272d411
commit
fd89043de2
@@ -73,7 +73,7 @@ set(QMLPROFILER_CPP_SOURCES
|
||||
|
||||
if(${Qt5_VERSION} VERSION_LESS "6.2.0")
|
||||
add_qtc_plugin(QmlProfiler
|
||||
DEPENDS QmlDebug QmlJS Tracing Qt5::QuickWidgets
|
||||
DEPENDS QmlDebug QmlJS Tracing Qt5::QuickWidgets Utils
|
||||
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport TextEditor
|
||||
SOURCES
|
||||
${TEST_SOURCES}
|
||||
|
||||
@@ -106,7 +106,7 @@ QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriter(QObject *parent)
|
||||
void QmlProfilerDetailsRewriter::requestDetailsForLocation(int typeId,
|
||||
const QmlEventLocation &location)
|
||||
{
|
||||
const QString localFile = getLocalFile(location.filename());
|
||||
const Utils::FilePath localFile = getLocalFile(location.filename());
|
||||
if (localFile.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -116,16 +116,15 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int typeId,
|
||||
m_pendingEvents.insert(localFile, {location, typeId});
|
||||
}
|
||||
|
||||
QString QmlProfilerDetailsRewriter::getLocalFile(const QString &remoteFile)
|
||||
Utils::FilePath QmlProfilerDetailsRewriter::getLocalFile(const QString &remoteFile)
|
||||
{
|
||||
const QString localFile = m_projectFinder.findFile(remoteFile).constFirst().toString();
|
||||
const QFileInfo fileInfo(localFile);
|
||||
if (!fileInfo.exists() || !fileInfo.isReadable())
|
||||
return QString();
|
||||
const Utils::FilePath localFile = m_projectFinder.findFile(remoteFile).constFirst();
|
||||
if (!localFile.exists() || !localFile.isReadableFile())
|
||||
return Utils::FilePath();
|
||||
if (!QmlJS::ModelManagerInterface::guessLanguageOfFile(localFile).isQmlLikeOrJsLanguage())
|
||||
return QString();
|
||||
return Utils::FilePath();
|
||||
|
||||
return fileInfo.canonicalFilePath();
|
||||
return localFile.canonicalPath();
|
||||
}
|
||||
|
||||
void QmlProfilerDetailsRewriter::reloadDocuments()
|
||||
@@ -182,7 +181,7 @@ void QmlProfilerDetailsRewriter::clear()
|
||||
|
||||
void QmlProfilerDetailsRewriter::documentReady(QmlJS::Document::Ptr doc)
|
||||
{
|
||||
const QString &fileName = doc->fileName();
|
||||
const Utils::FilePath &fileName = doc->fileName();
|
||||
auto first = m_pendingEvents.find(fileName);
|
||||
|
||||
// this could be triggered by an unrelated reload in Creator
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
void clear();
|
||||
void requestDetailsForLocation(int typeId, const QmlEventLocation &location);
|
||||
QString getLocalFile(const QString &remoteFile);
|
||||
Utils::FilePath getLocalFile(const QString &remoteFile);
|
||||
void reloadDocuments();
|
||||
void populateFileFinder(const ProjectExplorer::Target *target);
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
int typeId;
|
||||
};
|
||||
|
||||
QMultiHash<QString, PendingEvent> m_pendingEvents;
|
||||
QMultiHash<Utils::FilePath, PendingEvent> m_pendingEvents;
|
||||
Utils::FileInProjectFinder m_projectFinder;
|
||||
|
||||
void rewriteDetailsForLocation(const QString &source, QmlJS::Document::Ptr doc, int typeId,
|
||||
|
||||
@@ -284,7 +284,7 @@ void QmlProfilerModelManager::populateFileFinder(const ProjectExplorer::Target *
|
||||
d->detailsRewriter->populateFileFinder(target);
|
||||
}
|
||||
|
||||
QString QmlProfilerModelManager::findLocalFile(const QString &remoteFile)
|
||||
Utils::FilePath QmlProfilerModelManager::findLocalFile(const QString &remoteFile)
|
||||
{
|
||||
return d->detailsRewriter->getLocalFile(remoteFile);
|
||||
}
|
||||
@@ -323,8 +323,10 @@ int QmlProfilerModelManager::appendEventType(QmlEventType &&type)
|
||||
const QmlEventLocation &location = type.location();
|
||||
if (location.isValid()) {
|
||||
const RangeType rangeType = type.rangeType();
|
||||
const QmlEventLocation localLocation(d->detailsRewriter->getLocalFile(location.filename()),
|
||||
location.line(), location.column());
|
||||
const QmlEventLocation localLocation(d->detailsRewriter->getLocalFile(location.filename())
|
||||
.toString(),
|
||||
location.line(),
|
||||
location.column());
|
||||
|
||||
// location and type are invalid after this
|
||||
const int typeIndex = TimelineTraceManager::appendEventType(std::move(type));
|
||||
@@ -350,9 +352,12 @@ void QmlProfilerModelManager::setEventType(int typeIndex, QmlEventType &&type)
|
||||
// Only bindings and signal handlers need rewriting
|
||||
if (type.rangeType() == Binding || type.rangeType() == HandlingSignal)
|
||||
d->detailsRewriter->requestDetailsForLocation(typeIndex, location);
|
||||
d->textMarkModel->addTextMarkId(typeIndex, QmlEventLocation(
|
||||
d->detailsRewriter->getLocalFile(location.filename()),
|
||||
location.line(), location.column()));
|
||||
d->textMarkModel->addTextMarkId(typeIndex,
|
||||
QmlEventLocation(d->detailsRewriter
|
||||
->getLocalFile(location.filename())
|
||||
.toString(),
|
||||
location.line(),
|
||||
location.column()));
|
||||
}
|
||||
|
||||
TimelineTraceManager::setEventType(typeIndex, std::move(type));
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
void finalize() override;
|
||||
|
||||
void populateFileFinder(const ProjectExplorer::Target *target = nullptr);
|
||||
QString findLocalFile(const QString &remoteFile);
|
||||
Utils::FilePath findLocalFile(const QString &remoteFile);
|
||||
|
||||
static const char *featureName(ProfileFeature feature);
|
||||
|
||||
|
||||
@@ -420,8 +420,7 @@ void QmlProfilerTool::gotoSourceLocation(const QString &fileUrl, int lineNumber,
|
||||
if (lineNumber < 0 || fileUrl.isEmpty())
|
||||
return;
|
||||
|
||||
const auto projectFileName = FilePath::fromString(
|
||||
d->m_profilerModelManager->findLocalFile(fileUrl));
|
||||
const auto projectFileName = d->m_profilerModelManager->findLocalFile(fileUrl);
|
||||
|
||||
if (!projectFileName.exists() || !projectFileName.isReadableFile())
|
||||
return;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QLibraryInfo>
|
||||
#include <QTest>
|
||||
@@ -165,16 +166,16 @@ void QmlProfilerDetailsRewriterTest::testGetLocalFile()
|
||||
Q_UNUSED(factory)
|
||||
|
||||
seedRewriter();
|
||||
QCOMPARE(m_rewriter.getLocalFile("notthere.qml"), QString());
|
||||
QCOMPARE(m_rewriter.getLocalFile("notthere.qml"), Utils::FilePath());
|
||||
QCOMPARE(m_rewriter.getLocalFile("Test.qml"),
|
||||
QString::fromLatin1(":/qmlprofiler/tests/Test.qml"));
|
||||
QCOMPARE(m_rewriter.getLocalFile("qmlprofilerdetailsrewriter_test.cpp"), QString());
|
||||
Utils::FilePath::fromString(":/qmlprofiler/tests/Test.qml"));
|
||||
QCOMPARE(m_rewriter.getLocalFile("qmlprofilerdetailsrewriter_test.cpp"), Utils::FilePath());
|
||||
}
|
||||
|
||||
void QmlProfilerDetailsRewriterTest::testPopulateFileFinder()
|
||||
{
|
||||
m_rewriter.populateFileFinder(nullptr);
|
||||
QCOMPARE(m_rewriter.getLocalFile("Test.qml"), QString());
|
||||
QCOMPARE(m_rewriter.getLocalFile("Test.qml"), Utils::FilePath());
|
||||
|
||||
// Test that the rewriter will populate from available projects if given nullptr as parameter.
|
||||
DummyProject *project1 = new DummyProject(":/nix.nix");
|
||||
@@ -183,7 +184,7 @@ void QmlProfilerDetailsRewriterTest::testPopulateFileFinder()
|
||||
ProjectExplorer::SessionManager::addProject(project2);
|
||||
m_rewriter.populateFileFinder(nullptr);
|
||||
QCOMPARE(m_rewriter.getLocalFile("Test.qml"),
|
||||
QString::fromLatin1(":/qmlprofiler/tests/Test.qml"));
|
||||
Utils::FilePath::fromString(":/qmlprofiler/tests/Test.qml"));
|
||||
|
||||
ProjectExplorer::SessionManager::removeProject(project1);
|
||||
ProjectExplorer::SessionManager::removeProject(project2);
|
||||
@@ -208,7 +209,7 @@ void QmlProfilerDetailsRewriterTest::seedRewriter()
|
||||
const QString content = QString::fromUtf8(file.readAll());
|
||||
file.close();
|
||||
|
||||
QmlJS::Document::MutablePtr doc = QmlJS::Document::create(filename, QmlJS::Dialect::Qml);
|
||||
QmlJS::Document::MutablePtr doc = QmlJS::Document::create(Utils::FilePath::fromString(filename), QmlJS::Dialect::Qml);
|
||||
doc->setSource(content);
|
||||
doc->parse();
|
||||
QVERIFY(!doc->source().isEmpty());
|
||||
|
||||
Reference in New Issue
Block a user