summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2022-06-20 12:35:13 +0200
committerTim Jenssen <tim.jenssen@qt.io>2022-07-13 17:13:23 +0000
commitfd89043de2f8de1588ee61514170e0168e13e238 (patch)
tree8a9dedc64d065bc8c5a076607421adf636c0177a /src/libs/qmljs/qmljsmodelmanagerinterface.cpp
parent0bb272d41112dcdc3a92c8b6320294c415d630e5 (diff)
downloadqt-creator-fd89043de2f8de1588ee61514170e0168e13e238.tar.gz
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>
Diffstat (limited to 'src/libs/qmljs/qmljsmodelmanagerinterface.cpp')
-rw-r--r--src/libs/qmljs/qmljsmodelmanagerinterface.cpp342
1 files changed, 175 insertions, 167 deletions
diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
index 444d429a4b..78c60a406c 100644
--- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
+++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
@@ -84,21 +84,21 @@ static ModelManagerInterface *g_instance = nullptr;
static QMutex g_instanceMutex;
static const char *qtQuickUISuffix = "ui.qml";
-static void maybeAddPath(ViewerContext &context, const QString &path)
+static void maybeAddPath(ViewerContext &context, const Utils::FilePath &path)
{
if (!path.isEmpty() && !context.paths.contains(path))
context.paths.append(path);
}
-static QStringList environmentImportPaths()
+static QList<Utils::FilePath> environmentImportPaths()
{
- QStringList paths;
+ QList<Utils::FilePath> paths;
const QStringList importPaths = QString::fromLocal8Bit(qgetenv("QML_IMPORT_PATH")).split(
Utils::HostOsInfo::pathListSeparator(), Qt::SkipEmptyParts);
for (const QString &path : importPaths) {
- const QString canonicalPath = QDir(path).canonicalPath();
+ const Utils::FilePath canonicalPath = Utils::FilePath::fromString(path).canonicalPath();
if (!canonicalPath.isEmpty() && !paths.contains(canonicalPath))
paths.append(canonicalPath);
}
@@ -177,15 +177,14 @@ static QHash<QString, Dialect> defaultLanguageMapping()
return res;
}
-Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
+Dialect ModelManagerInterface::guessLanguageOfFile(const Utils::FilePath &fileName)
{
QHash<QString, Dialect> lMapping;
if (instance())
lMapping = instance()->languageForSuffix();
else
lMapping = defaultLanguageMapping();
- const QFileInfo info(fileName);
- QString fileSuffix = info.suffix();
+ QString fileSuffix = fileName.suffix();
/*
* I was reluctant to use complete suffix in all cases, because it is a huge
@@ -193,7 +192,7 @@ Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
*/
if (fileSuffix == QLatin1String("qml"))
- fileSuffix = info.completeSuffix();
+ fileSuffix = fileName.completeSuffix();
return lMapping.value(fileSuffix, Dialect::NoLanguage);
}
@@ -326,7 +325,7 @@ Snapshot ModelManagerInterface::newestSnapshot() const
return m_newestSnapshot;
}
-void ModelManagerInterface::updateSourceFiles(const QStringList &files,
+void ModelManagerInterface::updateSourceFiles(const QList<Utils::FilePath> &files,
bool emitDocumentOnDiskChanged)
{
if (m_indexerDisabled)
@@ -334,7 +333,7 @@ void ModelManagerInterface::updateSourceFiles(const QStringList &files,
refreshSourceFiles(files, emitDocumentOnDiskChanged);
}
-QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourceFiles,
+QFuture<void> ModelManagerInterface::refreshSourceFiles(const QList<Utils::FilePath> &sourceFiles,
bool emitDocumentOnDiskChanged)
{
if (sourceFiles.isEmpty())
@@ -365,21 +364,23 @@ QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourc
return result;
}
-
-void ModelManagerInterface::fileChangedOnDisk(const QString &path)
+void ModelManagerInterface::fileChangedOnDisk(const Utils::FilePath &path)
{
addFuture(Utils::runAsync(&ModelManagerInterface::parse,
- workingCopyInternal(), QStringList(path),
- this, Dialect(Dialect::AnyLanguage), true));
+ workingCopyInternal(),
+ FilePaths({path}),
+ this,
+ Dialect(Dialect::AnyLanguage),
+ true));
}
-void ModelManagerInterface::removeFiles(const QStringList &files)
+void ModelManagerInterface::removeFiles(const QList<Utils::FilePath> &files)
{
emit aboutToRemoveFiles(files);
QMutexLocker locker(&m_mutex);
- for (const QString &file : files) {
+ for (const Utils::FilePath &file : files) {
m_validSnapshot.remove(file);
m_newestSnapshot.remove(file);
}
@@ -389,8 +390,8 @@ namespace {
bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1,
const ModelManagerInterface::ProjectInfo &p2)
{
- QStringList s1 = p1.activeResourceFiles;
- QStringList s2 = p2.activeResourceFiles;
+ QList<Utils::FilePath> s1 = p1.activeResourceFiles;
+ QList<Utils::FilePath> s2 = p2.activeResourceFiles;
if (s1.size() < s2.size())
return true;
if (s1.size() > s2.size())
@@ -407,8 +408,8 @@ bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1,
bool pInfoLessThanAll(const ModelManagerInterface::ProjectInfo &p1,
const ModelManagerInterface::ProjectInfo &p2)
{
- QStringList s1 = p1.allResourceFiles;
- QStringList s2 = p2.allResourceFiles;
+ QList<Utils::FilePath> s1 = p1.allResourceFiles;
+ QList<Utils::FilePath> s2 = p2.allResourceFiles;
if (s1.size() < s2.size())
return true;
if (s1.size() > s2.size())
@@ -446,11 +447,10 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1,
}
-static QList<Utils::FilePath> generatedQrc(QStringList applicationDirectories)
+static QList<Utils::FilePath> generatedQrc(QList<Utils::FilePath> applicationDirectories)
{
QList<Utils::FilePath> res;
- for (const QString &pathStr : applicationDirectories) {
- Utils::FilePath path = Utils::FilePath::fromString(pathStr);
+ for (const Utils::FilePath &path : applicationDirectories) {
Utils::FilePath generatedQrcDir = path.pathAppended(".rcc");
if (generatedQrcDir.isReadableDir()) {
for (const Utils::FilePath & qrcPath: generatedQrcDir.dirEntries(FileFilter(QStringList({QStringLiteral(u"*.qrc")}), QDir::Files)))
@@ -477,15 +477,14 @@ void ModelManagerInterface::iterateQrcFiles(
QSet<Utils::FilePath> pathsChecked;
for (const ModelManagerInterface::ProjectInfo &pInfo : qAsConst(pInfos)) {
- QStringList qrcFilePaths;
+ QList<Utils::FilePath> qrcFilePaths;
if (resources == ActiveQrcResources)
qrcFilePaths = pInfo.activeResourceFiles;
else
qrcFilePaths = pInfo.allResourceFiles;
for (const Utils::FilePath &p : generatedQrc(pInfo.applicationDirectories))
- qrcFilePaths.append(p.toString());
- for (const QString &qrcFilePathStr : qAsConst(qrcFilePaths)) {
- auto qrcFilePath = Utils::FilePath::fromString(qrcFilePathStr);
+ qrcFilePaths.append(p);
+ for (const Utils::FilePath &qrcFilePath : qAsConst(qrcFilePaths)) {
if (pathsChecked.contains(qrcFilePath))
continue;
pathsChecked.insert(qrcFilePath);
@@ -497,13 +496,14 @@ void ModelManagerInterface::iterateQrcFiles(
}
}
-QStringList ModelManagerInterface::qrcPathsForFile(const QString &file, const QLocale *locale,
+QStringList ModelManagerInterface::qrcPathsForFile(const Utils::FilePath &file,
+ const QLocale *locale,
ProjectExplorer::Project *project,
QrcResourceSelector resources)
{
QStringList res;
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
- qrcFile->collectResourceFilesForSourceFile(file, &res, locale);
+ qrcFile->collectResourceFilesForSourceFile(file.toString(), &res, locale);
});
return res;
}
@@ -579,21 +579,20 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
updateImportPaths();
// remove files that are no longer in the project and have been deleted
- QStringList deletedFiles;
- for (const QString &oldFile : qAsConst(oldInfo.sourceFiles)) {
- if (snapshot.document(oldFile)
- && !pinfo.sourceFiles.contains(oldFile)
- && !QFile::exists(oldFile)) {
+ QList<Utils::FilePath> deletedFiles;
+ for (const Utils::FilePath &oldFile : qAsConst(oldInfo.sourceFiles)) {
+ if (snapshot.document(oldFile) && !pinfo.sourceFiles.contains(oldFile)
+ && !oldFile.exists()) {
deletedFiles += oldFile;
}
}
removeFiles(deletedFiles);
- for (const QString &oldFile : qAsConst(deletedFiles))
+ for (const Utils::FilePath &oldFile : qAsConst(deletedFiles))
m_fileToProject.remove(oldFile, p);
// parse any files not yet in the snapshot
- QStringList newFiles;
- for (const QString &file : qAsConst(pinfo.sourceFiles)) {
+ QList<Utils::FilePath> newFiles;
+ for (const Utils::FilePath &file : qAsConst(pinfo.sourceFiles)) {
if (!m_fileToProject.contains(file, p))
m_fileToProject.insert(file, p);
if (!snapshot.document(file))
@@ -604,12 +603,12 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
// update qrc cache
m_qrcContents = pinfo.resourceFileContents;
- for (const QString &newQrc : qAsConst(pinfo.allResourceFiles))
- m_qrcCache.addPath(newQrc, m_qrcContents.value(newQrc));
+ for (const Utils::FilePath &newQrc : qAsConst(pinfo.allResourceFiles))
+ m_qrcCache.addPath(newQrc.toString(), m_qrcContents.value(newQrc));
for (const Utils::FilePath &newQrc : generatedQrc(pinfo.applicationDirectories))
- m_qrcCache.addPath(newQrc.toString(), m_qrcContents.value(newQrc.toString()));
- for (const QString &oldQrc : qAsConst(oldInfo.allResourceFiles))
- m_qrcCache.removePath(oldQrc);
+ m_qrcCache.addPath(newQrc.toString(), m_qrcContents.value(newQrc));
+ for (const Utils::FilePath &oldQrc : qAsConst(oldInfo.allResourceFiles))
+ m_qrcCache.removePath(oldQrc.toString());
m_pluginDumper->loadBuiltinTypes(pinfo);
emit projectInfoUpdated(pinfo);
@@ -635,7 +634,7 @@ void ModelManagerInterface::removeProjectInfo(ProjectExplorer::Project *project)
\note Project pointer will be empty
*/
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(
- const QString &path) const
+ const Utils::FilePath &path) const
{
ProjectInfo res;
const auto allProjectInfos = allProjectInfosForPath(path);
@@ -659,16 +658,14 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(
Returns list of project infos for \a path
*/
QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfosForPath(
- const QString &path) const
+ const Utils::FilePath &path) const
{
QList<ProjectExplorer::Project *> projects;
{
QMutexLocker locker(&m_mutex);
projects = m_fileToProject.values(path);
- if (projects.isEmpty()) {
- QFileInfo fInfo(path);
- projects = m_fileToProject.values(fInfo.canonicalFilePath());
- }
+ if (projects.isEmpty())
+ projects = m_fileToProject.values(path.canonicalPath());
}
QList<ProjectInfo> infos;
for (ProjectExplorer::Project *project : qAsConst(projects)) {
@@ -689,9 +686,9 @@ void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
emit documentChangedOnDisk(std::move(doc));
}
-void ModelManagerInterface::updateQrcFile(const QString &path)
+void ModelManagerInterface::updateQrcFile(const Utils::FilePath &path)
{
- m_qrcCache.updatePath(path, m_qrcContents.value(path));
+ m_qrcCache.updatePath(path.toString(), m_qrcContents.value(path));
}
void ModelManagerInterface::updateDocument(const Document::Ptr &doc)
@@ -711,30 +708,30 @@ void ModelManagerInterface::updateLibraryInfo(const FilePath &path, const Librar
{
QMutexLocker locker(&m_mutex);
- m_validSnapshot.insertLibraryInfo(path.toString(), info);
- m_newestSnapshot.insertLibraryInfo(path.toString(), info);
+ m_validSnapshot.insertLibraryInfo(path, info);
+ m_newestSnapshot.insertLibraryInfo(path, info);
}
// only emit if we got new useful information
if (info.isValid())
- emit libraryInfoUpdated(path.toString(), info);
+ emit libraryInfoUpdated(path, info);
}
-static QStringList filesInDirectoryForLanguages(const QString &path,
- const QList<Dialect> &languages)
+static QList<Utils::FilePath> filesInDirectoryForLanguages(const Utils::FilePath &path,
+ const QList<Dialect> &languages)
{
const QStringList pattern = ModelManagerInterface::globPatternsForLanguages(languages);
- QStringList files;
+ QList<Utils::FilePath> files;
- const QDir dir(path);
- const auto entries = dir.entryInfoList(pattern, QDir::Files);
- for (const QFileInfo &fi : entries)
- files += fi.absoluteFilePath();
+ for (const Utils::FilePath &p : path.dirEntries(FileFilter(pattern, QDir::Files)))
+ files.append(p.absoluteFilePath());
return files;
}
-static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &snapshot,
- QStringList *importedFiles, QSet<QString> *scannedPaths)
+static void findNewImplicitImports(const Document::Ptr &doc,
+ const Snapshot &snapshot,
+ QList<Utils::FilePath> *importedFiles,
+ QSet<Utils::FilePath> *scannedPaths)
{
// scan files that could be implicitly imported
// it's important we also do this for JS files, otherwise the isEmpty check will fail
@@ -747,28 +744,33 @@ static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &sna
}
}
-static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapshot,
- QStringList *importedFiles, QSet<QString> *scannedPaths)
+static void findNewFileImports(const Document::Ptr &doc,
+ const Snapshot &snapshot,
+ QList<Utils::FilePath> *importedFiles,
+ QSet<Utils::FilePath> *scannedPaths)
{
// scan files and directories that are explicitly imported
const auto imports = doc->bind()->imports();
for (const ImportInfo &import : imports) {
const QString &importName = import.path();
+ Utils::FilePath importPath = Utils::FilePath::fromString(importName);
if (import.type() == ImportType::File) {
- if (! snapshot.document(importName))
- *importedFiles += importName;
+ if (!snapshot.document(importPath))
+ *importedFiles += importPath;
} else if (import.type() == ImportType::Directory) {
- if (snapshot.documentsInDirectory(importName).isEmpty()) {
- if (! scannedPaths->contains(importName)) {
- *importedFiles += filesInDirectoryForLanguages(
- importName, doc->language().companionLanguages());
- scannedPaths->insert(importName);
+ if (snapshot.documentsInDirectory(importPath).isEmpty()) {
+ if (!scannedPaths->contains(importPath)) {
+ *importedFiles
+ += filesInDirectoryForLanguages(importPath,
+ doc->language().companionLanguages());
+ scannedPaths->insert(importPath);
}
}
} else if (import.type() == ImportType::QrcFile) {
const QStringList importPaths
= ModelManagerInterface::instance()->filesAtQrcPath(importName);
- for (const QString &importPath : importPaths) {
+ for (const QString &importStr : importPaths) {
+ Utils::FilePath importPath = Utils::FilePath::fromString(importStr);
if (!snapshot.document(importPath))
*importedFiles += importPath;
}
@@ -776,10 +778,13 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
const QMap<QString, QStringList> files
= ModelManagerInterface::instance()->filesInQrcPath(importName);
for (auto qrc = files.cbegin(), end = files.cend(); qrc != end; ++qrc) {
- if (ModelManagerInterface::guessLanguageOfFile(qrc.key()).isQmlLikeOrJsLanguage()) {
+ if (ModelManagerInterface::guessLanguageOfFile(
+ Utils::FilePath::fromString(qrc.key()))
+ .isQmlLikeOrJsLanguage()) {
for (const QString &sourceFile : qrc.value()) {
- if (!snapshot.document(sourceFile))
- *importedFiles += sourceFile;
+ auto sourceFilePath = Utils::FilePath::fromString(sourceFile);
+ if (!snapshot.document(sourceFilePath))
+ *importedFiles += sourceFilePath;
}
}
}
@@ -793,8 +798,9 @@ enum class LibraryStatus {
Unknown
};
-static LibraryStatus libraryStatus(const FilePath &path, const Snapshot &snapshot,
- QSet<QString> *newLibraries)
+static LibraryStatus libraryStatus(const FilePath &path,
+ const Snapshot &snapshot,
+ QSet<Utils::FilePath> *newLibraries)
{
if (path.isEmpty())
return LibraryStatus::Rejected;
@@ -802,7 +808,7 @@ static LibraryStatus libraryStatus(const FilePath &path, const Snapshot &snapsho
const LibraryInfo &existingInfo = snapshot.libraryInfo(path);
if (existingInfo.isValid())
return LibraryStatus::Accepted;
- if (newLibraries->contains(path.toString()))
+ if (newLibraries->contains(path))
return LibraryStatus::Accepted;
// if we looked at the path before, done
return existingInfo.wasScanned()
@@ -813,7 +819,7 @@ static LibraryStatus libraryStatus(const FilePath &path, const Snapshot &snapsho
static bool findNewQmlApplicationInPath(const FilePath &path,
const Snapshot &snapshot,
ModelManagerInterface *modelManager,
- QSet<QString> *newLibraries)
+ QSet<FilePath> *newLibraries)
{
switch (libraryStatus(path, snapshot, newLibraries)) {
case LibraryStatus::Accepted: return true;
@@ -821,45 +827,43 @@ static bool findNewQmlApplicationInPath(const FilePath &path,
default: break;
}
- QString qmltypesFile;
+ FilePath qmltypesFile;
- QDir dir(path.toString());
- QDirIterator it(path.toString(), QStringList { "*.qmltypes" }, QDir::Files);
+ QList<Utils::FilePath> qmlTypes = path.dirEntries(
+ FileFilter(QStringList{"*.qmltypes"}, QDir::Files));
- if (!it.hasNext())
+ if (qmlTypes.isEmpty())
return false;
- qmltypesFile = it.next();
+ qmltypesFile = qmlTypes.first();
- LibraryInfo libraryInfo = LibraryInfo(qmltypesFile);
- const QString libraryPath = dir.absolutePath();
+ LibraryInfo libraryInfo = LibraryInfo(qmltypesFile.toString());
+ const Utils::FilePath libraryPath = path.absolutePath();
newLibraries->insert(libraryPath);
modelManager->updateLibraryInfo(path, libraryInfo);
- modelManager->loadPluginTypes(QFileInfo(libraryPath).canonicalFilePath(), libraryPath,
- QString(), QString());
+ modelManager->loadPluginTypes(libraryPath.canonicalPath(), libraryPath, QString(), QString());
return true;
}
-static bool findNewQmlLibraryInPath(const QString &path,
+static bool findNewQmlLibraryInPath(const Utils::FilePath &path,
const Snapshot &snapshot,
ModelManagerInterface *modelManager,
- QStringList *importedFiles,
- QSet<QString> *scannedPaths,
- QSet<QString> *newLibraries,
+ QList<Utils::FilePath> *importedFiles,
+ QSet<Utils::FilePath> *scannedPaths,
+ QSet<Utils::FilePath> *newLibraries,
bool ignoreMissing)
{
- switch (libraryStatus(FilePath::fromString(path), snapshot, newLibraries)) {
+ switch (libraryStatus(path, snapshot, newLibraries)) {
case LibraryStatus::Accepted: return true;
case LibraryStatus::Rejected: return false;
default: break;
}
- const QDir dir(path);
- QFile qmldirFile(dir.filePath(QLatin1String("qmldir")));
+ Utils::FilePath qmldirFile = path.pathAppended(QLatin1String("qmldir"));
if (!qmldirFile.exists()) {
if (!ignoreMissing) {
LibraryInfo libraryInfo(LibraryInfo::NotFound);
- modelManager->updateLibraryInfo(FilePath::fromString(path), libraryInfo);
+ modelManager->updateLibraryInfo(path, libraryInfo);
}
return false;
}
@@ -869,25 +873,24 @@ static bool findNewQmlLibraryInPath(const QString &path,
}
// found a new library!
- if (!qmldirFile.open(QFile::ReadOnly))
+ if (!qmldirFile.isReadableFile())
return false;
- QString qmldirData = QString::fromUtf8(qmldirFile.readAll());
+ QString qmldirData = QString::fromUtf8(qmldirFile.fileContents());
QmlDirParser qmldirParser;
qmldirParser.parse(qmldirData);
- const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
+ const Utils::FilePath libraryPath = qmldirFile.absolutePath();
newLibraries->insert(libraryPath);
- modelManager->updateLibraryInfo(FilePath::fromString(libraryPath), LibraryInfo(qmldirParser));
- modelManager->loadPluginTypes(QFileInfo(libraryPath).canonicalFilePath(), libraryPath,
- QString(), QString());
+ modelManager->updateLibraryInfo(libraryPath, LibraryInfo(qmldirParser));
+ modelManager->loadPluginTypes(libraryPath.canonicalPath(), libraryPath, QString(), QString());
// scan the qml files in the library
const auto components = qmldirParser.components();
for (const QmlDirParser::Component &component : components) {
if (!component.fileName.isEmpty()) {
- const QFileInfo componentFileInfo(dir.filePath(component.fileName));
- const QString path = QDir::cleanPath(componentFileInfo.absolutePath());
+ const FilePath componentFile = path.pathAppended(component.fileName);
+ const FilePath path = componentFile.absolutePath().cleanPath();
if (!scannedPaths->contains(path)) {
*importedFiles += filesInDirectoryForLanguages(path, Dialect(Dialect::AnyLanguage)
.companionLanguages());
@@ -899,31 +902,39 @@ static bool findNewQmlLibraryInPath(const QString &path,
return true;
}
-static QString modulePath(const ImportInfo &import, const QStringList &paths)
+static FilePath modulePath(const ImportInfo &import, const QList<FilePath> &paths)
{
if (!import.version().isValid())
- return QString();
+ return FilePath();
- const QStringList modPaths = modulePaths(import.name(), import.version().toString(), paths);
+ const QList<FilePath> modPaths = modulePaths(import.name(), import.version().toString(), paths);
return modPaths.value(0); // first is best match
}
-static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snapshot,
- ModelManagerInterface *modelManager, QStringList *importedFiles,
- QSet<QString> *scannedPaths, QSet<QString> *newLibraries)
+static void findNewLibraryImports(const Document::Ptr &doc,
+ const Snapshot &snapshot,
+ ModelManagerInterface *modelManager,
+ QList<FilePath> *importedFiles,
+ QSet<Utils::FilePath> *scannedPaths,
+ QSet<Utils::FilePath> *newLibraries)
{
// scan current dir
findNewQmlLibraryInPath(doc->path(), snapshot, modelManager,
importedFiles, scannedPaths, newLibraries, false);
// scan dir and lib imports
- const QStringList importPaths = modelManager->importPathsNames();
+ const QList<FilePath> importPaths = modelManager->importPathsNames();
const auto imports = doc->bind()->imports();
for (const ImportInfo &import : imports) {
switch (import.type()) {
case ImportType::Directory:
- findNewQmlLibraryInPath(import.path(), snapshot, modelManager,
- importedFiles, scannedPaths, newLibraries, false);
+ findNewQmlLibraryInPath(Utils::FilePath::fromString(import.path()),
+ snapshot,
+ modelManager,
+ importedFiles,
+ scannedPaths,
+ newLibraries,
+ false);
break;
case ImportType::Library:
findNewQmlLibraryInPath(modulePath(import, importPaths), snapshot, modelManager,
@@ -935,10 +946,10 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
}
}
-void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
- QSet<QString> &newLibraries,
+void ModelManagerInterface::parseLoop(QSet<Utils::FilePath> &scannedPaths,
+ QSet<Utils::FilePath> &newLibraries,
const WorkingCopy &workingCopy,
- QStringList files,
+ QList<Utils::FilePath> files,
ModelManagerInterface *modelManager,
Dialect mainLanguage,
bool emitDocChangedOnDisk,
@@ -948,7 +959,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
if (!reportProgress(qreal(i) / files.size()))
return;
- const QString fileName = files.at(i);
+ const Utils::FilePath fileName = files.at(i);
Dialect language = guessLanguageOfFile(fileName);
if (language == Dialect::NoLanguage) {
@@ -971,12 +982,9 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
contents = entry.first;
documentRevision = entry.second;
} else {
- QFile inFile(fileName);
-
- if (inFile.open(QIODevice::ReadOnly)) {
- QTextStream ins(&inFile);
+ if (fileName.isReadableFile()) {
+ QTextStream ins(fileName.fileContents());
contents = ins.readAll();
- inFile.close();
} else {
continue;
}
@@ -999,7 +1007,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
}
#endif
// get list of referenced files not yet in snapshot or in directories already scanned
- QStringList importedFiles;
+ QList<Utils::FilePath> importedFiles;
// update snapshot. requires synchronization, but significantly reduces amount of file
// system queries for library imports because queries are cached in libraryInfo
@@ -1015,7 +1023,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
}
// add new files to parse list
- for (const QString &file : qAsConst(importedFiles)) {
+ for (const Utils::FilePath &file : qAsConst(importedFiles)) {
if (!files.contains(file))
files.append(file);
}
@@ -1048,7 +1056,7 @@ private:
void ModelManagerInterface::parse(QFutureInterface<void> &future,
const WorkingCopy &workingCopy,
- QStringList files,
+ QList<Utils::FilePath> files,
ModelManagerInterface *modelManager,
Dialect mainLanguage,
bool emitDocChangedOnDisk)
@@ -1058,16 +1066,16 @@ void ModelManagerInterface::parse(QFutureInterface<void> &future,
future.setProgressRange(0, progressMax);
// paths we have scanned for files and added to the files list
- QSet<QString> scannedPaths;
+ QSet<Utils::FilePath> scannedPaths;
// libraries we've found while scanning imports
- QSet<QString> newLibraries;
+ QSet<Utils::FilePath> newLibraries;
parseLoop(scannedPaths, newLibraries, workingCopy, std::move(files), modelManager, mainLanguage,
emitDocChangedOnDisk, reporter);
future.setProgressValue(progressMax);
}
struct ScanItem {
- QString path;
+ Utils::FilePath path;
int depth = 0;
Dialect language = Dialect::AnyLanguage;
};
@@ -1079,20 +1087,20 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
bool emitDocChangedOnDisk, bool libOnly, bool forceRescan)
{
// paths we have scanned for files and added to the files list
- QSet<QString> scannedPaths;
+ QSet<Utils::FilePath> scannedPaths;
{
QMutexLocker l(&modelManager->m_mutex);
scannedPaths = modelManager->m_scannedPaths;
}
// libraries we've found while scanning imports
- QSet<QString> newLibraries;
+ QSet<Utils::FilePath> newLibraries;
QVector<ScanItem> pathsToScan;
pathsToScan.reserve(paths.size());
{
QMutexLocker l(&modelManager->m_mutex);
for (const auto &path : paths) {
- QString cPath = QDir::cleanPath(path.path().toString());
+ Utils::FilePath cPath = path.path().cleanPath();
if (!forceRescan && modelManager->m_scannedPaths.contains(cPath))
continue;
pathsToScan.append({cPath, 0, path.language()});
@@ -1111,7 +1119,7 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
pathsToScan.pop_back();
int pathBudget = (1 << (maxScanDepth + 2 - toScan.depth));
if (forceRescan || !scannedPaths.contains(toScan.path)) {
- QStringList importedFiles;
+ QList<Utils::FilePath> importedFiles;
if (forceRescan ||
(!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles,
&scannedPaths, &newLibraries, true)
@@ -1135,12 +1143,12 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
}
// always descend tree, as we might have just scanned with a smaller depth
if (toScan.depth < maxScanDepth) {
- QDir dir(toScan.path);
- QStringList subDirs(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot));
+ Utils::FilePath dir = toScan.path;
+ const QList<Utils::FilePath> subDirs = dir.dirEntries(QDir::Dirs | QDir::NoDotAndDotDot);
workDone += 1;
totalWork += pathBudget / 2 * subDirs.size() - pathBudget * 3 / 4 + 1;
- for (const QString &path : qAsConst(subDirs))
- pathsToScan.append({dir.absoluteFilePath(path), toScan.depth + 1, toScan.language});
+ for (const Utils::FilePath &path : subDirs)
+ pathsToScan.append({path.absoluteFilePath(), toScan.depth + 1, toScan.language});
} else {
workDone += pathBudget * 3 / 4;
}
@@ -1152,17 +1160,17 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
// assume no work has been done
QMutexLocker l(&modelManager->m_mutex);
for (const auto &path : paths)
- modelManager->m_scannedPaths.remove(path.path().toString());
+ modelManager->m_scannedPaths.remove(path.path());
}
}
-QStringList ModelManagerInterface::importPathsNames() const
+QList<Utils::FilePath> ModelManagerInterface::importPathsNames() const
{
- QStringList names;
+ QList<Utils::FilePath> names;
QMutexLocker l(&m_mutex);
names.reserve(m_allImportPaths.size());
for (const PathAndLanguage &x: m_allImportPaths)
- names << x.path().toString();
+ names << x.path();
return names;
}
@@ -1186,7 +1194,7 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
{
QMutexLocker l(&m_mutex);
for (const PathAndLanguage &importPath : importPaths)
- if (!m_scannedPaths.contains(importPath.path().toString()))
+ if (!m_scannedPaths.contains(importPath.path()))
pathToScan.maybeInsert(importPath);
}
@@ -1199,12 +1207,11 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
}
}
-static QList<Utils::FilePath> minimalPrefixPaths(const QStringList &paths)
+static QList<Utils::FilePath> minimalPrefixPaths(const QList<Utils::FilePath> &paths)
{
QList<Utils::FilePath> sortedPaths;
// find minimal prefix, ensure '/' at end
- for (const QString &pathStr : qAsConst(paths)) {
- Utils::FilePath path = Utils::FilePath::fromString(pathStr);
+ for (Utils::FilePath path : qAsConst(paths)) {
if (!path.endsWith("/"))
path.setPath(path.path() + "/");
if (path.path().length() > 1)
@@ -1227,7 +1234,7 @@ void ModelManagerInterface::updateImportPaths()
if (m_indexerDisabled)
return;
PathsAndLanguages allImportPaths;
- QStringList allApplicationDirectories;
+ QList<Utils::FilePath> allApplicationDirectories;
QmlLanguageBundles activeBundles;
QmlLanguageBundles extendedBundles;
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
@@ -1242,8 +1249,8 @@ void ModelManagerInterface::updateImportPaths()
}
for (const ViewerContext &vContext : qAsConst(m_defaultVContexts)) {
- for (const QString &path : vContext.paths)
- allImportPaths.maybeInsert(Utils::FilePath::fromString(path), vContext.language);
+ for (const Utils::FilePath &path : vContext.paths)
+ allImportPaths.maybeInsert(path, vContext.language);
allApplicationDirectories.append(vContext.applicationDirectories);
}
@@ -1275,8 +1282,8 @@ void ModelManagerInterface::updateImportPaths()
allImportPaths.maybeInsert(importPath);
}
- for (const QString &path : qAsConst(m_defaultImportPaths))
- allImportPaths.maybeInsert(Utils::FilePath::fromString(path), Dialect::Qml);
+ for (const Utils::FilePath &path : qAsConst(m_defaultImportPaths))
+ allImportPaths.maybeInsert(path, Dialect::Qml);
allImportPaths.compact();
allApplicationDirectories = Utils::filteredUnique(allApplicationDirectories);
@@ -1291,18 +1298,17 @@ void ModelManagerInterface::updateImportPaths()
// check if any file in the snapshot imports something new in the new paths
Snapshot snapshot = m_validSnapshot;
- QStringList importedFiles;
- QSet<QString> scannedPaths;
- QSet<QString> newLibraries;
+ QList<Utils::FilePath> importedFiles;
+ QSet<Utils::FilePath> scannedPaths;
+ QSet<Utils::FilePath> newLibraries;
for (const Document::Ptr &doc : qAsConst(snapshot))
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
- for (const QString &pathStr : qAsConst(allApplicationDirectories)) {
- Utils::FilePath path = Utils::FilePath::fromString(pathStr);
+ for (const Utils::FilePath &path : qAsConst(allApplicationDirectories)) {
allImportPaths.maybeInsert(path, Dialect::Qml);
findNewQmlApplicationInPath(path, snapshot, this, &newLibraries);
}
for (const Utils::FilePath &qrcPath : generatedQrc(allApplicationDirectories))
- updateQrcFile(qrcPath.toString());
+ updateQrcFile(qrcPath);
updateSourceFiles(importedFiles, true);
@@ -1311,8 +1317,10 @@ void ModelManagerInterface::updateImportPaths()
maybeScan(allImportPaths);
}
-void ModelManagerInterface::loadPluginTypes(const QString &libraryPath, const QString &importPath,
- const QString &importUri, const QString &importVersion)
+void ModelManagerInterface::loadPluginTypes(const Utils::FilePath &libraryPath,
+ const Utils::FilePath &importPath,
+ const QString &importUri,
+ const QString &importVersion)
{
m_pluginDumper->loadPluginTypes(libraryPath, importPath, importUri, importVersion);
}
@@ -1526,25 +1534,25 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
Q_FALLTHROUGH();
case ViewerContext::AddAllPaths:
{
- for (const QString &path : qAsConst(defaultVCtx.paths))
+ for (const Utils::FilePath &path : qAsConst(defaultVCtx.paths))
maybeAddPath(res, path);
switch (res.language.dialect()) {
case Dialect::AnyLanguage:
case Dialect::Qml:
- maybeAddPath(res, info.qtQmlPath.toString());
+ maybeAddPath(res, info.qtQmlPath);
Q_FALLTHROUGH();
case Dialect::QmlQtQuick2:
case Dialect::QmlQtQuick2Ui:
{
if (res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui)
- maybeAddPath(res, info.qtQmlPath.toString());
+ maybeAddPath(res, info.qtQmlPath);
QList<Dialect> languages = res.language.companionLanguages();
auto addPathsOnLanguageMatch = [&](const PathsAndLanguages &importPaths) {
for (const auto &importPath : importPaths) {
if (languages.contains(importPath.language())
|| importPath.language().companionLanguages().contains(res.language)) {
- maybeAddPath(res, importPath.path().toString());
+ maybeAddPath(res, importPath.path());
}
}
};
@@ -1561,7 +1569,7 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
addPathsOnLanguageMatch(pInfo.importPaths);
}
const auto environmentPaths = environmentImportPaths();
- for (const QString &path : environmentPaths)
+ for (const Utils::FilePath &path : environmentPaths)
maybeAddPath(res, path);
break;
}
@@ -1579,14 +1587,14 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
res.selectors.append(defaultVCtx.selectors);
Q_FALLTHROUGH();
case ViewerContext::AddDefaultPaths:
- for (const QString &path : qAsConst(defaultVCtx.paths))
+ for (const Utils::FilePath &path : qAsConst(defaultVCtx.paths))
maybeAddPath(res, path);
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml)
- maybeAddPath(res, info.qtQmlPath.toString());
+ maybeAddPath(res, info.qtQmlPath);
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|| res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui) {
const auto environemntPaths = environmentImportPaths();
- for (const QString &path : environemntPaths)
+ for (const Utils::FilePath &path : environemntPaths)
maybeAddPath(res, path);
}
break;
@@ -1676,7 +1684,7 @@ void ModelManagerInterface::addFuture(const QFuture<void> &future)
m_futureSynchronizer.addFuture(future);
}
-Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &filePath)
+Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const Utils::FilePath &filePath)
{
QmlJS::Document::Ptr document = newestSnapshot().document(filePath);
if (!document) {
@@ -1691,7 +1699,7 @@ Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &fi
void ModelManagerInterface::resetCodeModel()
{
- QStringList documents;
+ QList<Utils::FilePath> documents;
{
QMutexLocker locker(&m_mutex);