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:
Fawzi Mohamed
2022-06-20 12:35:13 +02:00
committed by Tim Jenssen
parent 0bb272d411
commit fd89043de2
79 changed files with 844 additions and 680 deletions

View File

@@ -61,7 +61,7 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
if (!regexp.isValid())
return {};
const QHash<QString, QList<LocatorData::Entry> > locatorEntries = m_data->entries();
const QHash<Utils::FilePath, QList<LocatorData::Entry>> locatorEntries = m_data->entries();
for (const QList<LocatorData::Entry> &items : locatorEntries) {
if (future.isCanceled())
break;
@@ -102,6 +102,5 @@ void FunctionFilter::accept(const Core::LocatorFilterEntry &selection,
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
const LocatorData::Entry entry = qvariant_cast<LocatorData::Entry>(selection.internalData);
Core::EditorManager::openEditorAt(
{Utils::FilePath::fromString(entry.fileName), entry.line, entry.column});
Core::EditorManager::openEditorAt({entry.fileName, entry.line, entry.column});
}

View File

@@ -47,13 +47,15 @@ LocatorData::LocatorData()
// Force the updating of source file when updating a project (they could be cached, in such
// case LocatorData::onDocumentUpdated will not be called.
connect(manager, &ModelManagerInterface::projectInfoUpdated,
connect(manager,
&ModelManagerInterface::projectInfoUpdated,
[manager](const ModelManagerInterface::ProjectInfo &info) {
QStringList files;
for (const Utils::FilePath &f: info.project->files(ProjectExplorer::Project::SourceFiles))
files << f.toString();
manager->updateSourceFiles(files, true);
});
Utils::FilePaths files;
for (const Utils::FilePath &f :
info.project->files(ProjectExplorer::Project::SourceFiles))
files << f;
manager->updateSourceFiles(files, true);
});
connect(manager, &ModelManagerInterface::documentUpdated,
this, &LocatorData::onDocumentUpdated);
@@ -86,7 +88,7 @@ public:
if (!doc->componentName().isEmpty())
m_documentContext = doc->componentName();
else
m_documentContext = Utils::FilePath::fromString(doc->fileName()).fileName();
m_documentContext = doc->fileName().fileName();
accept(doc->ast(), m_documentContext);
return m_entries;
}
@@ -236,7 +238,7 @@ protected:
};
} // anonymous namespace
QHash<QString, QList<LocatorData::Entry> > LocatorData::entries() const
QHash<Utils::FilePath, QList<LocatorData::Entry>> LocatorData::entries() const
{
QMutexLocker l(&m_mutex);
return m_entries;
@@ -249,10 +251,10 @@ void LocatorData::onDocumentUpdated(const Document::Ptr &doc)
m_entries.insert(doc->fileName(), entries);
}
void LocatorData::onAboutToRemoveFiles(const QStringList &files)
void LocatorData::onAboutToRemoveFiles(const Utils::FilePaths &files)
{
QMutexLocker l(&m_mutex);
for (const QString &file : files) {
for (const Utils::FilePath &file : files) {
m_entries.remove(file);
}
}

View File

@@ -25,6 +25,7 @@
#pragma once
#include <utils/filepath.h>
#include <qmljs/qmljsdocument.h>
#include <QObject>
@@ -53,19 +54,19 @@ public:
QString symbolName;
QString displayName;
QString extraInfo;
QString fileName;
Utils::FilePath fileName;
int line;
int column;
};
QHash<QString, QList<Entry> > entries() const;
QHash<Utils::FilePath, QList<Entry>> entries() const;
private:
void onDocumentUpdated(const QmlJS::Document::Ptr &doc);
void onAboutToRemoveFiles(const QStringList &files);
void onAboutToRemoveFiles(const Utils::FilePaths &files);
mutable QMutex m_mutex;
QHash<QString, QList<Entry> > m_entries;
QHash<Utils::FilePath, QList<Entry>> m_entries;
};
} // namespace Internal

View File

@@ -115,14 +115,14 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
Constants::QMLPROJECT_MIMETYPE,
Constants::QMLTYPES_MIMETYPE,
Constants::QMLUI_MIMETYPE };
projectInfo.sourceFiles = Utils::transform(project->files([&qmlTypeNames](const Node *n) {
projectInfo.sourceFiles = project->files([&qmlTypeNames](const Node *n) {
if (!Project::SourceFiles(n))
return false;
const FileNode *fn = n->asFileNode();
return fn && fn->fileType() == FileType::QML
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath(),
MimeMatchMode::MatchExtension).name());
}), &FilePath::toString);
});
activeTarget = project->activeTarget();
}
Kit *activeKit = activeTarget ? activeTarget->kit() : KitManager::defaultKit();
@@ -131,15 +131,15 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
projectInfo.tryQmlDump = false;
if (activeTarget) {
QDir baseDir;
auto addAppDir = [&baseDir, & projectInfo](const QString &mdir) {
auto dir = QDir::cleanPath(mdir);
FilePath baseDir;
auto addAppDir = [&baseDir, &projectInfo](const FilePath &mdir) {
auto dir = mdir.cleanPath();
if (!baseDir.path().isEmpty()) {
auto rDir = baseDir.relativeFilePath(dir);
auto rDir = dir.relativePath(baseDir);
// do not add directories outside the build directory
// this might happen for example when we think an executable path belongs to
// a bundle, and we need to remove extra directories, but that was not the case
if (rDir.split(u'/').contains(QStringLiteral(u"..")))
if (rDir.path().split(u'/').contains(QStringLiteral(u"..")))
return;
}
if (!projectInfo.applicationDirectories.contains(dir))
@@ -153,8 +153,8 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
projectInfo.qmlDumpEnvironment.appendOrSet("QML2_IMPORT_PATH", bc->environment().expandedValueForKey("QML2_IMPORT_PATH"), ":");
// Treat every target (library or application) in the build directory
QString dir = bc->buildDirectory().toString();
baseDir.setPath(QDir{dir}.absolutePath());
FilePath dir = bc->buildDirectory();
baseDir = dir.absoluteFilePath();
addAppDir(dir);
}
// Qml loads modules from the following sources
@@ -169,24 +169,23 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
if (target.targetFilePath.isEmpty())
continue;
auto dir = target.targetFilePath.parentDir();
projectInfo.applicationDirectories.append(dir.toString());
projectInfo.applicationDirectories.append(dir);
// unfortunately the build directory of the executable where cmake puts the qml
// might be different than the directory of the executable:
#if defined(Q_OS_WIN)
// On Windows systems QML type information is located one directory higher as we build
// in dedicated "debug" and "release" directories
addAppDir(
dir.parentDir().toString());
#elif defined(Q_OS_MACOS)
// On macOS and iOS when building a bundle this is not the case and
// we have to go up up to three additional directories
// (BundleName.app/Contents/MacOS or BundleName.app/Contents for iOS)
if (dir.fileName() == u"MacOS")
dir = dir.parentDir();
if (dir.fileName() == u"Contents")
dir = dir.parentDir().parentDir();
addAppDir(dir.toString());
#endif
if (HostOsInfo::isWindowsHost()) {
// On Windows systems QML type information is located one directory higher as we build
// in dedicated "debug" and "release" directories
addAppDir(dir.parentDir());
} else if (HostOsInfo::isMacHost()) {
// On macOS and iOS when building a bundle this is not the case and
// we have to go up up to three additional directories
// (BundleName.app/Contents/MacOS or BundleName.app/Contents for iOS)
if (dir.fileName() == u"MacOS")
dir = dir.parentDir();
if (dir.fileName() == u"Contents")
dir = dir.parentDir().parentDir();
addAppDir(dir);
}
}
}
if (qtVersion && qtVersion->isValid()) {
@@ -271,7 +270,7 @@ void ModelManager::delayedInitialization()
ViewerContext qbsVContext;
qbsVContext.language = Dialect::QmlQbs;
qbsVContext.paths.append(ICore::resourcePath("qbs").toString());
qbsVContext.paths.append(ICore::resourcePath("qbs"));
setDefaultVContext(qbsVContext);
}
@@ -297,7 +296,7 @@ ModelManagerInterface::WorkingCopy ModelManager::workingCopyInternal() const
const QList<IDocument *> documents = DocumentModel::openedDocuments();
for (IDocument *document : documents) {
const QString key = document->filePath().toString();
const Utils::FilePath key = document->filePath();
if (auto textDocument = qobject_cast<const TextEditor::TextDocument *>(document)) {
// TODO the language should be a property on the document, not the editor
if (DocumentModel::editorsForDocument(document).constFirst()

View File

@@ -90,7 +90,7 @@ public:
void fileChanged(const Utils::FilePath &filePath) override
{
m_modelManager->updateSourceFiles({filePath.toString()}, true);
m_modelManager->updateSourceFiles({filePath}, true);
}
ModelManagerInterface *m_modelManager;
@@ -129,7 +129,7 @@ QmlJSRefactoringFile::QmlJSRefactoringFile(
: RefactoringFile(filePath, data)
{
// the RefactoringFile is invalid if its not for a file with qml or js code
if (ModelManagerInterface::guessLanguageOfFile(filePath.toString()) == Dialect::NoLanguage)
if (ModelManagerInterface::guessLanguageOfFile(filePath) == Dialect::NoLanguage)
m_filePath.clear();
}
@@ -138,18 +138,19 @@ QmlJSRefactoringFile::QmlJSRefactoringFile(TextEditor::TextEditorWidget *editor,
, m_qmljsDocument(document)
{
if (document)
m_filePath = Utils::FilePath::fromString(document->fileName());
m_filePath = document->fileName();
}
Document::Ptr QmlJSRefactoringFile::qmljsDocument() const
{
if (!m_qmljsDocument) {
const QString source = document()->toPlainText();
const QString name = filePath().toString();
const Snapshot &snapshot = data()->m_snapshot;
Document::MutablePtr newDoc = snapshot.documentFromSource(source, name,
ModelManagerInterface::guessLanguageOfFile(name));
Document::MutablePtr newDoc
= snapshot.documentFromSource(source,
filePath(),
ModelManagerInterface::guessLanguageOfFile(filePath()));
newDoc->parse();
m_qmljsDocument = newDoc;
}

View File

@@ -43,10 +43,9 @@ void QmlJSToolsPlugin::test_basic()
{
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
const QString qmlFilePath = Core::ICore::resourcePath(
"qmldesigner/itemLibraryQmlSources/ItemDelegate.qml")
.toString();
modelManager->updateSourceFiles(QStringList(qmlFilePath), false);
const Utils::FilePath qmlFilePath = Core::ICore::resourcePath(
"qmldesigner/itemLibraryQmlSources/ItemDelegate.qml");
modelManager->updateSourceFiles(QList<Utils::FilePath>({qmlFilePath}), false);
modelManager->test_joinAllThreads();
Snapshot snapshot = modelManager->snapshot();