forked from qt-creator/qt-creator
QmlJS: Clean up qmljsmodelmanagerinterface.{h|cpp}
Avoid foreach, fix linter warnings, simplify types, apply coding style. Change-Id: I7cec65e775ee14ce60e1e57077e917285d58c152 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -50,8 +50,6 @@
|
||||
#include <QtAlgorithms>
|
||||
#include <QLibraryInfo>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace QmlJS {
|
||||
@@ -78,8 +76,7 @@ QMLJS_EXPORT Q_LOGGING_CATEGORY(qmljsLog, "qtc.qmljs.common", QtWarningMsg)
|
||||
*/
|
||||
|
||||
static ModelManagerInterface *g_instance = nullptr;
|
||||
|
||||
const char qtQuickUISuffix[] = "ui.qml";
|
||||
static const char *qtQuickUISuffix = "ui.qml";
|
||||
|
||||
static void maybeAddPath(ViewerContext &context, const QString &path)
|
||||
{
|
||||
@@ -111,13 +108,15 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent)
|
||||
m_indexerDisabled = qEnvironmentVariableIsSet("QTC_NO_CODE_INDEXER");
|
||||
|
||||
m_updateCppQmlTypesTimer = new QTimer(this);
|
||||
m_updateCppQmlTypesTimer->setInterval(1000);
|
||||
const int second = 1000;
|
||||
m_updateCppQmlTypesTimer->setInterval(second);
|
||||
m_updateCppQmlTypesTimer->setSingleShot(true);
|
||||
connect(m_updateCppQmlTypesTimer, &QTimer::timeout,
|
||||
this, &ModelManagerInterface::startCppQmlTypeUpdate);
|
||||
|
||||
m_asyncResetTimer = new QTimer(this);
|
||||
m_asyncResetTimer->setInterval(15000);
|
||||
const int fifteenSeconds = 15000;
|
||||
m_asyncResetTimer->setInterval(fifteenSeconds);
|
||||
m_asyncResetTimer->setSingleShot(true);
|
||||
connect(m_asyncResetTimer, &QTimer::timeout, this, &ModelManagerInterface::resetCodeModel);
|
||||
|
||||
@@ -179,7 +178,7 @@ Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
|
||||
return lMapping.value(fileSuffix, Dialect::NoLanguage);
|
||||
}
|
||||
|
||||
QStringList ModelManagerInterface::globPatternsForLanguages(const QList<Dialect> languages)
|
||||
QStringList ModelManagerInterface::globPatternsForLanguages(const QList<Dialect> &languages)
|
||||
{
|
||||
QStringList patterns;
|
||||
const QHash<QString, Dialect> lMapping =
|
||||
@@ -235,7 +234,7 @@ ModelManagerInterface::WorkingCopy ModelManagerInterface::workingCopyInternal()
|
||||
return res;
|
||||
}
|
||||
|
||||
void ModelManagerInterface::addTaskInternal(QFuture<void> result, const QString &msg,
|
||||
void ModelManagerInterface::addTaskInternal(const QFuture<void> &result, const QString &msg,
|
||||
const char *taskId) const
|
||||
{
|
||||
Q_UNUSED(result)
|
||||
@@ -270,9 +269,9 @@ void ModelManagerInterface::loadQmlTypeDescriptionsInternal(const QString &resou
|
||||
CppQmlTypesLoader::defaultLibraryObjects.unite(
|
||||
CppQmlTypesLoader::loadQmlTypes(qmlTypesFiles, &errors, &warnings));
|
||||
|
||||
foreach (const QString &error, errors)
|
||||
for (const QString &error : qAsConst(errors))
|
||||
writeMessageInternal(error);
|
||||
foreach (const QString &warning, warnings)
|
||||
for (const QString &warning : qAsConst(warnings))
|
||||
writeMessageInternal(warning);
|
||||
}
|
||||
|
||||
@@ -297,7 +296,7 @@ Snapshot ModelManagerInterface::newestSnapshot() const
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateSourceFiles(const QStringList &files,
|
||||
bool emitDocumentOnDiskChanged)
|
||||
bool emitDocumentOnDiskChanged)
|
||||
{
|
||||
if (m_indexerDisabled)
|
||||
return;
|
||||
@@ -306,10 +305,11 @@ void ModelManagerInterface::updateSourceFiles(const QStringList &files,
|
||||
|
||||
void ModelManagerInterface::cleanupFutures()
|
||||
{
|
||||
if (m_futures.size() > 10) {
|
||||
QList<QFuture<void> > futures = m_futures;
|
||||
const int maxFutures = 10;
|
||||
if (m_futures.size() > maxFutures) {
|
||||
const QList<QFuture<void>> futures = m_futures;
|
||||
m_futures.clear();
|
||||
foreach (const QFuture<void> &future, futures) {
|
||||
for (const QFuture<void> &future : futures) {
|
||||
if (!(future.isFinished() || future.isCanceled()))
|
||||
m_futures.append(future);
|
||||
}
|
||||
@@ -317,7 +317,7 @@ void ModelManagerInterface::cleanupFutures()
|
||||
}
|
||||
|
||||
QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourceFiles,
|
||||
bool emitDocumentOnDiskChanged)
|
||||
bool emitDocumentOnDiskChanged)
|
||||
{
|
||||
if (sourceFiles.isEmpty())
|
||||
return QFuture<void>();
|
||||
@@ -362,14 +362,15 @@ void ModelManagerInterface::removeFiles(const QStringList &files)
|
||||
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
foreach (const QString &file, files) {
|
||||
for (const QString &file : files) {
|
||||
m_validSnapshot.remove(file);
|
||||
m_newestSnapshot.remove(file);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1, const ModelManagerInterface::ProjectInfo &p2)
|
||||
bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1,
|
||||
const ModelManagerInterface::ProjectInfo &p2)
|
||||
{
|
||||
QStringList s1 = p1.activeResourceFiles;
|
||||
QStringList s2 = p2.activeResourceFiles;
|
||||
@@ -380,13 +381,14 @@ bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1, const Mod
|
||||
for (int i = 0; i < s1.size(); ++i) {
|
||||
if (s1.at(i) < s2.at(i))
|
||||
return true;
|
||||
else if (s1.at(i) > s2.at(i))
|
||||
if (s1.at(i) > s2.at(i))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pInfoLessThanAll(const ModelManagerInterface::ProjectInfo &p1, const ModelManagerInterface::ProjectInfo &p2)
|
||||
bool pInfoLessThanAll(const ModelManagerInterface::ProjectInfo &p1,
|
||||
const ModelManagerInterface::ProjectInfo &p2)
|
||||
{
|
||||
QStringList s1 = p1.allResourceFiles;
|
||||
QStringList s2 = p2.allResourceFiles;
|
||||
@@ -397,13 +399,14 @@ bool pInfoLessThanAll(const ModelManagerInterface::ProjectInfo &p1, const ModelM
|
||||
for (int i = 0; i < s1.size(); ++i) {
|
||||
if (s1.at(i) < s2.at(i))
|
||||
return true;
|
||||
else if (s1.at(i) > s2.at(i))
|
||||
if (s1.at(i) > s2.at(i))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1, const ModelManagerInterface::ProjectInfo &p2)
|
||||
bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1,
|
||||
const ModelManagerInterface::ProjectInfo &p2)
|
||||
{
|
||||
if (p1.qtQmlPath < p2.qtQmlPath)
|
||||
return true;
|
||||
@@ -418,7 +421,7 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1, const Mo
|
||||
for (int i = 0; i < s1.size(); ++i) {
|
||||
if (s1.at(i) < s2.at(i))
|
||||
return true;
|
||||
else if (s2.at(i) < s1.at(i))
|
||||
if (s2.at(i) < s1.at(i))
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -426,9 +429,9 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1, const Mo
|
||||
|
||||
}
|
||||
|
||||
void ModelManagerInterface::iterateQrcFiles(ProjectExplorer::Project *project,
|
||||
QrcResourceSelector resources,
|
||||
std::function<void(QrcParser::ConstPtr)> callback)
|
||||
void ModelManagerInterface::iterateQrcFiles(
|
||||
ProjectExplorer::Project *project, QrcResourceSelector resources,
|
||||
const std::function<void(QrcParser::ConstPtr)> &callback)
|
||||
{
|
||||
QList<ProjectInfo> pInfos;
|
||||
if (project) {
|
||||
@@ -442,13 +445,13 @@ void ModelManagerInterface::iterateQrcFiles(ProjectExplorer::Project *project,
|
||||
}
|
||||
|
||||
QSet<QString> pathsChecked;
|
||||
foreach (const ModelManagerInterface::ProjectInfo &pInfo, pInfos) {
|
||||
for (const ModelManagerInterface::ProjectInfo &pInfo : qAsConst(pInfos)) {
|
||||
QStringList qrcFilePaths;
|
||||
if (resources == ActiveQrcResources)
|
||||
qrcFilePaths = pInfo.activeResourceFiles;
|
||||
else
|
||||
qrcFilePaths = pInfo.allResourceFiles;
|
||||
foreach (const QString &qrcFilePath, qrcFilePaths) {
|
||||
for (const QString &qrcFilePath : qAsConst(qrcFilePaths)) {
|
||||
if (pathsChecked.contains(qrcFilePath))
|
||||
continue;
|
||||
pathsChecked.insert(qrcFilePath);
|
||||
@@ -465,7 +468,7 @@ QStringList ModelManagerInterface::qrcPathsForFile(const QString &file, const QL
|
||||
QrcResourceSelector resources)
|
||||
{
|
||||
QStringList res;
|
||||
iterateQrcFiles(project, resources, [&](QrcParser::ConstPtr qrcFile) {
|
||||
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
|
||||
qrcFile->collectResourceFilesForSourceFile(file, &res, locale);
|
||||
});
|
||||
return res;
|
||||
@@ -477,7 +480,7 @@ QStringList ModelManagerInterface::filesAtQrcPath(const QString &path, const QLo
|
||||
{
|
||||
QString normPath = QrcParser::normalizedQrcFilePath(path);
|
||||
QStringList res;
|
||||
iterateQrcFiles(project, resources, [&](QrcParser::ConstPtr qrcFile) {
|
||||
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
|
||||
qrcFile->collectFilesAtPath(normPath, &res, locale);
|
||||
});
|
||||
return res;
|
||||
@@ -491,7 +494,7 @@ QMap<QString, QStringList> ModelManagerInterface::filesInQrcPath(const QString &
|
||||
{
|
||||
QString normPath = QrcParser::normalizedQrcDirectoryPath(path);
|
||||
QMap<QString, QStringList> res;
|
||||
iterateQrcFiles(project, resources, [&](QrcParser::ConstPtr qrcFile) {
|
||||
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
|
||||
qrcFile->collectFilesInPath(normPath, &res, addDirs, locale);
|
||||
});
|
||||
return res;
|
||||
@@ -504,18 +507,22 @@ QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::projectInfos()
|
||||
return m_projects.values();
|
||||
}
|
||||
|
||||
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfo(
|
||||
ProjectExplorer::Project *project,
|
||||
const ModelManagerInterface::ProjectInfo &defaultValue) const
|
||||
bool ModelManagerInterface::containsProject(ProjectExplorer::Project *project) const
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
return m_projects.contains(project);
|
||||
}
|
||||
|
||||
return m_projects.value(project, defaultValue);
|
||||
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfo(
|
||||
ProjectExplorer::Project *project) const
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
return m_projects.value(project);
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p)
|
||||
{
|
||||
if (! pinfo.isValid() || !p || m_indexerDisabled)
|
||||
if (pinfo.project.isNull() || !p || m_indexerDisabled)
|
||||
return;
|
||||
|
||||
Snapshot snapshot;
|
||||
@@ -539,7 +546,7 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
|
||||
|
||||
// remove files that are no longer in the project and have been deleted
|
||||
QStringList deletedFiles;
|
||||
foreach (const QString &oldFile, oldInfo.sourceFiles) {
|
||||
for (const QString &oldFile : qAsConst(oldInfo.sourceFiles)) {
|
||||
if (snapshot.document(oldFile)
|
||||
&& !pinfo.sourceFiles.contains(oldFile)
|
||||
&& !QFile::exists(oldFile)) {
|
||||
@@ -547,38 +554,27 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
|
||||
}
|
||||
}
|
||||
removeFiles(deletedFiles);
|
||||
foreach (const QString &oldFile, deletedFiles)
|
||||
for (const QString &oldFile : qAsConst(deletedFiles))
|
||||
m_fileToProject.remove(oldFile, p);
|
||||
|
||||
// parse any files not yet in the snapshot
|
||||
QStringList newFiles;
|
||||
foreach (const QString &file, pinfo.sourceFiles) {
|
||||
for (const QString &file : qAsConst(pinfo.sourceFiles)) {
|
||||
if (!snapshot.document(file))
|
||||
newFiles += file;
|
||||
}
|
||||
foreach (const QString &newFile, newFiles)
|
||||
for (const QString &newFile : qAsConst(newFiles))
|
||||
m_fileToProject.insert(newFile, p);
|
||||
updateSourceFiles(newFiles, false);
|
||||
|
||||
// update qrc cache
|
||||
m_qrcContents = pinfo.resourceFileContents;
|
||||
foreach (const QString &newQrc, pinfo.allResourceFiles)
|
||||
for (const QString &newQrc : qAsConst(pinfo.allResourceFiles))
|
||||
m_qrcCache.addPath(newQrc, m_qrcContents.value(newQrc));
|
||||
foreach (const QString &oldQrc, oldInfo.allResourceFiles)
|
||||
for (const QString &oldQrc : qAsConst(oldInfo.allResourceFiles))
|
||||
m_qrcCache.removePath(oldQrc);
|
||||
|
||||
int majorVersion, minorVersion, patchVersion;
|
||||
// dump builtin types if the shipped definitions are probably outdated and the
|
||||
// Qt version ships qmlplugindump
|
||||
if (::sscanf(pinfo.qtVersionString.toLatin1().constData(), "%d.%d.%d",
|
||||
&majorVersion, &minorVersion, &patchVersion) != 3)
|
||||
majorVersion = minorVersion = patchVersion = -1;
|
||||
|
||||
if (majorVersion > 4 || (majorVersion == 4 && (minorVersion > 8 || (minorVersion == 8
|
||||
&& patchVersion >= 5)))) {
|
||||
m_pluginDumper->loadBuiltinTypes(pinfo);
|
||||
}
|
||||
|
||||
m_pluginDumper->loadBuiltinTypes(pinfo);
|
||||
emit projectInfoUpdated(pinfo);
|
||||
}
|
||||
|
||||
@@ -601,14 +597,16 @@ void ModelManagerInterface::removeProjectInfo(ProjectExplorer::Project *project)
|
||||
|
||||
\note Project pointer will be empty
|
||||
*/
|
||||
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(const QString &path) const
|
||||
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(
|
||||
const QString &path) const
|
||||
{
|
||||
ProjectInfo res;
|
||||
foreach (const ProjectInfo &pInfo, allProjectInfosForPath(path)) {
|
||||
const auto allProjectInfos = allProjectInfosForPath(path);
|
||||
for (const ProjectInfo &pInfo : allProjectInfos) {
|
||||
if (res.qtQmlPath.isEmpty())
|
||||
res.qtQmlPath = pInfo.qtQmlPath;
|
||||
for (int i = 0; i < pInfo.importPaths.size(); ++i)
|
||||
res.importPaths.maybeInsert(pInfo.importPaths.at(i));
|
||||
for (const auto &importPath : pInfo.importPaths)
|
||||
res.importPaths.maybeInsert(importPath);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -616,7 +614,8 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(con
|
||||
/*!
|
||||
Returns list of project infos for \a path
|
||||
*/
|
||||
QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfosForPath(const QString &path) const
|
||||
QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfosForPath(
|
||||
const QString &path) const
|
||||
{
|
||||
QList<ProjectExplorer::Project *> projects;
|
||||
{
|
||||
@@ -628,9 +627,9 @@ QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfos
|
||||
}
|
||||
}
|
||||
QList<ProjectInfo> infos;
|
||||
foreach (ProjectExplorer::Project *project, projects) {
|
||||
for (ProjectExplorer::Project *project : qAsConst(projects)) {
|
||||
ProjectInfo info = projectInfo(project);
|
||||
if (info.isValid())
|
||||
if (!info.project.isNull())
|
||||
infos.append(info);
|
||||
}
|
||||
std::sort(infos.begin(), infos.end(), &pInfoLessThanImports);
|
||||
@@ -644,14 +643,16 @@ bool ModelManagerInterface::isIdle() const
|
||||
}
|
||||
|
||||
void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
|
||||
{ emit documentChangedOnDisk(doc); }
|
||||
{
|
||||
emit documentChangedOnDisk(std::move(doc));
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateQrcFile(const QString &path)
|
||||
{
|
||||
m_qrcCache.updatePath(path, m_qrcContents.value(path));
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateDocument(Document::Ptr doc)
|
||||
void ModelManagerInterface::updateDocument(const Document::Ptr &doc)
|
||||
{
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
@@ -676,27 +677,29 @@ void ModelManagerInterface::updateLibraryInfo(const QString &path, const Library
|
||||
emit libraryInfoUpdated(path, info);
|
||||
}
|
||||
|
||||
static QStringList filesInDirectoryForLanguages(const QString &path, QList<Dialect> languages)
|
||||
static QStringList filesInDirectoryForLanguages(const QString &path,
|
||||
const QList<Dialect> &languages)
|
||||
{
|
||||
const QStringList pattern = ModelManagerInterface::globPatternsForLanguages(languages);
|
||||
QStringList files;
|
||||
|
||||
const QDir dir(path);
|
||||
foreach (const QFileInfo &fi, dir.entryInfoList(pattern, QDir::Files))
|
||||
const auto entries = dir.entryInfoList(pattern, QDir::Files);
|
||||
for (const QFileInfo &fi : entries)
|
||||
files += fi.absoluteFilePath();
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
||||
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
||||
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
||||
{
|
||||
// scan files that could be implicitly imported
|
||||
// it's important we also do this for JS files, otherwise the isEmpty check will fail
|
||||
if (snapshot.documentsInDirectory(doc->path()).isEmpty()) {
|
||||
if (! scannedPaths->contains(doc->path())) {
|
||||
if (!scannedPaths->contains(doc->path())) {
|
||||
*importedFiles += filesInDirectoryForLanguages(doc->path(),
|
||||
doc->language().companionLanguages());
|
||||
doc->language().companionLanguages());
|
||||
scannedPaths->insert(doc->path());
|
||||
}
|
||||
}
|
||||
@@ -706,7 +709,8 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
|
||||
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
||||
{
|
||||
// scan files and directories that are explicitly imported
|
||||
foreach (const ImportInfo &import, doc->bind()->imports()) {
|
||||
const auto imports = doc->bind()->imports();
|
||||
for (const ImportInfo &import : imports) {
|
||||
const QString &importName = import.path();
|
||||
if (import.type() == ImportType::File) {
|
||||
if (! snapshot.document(importName))
|
||||
@@ -714,24 +718,26 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
|
||||
} else if (import.type() == ImportType::Directory) {
|
||||
if (snapshot.documentsInDirectory(importName).isEmpty()) {
|
||||
if (! scannedPaths->contains(importName)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(importName,
|
||||
doc->language().companionLanguages());
|
||||
*importedFiles += filesInDirectoryForLanguages(
|
||||
importName, doc->language().companionLanguages());
|
||||
scannedPaths->insert(importName);
|
||||
}
|
||||
}
|
||||
} else if (import.type() == ImportType::QrcFile) {
|
||||
QStringList importPaths = ModelManagerInterface::instance()->filesAtQrcPath(importName);
|
||||
foreach (const QString &importPath, importPaths) {
|
||||
if (! snapshot.document(importPath))
|
||||
const QStringList importPaths
|
||||
= ModelManagerInterface::instance()->filesAtQrcPath(importName);
|
||||
for (const QString &importPath : importPaths) {
|
||||
if (!snapshot.document(importPath))
|
||||
*importedFiles += importPath;
|
||||
}
|
||||
} else if (import.type() == ImportType::QrcDirectory) {
|
||||
const QMap<QString, QStringList> files = ModelManagerInterface::instance()->filesInQrcPath(importName);
|
||||
for (auto dirContents = files.cbegin(), end = files.cend(); dirContents != end; ++dirContents) {
|
||||
if (ModelManagerInterface::guessLanguageOfFile(dirContents.key()).isQmlLikeOrJsLanguage()) {
|
||||
foreach (const QString &filePath, dirContents.value()) {
|
||||
if (! snapshot.document(filePath))
|
||||
*importedFiles += filePath;
|
||||
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()) {
|
||||
for (const QString &sourceFile : qrc.value()) {
|
||||
if (!snapshot.document(sourceFile))
|
||||
*importedFiles += sourceFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -786,13 +792,14 @@ static bool findNewQmlLibraryInPath(const QString &path,
|
||||
QString(), QString());
|
||||
|
||||
// scan the qml files in the library
|
||||
foreach (const QmlDirParser::Component &component, qmldirParser.components()) {
|
||||
if (! component.fileName.isEmpty()) {
|
||||
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());
|
||||
if (! scannedPaths->contains(path)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(path,
|
||||
Dialect(Dialect::AnyLanguage).companionLanguages());
|
||||
if (!scannedPaths->contains(path)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(path, Dialect(Dialect::AnyLanguage)
|
||||
.companionLanguages());
|
||||
scannedPaths->insert(path);
|
||||
}
|
||||
}
|
||||
@@ -809,8 +816,8 @@ static QString modulePath(const ImportInfo &import, const QStringList &paths)
|
||||
}
|
||||
|
||||
static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
||||
ModelManagerInterface *modelManager,
|
||||
QStringList *importedFiles, QSet<QString> *scannedPaths, QSet<QString> *newLibraries)
|
||||
ModelManagerInterface *modelManager, QStringList *importedFiles,
|
||||
QSet<QString> *scannedPaths, QSet<QString> *newLibraries)
|
||||
{
|
||||
// scan current dir
|
||||
findNewQmlLibraryInPath(doc->path(), snapshot, modelManager,
|
||||
@@ -818,31 +825,31 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
|
||||
|
||||
// scan dir and lib imports
|
||||
const QStringList importPaths = modelManager->importPathsNames();
|
||||
foreach (const ImportInfo &import, doc->bind()->imports()) {
|
||||
if (import.type() == ImportType::Directory) {
|
||||
const QString targetPath = import.path();
|
||||
findNewQmlLibraryInPath(targetPath, snapshot, modelManager,
|
||||
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);
|
||||
}
|
||||
|
||||
if (import.type() == ImportType::Library) {
|
||||
const QString libraryPath = modulePath(import, importPaths);
|
||||
if (libraryPath.isEmpty())
|
||||
continue;
|
||||
findNewQmlLibraryInPath(libraryPath, snapshot, modelManager, importedFiles,
|
||||
scannedPaths, newLibraries, false);
|
||||
break;
|
||||
case ImportType::Library:
|
||||
findNewQmlLibraryInPath(modulePath(import, importPaths), snapshot, modelManager,
|
||||
importedFiles, scannedPaths, newLibraries, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
QSet<QString> &newLibraries,
|
||||
WorkingCopy workingCopy,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk,
|
||||
std::function<bool(qreal)> reportProgress)
|
||||
QSet<QString> &newLibraries,
|
||||
const WorkingCopy &workingCopy,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk,
|
||||
const std::function<bool(qreal)> &reportProgress)
|
||||
{
|
||||
for (int i = 0; i < files.size(); ++i) {
|
||||
if (!reportProgress(qreal(i) / files.size()))
|
||||
@@ -895,11 +902,12 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
QStringList importedFiles;
|
||||
findNewImplicitImports(doc, snapshot, &importedFiles, &scannedPaths);
|
||||
findNewFileImports(doc, snapshot, &importedFiles, &scannedPaths);
|
||||
findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths, &newLibraries);
|
||||
findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths,
|
||||
&newLibraries);
|
||||
|
||||
// add new files to parse list
|
||||
foreach (const QString &file, importedFiles) {
|
||||
if (! files.contains(file))
|
||||
for (const QString &file : qAsConst(importedFiles)) {
|
||||
if (!files.contains(file))
|
||||
files.append(file);
|
||||
}
|
||||
|
||||
@@ -912,9 +920,10 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
||||
class FutureReporter
|
||||
{
|
||||
public:
|
||||
FutureReporter(QFutureInterface<void> &future, int multiplier = 100, int base = 0)
|
||||
:future(future), multiplier(multiplier), base(base)
|
||||
{ }
|
||||
FutureReporter(QFutureInterface<void> &future, int multiplier, int base)
|
||||
: future(future), multiplier(multiplier), base(base)
|
||||
{}
|
||||
|
||||
bool operator()(qreal val)
|
||||
{
|
||||
if (future.isCanceled())
|
||||
@@ -929,37 +938,36 @@ private:
|
||||
};
|
||||
|
||||
void ModelManagerInterface::parse(QFutureInterface<void> &future,
|
||||
WorkingCopy workingCopy,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk)
|
||||
const WorkingCopy &workingCopy,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk)
|
||||
{
|
||||
FutureReporter reporter(future);
|
||||
future.setProgressRange(0, 100);
|
||||
const int progressMax = 100;
|
||||
FutureReporter reporter(future, progressMax, 0);
|
||||
future.setProgressRange(0, progressMax);
|
||||
|
||||
// paths we have scanned for files and added to the files list
|
||||
QSet<QString> scannedPaths;
|
||||
// libraries we've found while scanning imports
|
||||
QSet<QString> newLibraries;
|
||||
parseLoop(scannedPaths, newLibraries, workingCopy, files, modelManager, mainLanguage,
|
||||
parseLoop(scannedPaths, newLibraries, workingCopy, std::move(files), modelManager, mainLanguage,
|
||||
emitDocChangedOnDisk, reporter);
|
||||
future.setProgressValue(100);
|
||||
future.setProgressValue(progressMax);
|
||||
}
|
||||
|
||||
struct ScanItem {
|
||||
QString path;
|
||||
int depth;
|
||||
Dialect language;
|
||||
ScanItem(QString path = QString(), int depth = 0, Dialect language = Dialect::AnyLanguage)
|
||||
: path(path), depth(depth), language(language)
|
||||
{ }
|
||||
int depth = 0;
|
||||
Dialect language = Dialect::AnyLanguage;
|
||||
};
|
||||
|
||||
void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
ModelManagerInterface::WorkingCopy workingCopy,
|
||||
PathsAndLanguages paths, ModelManagerInterface *modelManager,
|
||||
bool emitDocChangedOnDisk, bool libOnly, bool forceRescan)
|
||||
const ModelManagerInterface::WorkingCopy &workingCopy,
|
||||
const PathsAndLanguages &paths,
|
||||
ModelManagerInterface *modelManager,
|
||||
bool emitDocChangedOnDisk, bool libOnly, bool forceRescan)
|
||||
{
|
||||
// paths we have scanned for files and added to the files list
|
||||
QSet<QString> scannedPaths;
|
||||
@@ -974,18 +982,18 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
pathsToScan.reserve(paths.size());
|
||||
{
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
for (int i = 0; i < paths.size(); ++i) {
|
||||
PathAndLanguage pAndL = paths.at(i);
|
||||
QString cPath = QDir::cleanPath(pAndL.path().toString());
|
||||
for (const auto &path : paths) {
|
||||
QString cPath = QDir::cleanPath(path.path().toString());
|
||||
if (!forceRescan && modelManager->m_scannedPaths.contains(cPath))
|
||||
continue;
|
||||
pathsToScan.append(ScanItem(cPath, 0, pAndL.language()));
|
||||
pathsToScan.append({cPath, 0, path.language()});
|
||||
modelManager->m_scannedPaths.insert(cPath);
|
||||
}
|
||||
}
|
||||
const int maxScanDepth = 5;
|
||||
int progressRange = pathsToScan.size() * (1 << (2 + maxScanDepth));
|
||||
int totalWork(progressRange), workDone(0);
|
||||
int totalWork = progressRange;
|
||||
int workDone = 0;
|
||||
future.setProgressRange(0, progressRange); // update max length while iterating?
|
||||
const Snapshot snapshot = modelManager->snapshot();
|
||||
bool isCanceled = future.isCanceled();
|
||||
@@ -997,10 +1005,10 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
QStringList importedFiles;
|
||||
if (forceRescan ||
|
||||
(!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles,
|
||||
&scannedPaths, &newLibraries, true)
|
||||
&scannedPaths, &newLibraries, true)
|
||||
&& !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty())) {
|
||||
importedFiles += filesInDirectoryForLanguages(toScan.path,
|
||||
toScan.language.companionLanguages());
|
||||
toScan.language.companionLanguages());
|
||||
}
|
||||
workDone += 1;
|
||||
future.setProgressValue(progressRange * workDone / totalWork);
|
||||
@@ -1022,8 +1030,8 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
QStringList subDirs(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot));
|
||||
workDone += 1;
|
||||
totalWork += pathBudget / 2 * subDirs.size() - pathBudget * 3 / 4 + 1;
|
||||
foreach (const QString path, subDirs)
|
||||
pathsToScan.append(ScanItem(dir.absoluteFilePath(path), toScan.depth + 1, toScan.language));
|
||||
for (const QString &path : qAsConst(subDirs))
|
||||
pathsToScan.append({dir.absoluteFilePath(path), toScan.depth + 1, toScan.language});
|
||||
} else {
|
||||
workDone += pathBudget * 3 / 4;
|
||||
}
|
||||
@@ -1034,8 +1042,8 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
||||
if (isCanceled) {
|
||||
// assume no work has been done
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
for (int i = 0; i < paths.size(); ++i)
|
||||
modelManager->m_scannedPaths.remove(paths.at(i).path().toString());
|
||||
for (const auto &path : paths)
|
||||
modelManager->m_scannedPaths.remove(path.path().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1068,7 +1076,7 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
|
||||
PathsAndLanguages pathToScan;
|
||||
{
|
||||
QMutexLocker l(&m_mutex);
|
||||
foreach (const PathAndLanguage &importPath, importPaths)
|
||||
for (const PathAndLanguage &importPath : importPaths)
|
||||
if (!m_scannedPaths.contains(importPath.path().toString()))
|
||||
pathToScan.maybeInsert(importPath);
|
||||
}
|
||||
@@ -1091,44 +1099,48 @@ void ModelManagerInterface::updateImportPaths()
|
||||
PathsAndLanguages allImportPaths;
|
||||
QmlLanguageBundles activeBundles;
|
||||
QmlLanguageBundles extendedBundles;
|
||||
for (auto pInfoIter = m_projects.cbegin(), end = m_projects.cend(); pInfoIter != end; ++pInfoIter) {
|
||||
const PathsAndLanguages &iPaths = pInfoIter.value().importPaths;
|
||||
for (int i = 0; i < iPaths.size(); ++i) {
|
||||
PathAndLanguage pAndL = iPaths.at(i);
|
||||
const QString canonicalPath = pAndL.path().toFileInfo().canonicalFilePath();
|
||||
if (!canonicalPath.isEmpty())
|
||||
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
|
||||
for (const auto &importPath : pInfo.importPaths) {
|
||||
const QString canonicalPath = importPath.path().toFileInfo().canonicalFilePath();
|
||||
if (!canonicalPath.isEmpty()) {
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(canonicalPath),
|
||||
pAndL.language());
|
||||
importPath.language());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto vCtxsIter = m_defaultVContexts.cbegin(), end = m_defaultVContexts.cend();
|
||||
vCtxsIter != end; ++ vCtxsIter) {
|
||||
foreach (const QString &path, vCtxsIter.value().paths)
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(path), vCtxsIter.value().language);
|
||||
|
||||
for (const ViewerContext &vContext : qAsConst(m_defaultVContexts)) {
|
||||
for (const QString &path : vContext.paths)
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(path), vContext.language);
|
||||
}
|
||||
for (auto pInfoIter = m_projects.cbegin(), end = m_projects.cend(); pInfoIter != end; ++pInfoIter) {
|
||||
activeBundles.mergeLanguageBundles(pInfoIter.value().activeBundle);
|
||||
foreach (Dialect l, pInfoIter.value().activeBundle.languages()) {
|
||||
foreach (const QString &path, pInfoIter.value().activeBundle.bundleForLanguage(l)
|
||||
.searchPaths().stringList()) {
|
||||
|
||||
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
|
||||
activeBundles.mergeLanguageBundles(pInfo.activeBundle);
|
||||
const auto languages = pInfo.activeBundle.languages();
|
||||
for (Dialect l : languages) {
|
||||
const auto paths = pInfo.activeBundle.bundleForLanguage(l).searchPaths().stringList();
|
||||
for (const QString &path : paths) {
|
||||
const QString canonicalPath = QFileInfo(path).canonicalFilePath();
|
||||
if (!canonicalPath.isEmpty())
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(canonicalPath), l);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto pInfoIter = m_projects.cbegin(), end = m_projects.cend(); pInfoIter != end; ++pInfoIter) {
|
||||
QString pathAtt = pInfoIter.value().qtQmlPath;
|
||||
if (!pathAtt.isEmpty())
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(pathAtt), Dialect::QmlQtQuick2);
|
||||
|
||||
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
|
||||
if (!pInfo.qtQmlPath.isEmpty()) {
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(pInfo.qtQmlPath),
|
||||
Dialect::QmlQtQuick2);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QString pathAtt = defaultProjectInfo().qtQmlPath;
|
||||
const QString pathAtt = defaultProjectInfo().qtQmlPath;
|
||||
if (!pathAtt.isEmpty())
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(pathAtt), Dialect::QmlQtQuick2);
|
||||
}
|
||||
|
||||
foreach (const QString &path, m_defaultImportPaths)
|
||||
for (const QString &path : qAsConst(m_defaultImportPaths))
|
||||
allImportPaths.maybeInsert(Utils::FilePath::fromString(path), Dialect::Qml);
|
||||
allImportPaths.compact();
|
||||
|
||||
@@ -1145,7 +1157,7 @@ void ModelManagerInterface::updateImportPaths()
|
||||
QStringList importedFiles;
|
||||
QSet<QString> scannedPaths;
|
||||
QSet<QString> newLibraries;
|
||||
foreach (const Document::Ptr &doc, snapshot)
|
||||
for (const Document::Ptr &doc : qAsConst(snapshot))
|
||||
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
|
||||
|
||||
updateSourceFiles(importedFiles, true);
|
||||
@@ -1230,13 +1242,14 @@ bool rescanExports(const QString &fileName, FindExportedCppTypes &finder,
|
||||
} else {
|
||||
ModelManagerInterface::CppData &data = newData[fileName];
|
||||
if (!hasNewInfo && (data.exportedTypes.size() != exported.size()
|
||||
|| data.contextProperties != contextProperties))
|
||||
|| data.contextProperties != contextProperties)) {
|
||||
hasNewInfo = true;
|
||||
}
|
||||
if (!hasNewInfo) {
|
||||
QHash<QString, QByteArray> newFingerprints;
|
||||
foreach (LanguageUtils::FakeMetaObject::ConstPtr newType, exported)
|
||||
for (const auto &newType : qAsConst(exported))
|
||||
newFingerprints[newType->className()]=newType->fingerprint();
|
||||
foreach (LanguageUtils::FakeMetaObject::ConstPtr oldType, data.exportedTypes) {
|
||||
for (const auto &oldType : qAsConst(data.exportedTypes)) {
|
||||
if (newFingerprints.value(oldType->className()) != oldType->fingerprint()) {
|
||||
hasNewInfo = true;
|
||||
break;
|
||||
@@ -1249,16 +1262,16 @@ bool rescanExports(const QString &fileName, FindExportedCppTypes &finder,
|
||||
return hasNewInfo;
|
||||
}
|
||||
|
||||
void ModelManagerInterface::updateCppQmlTypes(QFutureInterface<void> &futureInterface,
|
||||
ModelManagerInterface *qmlModelManager,
|
||||
CPlusPlus::Snapshot snapshot,
|
||||
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > documents)
|
||||
void ModelManagerInterface::updateCppQmlTypes(
|
||||
QFutureInterface<void> &futureInterface, ModelManagerInterface *qmlModelManager,
|
||||
const CPlusPlus::Snapshot &snapshot,
|
||||
const QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> &documents)
|
||||
{
|
||||
futureInterface.setProgressRange(0, documents.size());
|
||||
futureInterface.setProgressValue(0);
|
||||
|
||||
CppDataHash newData;
|
||||
QHash<QString, QList<CPlusPlus::Document::Ptr> > newDeclarations;
|
||||
QHash<QString, QList<CPlusPlus::Document::Ptr>> newDeclarations;
|
||||
{
|
||||
QMutexLocker locker(&qmlModelManager->m_cppDataMutex);
|
||||
newData = qmlModelManager->m_cppDataHash;
|
||||
@@ -1268,8 +1281,8 @@ void ModelManagerInterface::updateCppQmlTypes(QFutureInterface<void> &futureInte
|
||||
FindExportedCppTypes finder(snapshot);
|
||||
|
||||
bool hasNewInfo = false;
|
||||
typedef QPair<CPlusPlus::Document::Ptr, bool> DocScanPair;
|
||||
foreach (const DocScanPair &pair, documents) {
|
||||
using DocScanPair = QPair<CPlusPlus::Document::Ptr, bool>;
|
||||
for (const DocScanPair &pair : documents) {
|
||||
if (futureInterface.isCanceled())
|
||||
return;
|
||||
futureInterface.setProgressValue(futureInterface.progressValue() + 1);
|
||||
@@ -1279,7 +1292,8 @@ void ModelManagerInterface::updateCppQmlTypes(QFutureInterface<void> &futureInte
|
||||
const QString fileName = doc->fileName();
|
||||
if (!scan) {
|
||||
hasNewInfo = newData.remove(fileName) > 0 || hasNewInfo;
|
||||
foreach (const CPlusPlus::Document::Ptr &savedDoc, newDeclarations.value(fileName)) {
|
||||
const auto savedDocs = newDeclarations.value(fileName);
|
||||
for (const CPlusPlus::Document::Ptr &savedDoc : savedDocs) {
|
||||
finder(savedDoc);
|
||||
hasNewInfo = rescanExports(savedDoc->fileName(), finder, newData) || hasNewInfo;
|
||||
}
|
||||
@@ -1288,14 +1302,13 @@ void ModelManagerInterface::updateCppQmlTypes(QFutureInterface<void> &futureInte
|
||||
|
||||
for (auto it = newDeclarations.begin(), end = newDeclarations.end(); it != end;) {
|
||||
for (auto docIt = it->begin(), endDocIt = it->end(); docIt != endDocIt;) {
|
||||
CPlusPlus::Document::Ptr &savedDoc = *docIt;
|
||||
const CPlusPlus::Document::Ptr &savedDoc = *docIt;
|
||||
if (savedDoc->fileName() == fileName) {
|
||||
savedDoc->releaseSourceAndAST();
|
||||
it->erase(docIt);
|
||||
break;
|
||||
} else {
|
||||
++docIt;
|
||||
}
|
||||
++docIt;
|
||||
}
|
||||
if (it->isEmpty())
|
||||
it = newDeclarations.erase(it);
|
||||
@@ -1303,7 +1316,8 @@ void ModelManagerInterface::updateCppQmlTypes(QFutureInterface<void> &futureInte
|
||||
++it;
|
||||
}
|
||||
|
||||
foreach (const QString &declarationFile, finder(doc)) {
|
||||
const auto found = finder(doc);
|
||||
for (const QString &declarationFile : found) {
|
||||
newDeclarations[declarationFile].append(doc);
|
||||
doc->keepSourceAndAST(); // keep for later reparsing when dependent doc changes
|
||||
}
|
||||
@@ -1329,7 +1343,7 @@ ModelManagerInterface::CppDataHash ModelManagerInterface::cppData() const
|
||||
LibraryInfo ModelManagerInterface::builtins(const Document::Ptr &doc) const
|
||||
{
|
||||
const ProjectInfo info = projectInfoForPath(doc->fileName());
|
||||
if (info.isValid() && !info.qtQmlPath.isEmpty())
|
||||
if (!info.project.isNull() && !info.qtQmlPath.isEmpty())
|
||||
return m_validSnapshot.libraryInfo(info.qtQmlPath);
|
||||
return LibraryInfo();
|
||||
}
|
||||
@@ -1360,7 +1374,7 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
Q_FALLTHROUGH();
|
||||
case ViewerContext::AddAllPaths:
|
||||
{
|
||||
foreach (const QString &path, defaultVCtx.paths)
|
||||
for (const QString &path : qAsConst(defaultVCtx.paths))
|
||||
maybeAddPath(res, path);
|
||||
switch (res.language.dialect()) {
|
||||
case Dialect::AnyLanguage:
|
||||
@@ -1379,14 +1393,16 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
}
|
||||
std::sort(allProjects.begin(), allProjects.end(), &pInfoLessThanImports);
|
||||
QList<Dialect> languages = res.language.companionLanguages();
|
||||
foreach (const ProjectInfo &pInfo, allProjects) {
|
||||
for (int i = 0; i< pInfo.importPaths.size(); ++i) {
|
||||
PathAndLanguage pAndL = pInfo.importPaths.at(i);
|
||||
if (languages.contains(pAndL.language()) || pAndL.language().companionLanguages().contains(res.language))
|
||||
maybeAddPath(res, pAndL.path().toString());
|
||||
for (const ProjectInfo &pInfo : qAsConst(allProjects)) {
|
||||
for (const auto &importPath : pInfo.importPaths) {
|
||||
if (languages.contains(importPath.language())
|
||||
|| importPath.language().companionLanguages().contains(res.language)) {
|
||||
maybeAddPath(res, importPath.path().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (const QString &path, environmentImportPaths())
|
||||
const auto environmentPaths = environmentImportPaths();
|
||||
for (const QString &path : environmentPaths)
|
||||
maybeAddPath(res, path);
|
||||
break;
|
||||
}
|
||||
@@ -1404,13 +1420,14 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
||||
res.selectors.append(defaultVCtx.selectors);
|
||||
Q_FALLTHROUGH();
|
||||
case ViewerContext::AddDefaultPaths:
|
||||
foreach (const QString &path, defaultVCtx.paths)
|
||||
for (const QString &path : qAsConst(defaultVCtx.paths))
|
||||
maybeAddPath(res, path);
|
||||
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml)
|
||||
maybeAddPath(res, info.qtQmlPath);
|
||||
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
||||
|| res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui) {
|
||||
foreach (const QString &path, environmentImportPaths())
|
||||
const auto environemntPaths = environmentImportPaths();
|
||||
for (const QString &path : environemntPaths)
|
||||
maybeAddPath(res, path);
|
||||
}
|
||||
break;
|
||||
@@ -1437,10 +1454,7 @@ ViewerContext ModelManagerInterface::defaultVContext(Dialect language,
|
||||
defaultCtx = m_defaultVContexts.value(language);
|
||||
}
|
||||
defaultCtx.language = language;
|
||||
if (autoComplete)
|
||||
return completeVContext(defaultCtx, doc);
|
||||
else
|
||||
return defaultCtx;
|
||||
return autoComplete ? completeVContext(defaultCtx, doc) : defaultCtx;
|
||||
}
|
||||
|
||||
ModelManagerInterface::ProjectInfo ModelManagerInterface::defaultProjectInfo() const
|
||||
@@ -1463,7 +1477,7 @@ void ModelManagerInterface::setDefaultVContext(const ViewerContext &vContext)
|
||||
|
||||
void ModelManagerInterface::joinAllThreads()
|
||||
{
|
||||
foreach (QFuture<void> future, m_futures)
|
||||
for (QFuture<void> &future : m_futures)
|
||||
future.waitForFinished();
|
||||
m_futures.clear();
|
||||
}
|
||||
@@ -1489,7 +1503,7 @@ void ModelManagerInterface::resetCodeModel()
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
// find all documents currently in the code model
|
||||
foreach (Document::Ptr doc, m_validSnapshot)
|
||||
for (const Document::Ptr &doc : qAsConst(m_validSnapshot))
|
||||
documents.append(doc->fileName());
|
||||
|
||||
// reset the snapshot
|
||||
|
||||
@@ -49,38 +49,22 @@ namespace QmlJS {
|
||||
class Snapshot;
|
||||
class PluginDumper;
|
||||
|
||||
class QMLJS_EXPORT ModelManagerInterface: public QObject
|
||||
class QMLJS_EXPORT ModelManagerInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ModelManagerInterface)
|
||||
|
||||
public:
|
||||
ModelManagerInterface(ModelManagerInterface &&) = delete;
|
||||
ModelManagerInterface &operator=(ModelManagerInterface &&) = delete;
|
||||
|
||||
enum QrcResourceSelector {
|
||||
ActiveQrcResources,
|
||||
AllQrcResources
|
||||
};
|
||||
|
||||
class ProjectInfo
|
||||
struct ProjectInfo
|
||||
{
|
||||
public:
|
||||
ProjectInfo()
|
||||
: tryQmlDump(false), qmlDumpHasRelocatableFlag(true)
|
||||
{ }
|
||||
|
||||
ProjectInfo(QPointer<ProjectExplorer::Project> project)
|
||||
: project(project)
|
||||
, tryQmlDump(false), qmlDumpHasRelocatableFlag(true)
|
||||
{ }
|
||||
|
||||
explicit operator bool() const
|
||||
{ return ! project.isNull(); }
|
||||
|
||||
bool isValid() const
|
||||
{ return ! project.isNull(); }
|
||||
|
||||
bool isNull() const
|
||||
{ return project.isNull(); }
|
||||
|
||||
public: // attributes
|
||||
QPointer<ProjectExplorer::Project> project;
|
||||
QStringList sourceFiles;
|
||||
PathsAndLanguages importPaths;
|
||||
@@ -89,8 +73,8 @@ public:
|
||||
QHash<QString, QString> resourceFileContents;
|
||||
|
||||
// whether trying to run qmldump makes sense
|
||||
bool tryQmlDump;
|
||||
bool qmlDumpHasRelocatableFlag;
|
||||
bool tryQmlDump = false;
|
||||
bool qmlDumpHasRelocatableFlag = true;
|
||||
QString qmlDumpPath;
|
||||
::Utils::Environment qmlDumpEnvironment;
|
||||
|
||||
@@ -103,42 +87,41 @@ public:
|
||||
class WorkingCopy
|
||||
{
|
||||
public:
|
||||
typedef QHash<QString, QPair<QString, int> > Table;
|
||||
using Table = QHash<QString, QPair<QString, int>>;
|
||||
|
||||
void insert(const QString &fileName, const QString &source, int revision = 0)
|
||||
{ _elements.insert(fileName, {source, revision}); }
|
||||
{ m_elements.insert(fileName, {source, revision}); }
|
||||
|
||||
bool contains(const QString &fileName) const
|
||||
{ return _elements.contains(fileName); }
|
||||
{ return m_elements.contains(fileName); }
|
||||
|
||||
QString source(const QString &fileName) const
|
||||
{ return _elements.value(fileName).first; }
|
||||
{ return m_elements.value(fileName).first; }
|
||||
|
||||
QPair<QString, int> get(const QString &fileName) const
|
||||
{ return _elements.value(fileName); }
|
||||
{ return m_elements.value(fileName); }
|
||||
|
||||
Table all() const
|
||||
{ return _elements; }
|
||||
{ return m_elements; }
|
||||
|
||||
private:
|
||||
Table _elements;
|
||||
Table m_elements;
|
||||
};
|
||||
|
||||
class CppData
|
||||
struct CppData
|
||||
{
|
||||
public:
|
||||
QList<LanguageUtils::FakeMetaObject::ConstPtr> exportedTypes;
|
||||
QHash<QString, QString> contextProperties;
|
||||
};
|
||||
|
||||
typedef QHash<QString, CppData> CppDataHash;
|
||||
using CppDataHash = QHash<QString, CppData>;
|
||||
|
||||
public:
|
||||
ModelManagerInterface(QObject *parent = nullptr);
|
||||
~ModelManagerInterface() override;
|
||||
|
||||
static Dialect guessLanguageOfFile(const QString &fileName);
|
||||
static QStringList globPatternsForLanguages(const QList<Dialect> languages);
|
||||
static QStringList globPatternsForLanguages(const QList<Dialect> &languages);
|
||||
static ModelManagerInterface *instance();
|
||||
static void writeWarning(const QString &msg);
|
||||
static WorkingCopy workingCopy();
|
||||
@@ -157,18 +140,18 @@ public:
|
||||
QStringList filesAtQrcPath(const QString &path, const QLocale *locale = nullptr,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
QrcResourceSelector resources = AllQrcResources);
|
||||
QMap<QString,QStringList> filesInQrcPath(const QString &path,
|
||||
const QLocale *locale = nullptr,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
bool addDirs = false,
|
||||
QrcResourceSelector resources = AllQrcResources);
|
||||
QMap<QString, QStringList> filesInQrcPath(const QString &path,
|
||||
const QLocale *locale = nullptr,
|
||||
ProjectExplorer::Project *project = nullptr,
|
||||
bool addDirs = false,
|
||||
QrcResourceSelector resources = AllQrcResources);
|
||||
|
||||
QList<ProjectInfo> projectInfos() const;
|
||||
ProjectInfo projectInfo(ProjectExplorer::Project *project,
|
||||
const ModelManagerInterface::ProjectInfo &defaultValue = ProjectInfo()) const;
|
||||
bool containsProject(ProjectExplorer::Project *project) const;
|
||||
ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
|
||||
void updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p);
|
||||
|
||||
void updateDocument(QmlJS::Document::Ptr doc);
|
||||
void updateDocument(const QmlJS::Document::Ptr& doc);
|
||||
void updateLibraryInfo(const QString &path, const QmlJS::LibraryInfo &info);
|
||||
void emitDocumentChangedOnDisk(QmlJS::Document::Ptr doc);
|
||||
void updateQrcFile(const QString &path);
|
||||
@@ -199,11 +182,10 @@ public:
|
||||
void joinAllThreads();
|
||||
|
||||
QmlJS::Document::Ptr ensuredGetDocumentForPath(const QString &filePath);
|
||||
static void importScan(QFutureInterface<void> &future,
|
||||
WorkingCopy workingCopyInternal,
|
||||
PathsAndLanguages paths,
|
||||
ModelManagerInterface *modelManager,
|
||||
bool emitDocChangedOnDisk, bool libOnly = true, bool forceRescan = false);
|
||||
static void importScan(QFutureInterface<void> &future, const WorkingCopy& workingCopyInternal,
|
||||
const PathsAndLanguages& paths, ModelManagerInterface *modelManager,
|
||||
bool emitDocChangedOnDisk, bool libOnly = true,
|
||||
bool forceRescan = false);
|
||||
|
||||
virtual void resetCodeModel();
|
||||
void removeProjectInfo(ProjectExplorer::Project *project);
|
||||
@@ -225,25 +207,27 @@ protected:
|
||||
virtual QHash<QString,Dialect> languageForSuffix() const;
|
||||
virtual void writeMessageInternal(const QString &msg) const;
|
||||
virtual WorkingCopy workingCopyInternal() const;
|
||||
virtual void addTaskInternal(QFuture<void> result, const QString &msg, const char *taskId) const;
|
||||
virtual void addTaskInternal(const QFuture<void> &result, const QString &msg,
|
||||
const char *taskId) const;
|
||||
|
||||
QFuture<void> refreshSourceFiles(const QStringList &sourceFiles,
|
||||
bool emitDocumentOnDiskChanged);
|
||||
|
||||
static void parseLoop(QSet<QString> &scannedPaths, QSet<QString> &newLibraries,
|
||||
WorkingCopy workingCopyInternal, QStringList files, ModelManagerInterface *modelManager,
|
||||
const WorkingCopy &workingCopyInternal, QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
QmlJS::Dialect mainLanguage, bool emitDocChangedOnDisk,
|
||||
std::function<bool (qreal)> reportProgress);
|
||||
const std::function<bool(qreal)> &reportProgress);
|
||||
static void parse(QFutureInterface<void> &future,
|
||||
WorkingCopy workingCopyInternal,
|
||||
const WorkingCopy &workingCopyInternal,
|
||||
QStringList files,
|
||||
ModelManagerInterface *modelManager,
|
||||
QmlJS::Dialect mainLanguage,
|
||||
bool emitDocChangedOnDisk);
|
||||
static void updateCppQmlTypes(QFutureInterface<void> &futureInterface,
|
||||
ModelManagerInterface *qmlModelManager,
|
||||
CPlusPlus::Snapshot snapshot,
|
||||
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > documents);
|
||||
static void updateCppQmlTypes(
|
||||
QFutureInterface<void> &futureInterface, ModelManagerInterface *qmlModelManager,
|
||||
const CPlusPlus::Snapshot &snapshot,
|
||||
const QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> &documents);
|
||||
|
||||
void maybeScan(const PathsAndLanguages &importPaths);
|
||||
void updateImportPaths();
|
||||
@@ -254,7 +238,7 @@ private:
|
||||
void cleanupFutures();
|
||||
void iterateQrcFiles(ProjectExplorer::Project *project,
|
||||
QrcResourceSelector resources,
|
||||
std::function<void(Utils::QrcParser::ConstPtr)> callback);
|
||||
const std::function<void(Utils::QrcParser::ConstPtr)> &callback);
|
||||
|
||||
mutable QMutex m_mutex;
|
||||
QmlJS::Snapshot m_validSnapshot;
|
||||
@@ -269,13 +253,13 @@ private:
|
||||
|
||||
QTimer *m_updateCppQmlTypesTimer = nullptr;
|
||||
QTimer *m_asyncResetTimer = nullptr;
|
||||
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > m_queuedCppDocuments;
|
||||
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> m_queuedCppDocuments;
|
||||
QFuture<void> m_cppQmlTypesUpdater;
|
||||
Utils::QrcCache m_qrcCache;
|
||||
QHash<QString, QString> m_qrcContents;
|
||||
|
||||
CppDataHash m_cppDataHash;
|
||||
QHash<QString, QList<CPlusPlus::Document::Ptr> > m_cppDeclarationFiles;
|
||||
QHash<QString, QList<CPlusPlus::Document::Ptr>> m_cppDeclarationFiles;
|
||||
mutable QMutex m_cppDataMutex;
|
||||
|
||||
// project integration
|
||||
|
||||
Reference in New Issue
Block a user