2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-09-04 16:51:11 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
#include "qmljsbind.h"
|
|
|
|
#include "qmljsconstants.h"
|
|
|
|
#include "qmljsfindexportedcpptypes.h"
|
|
|
|
#include "qmljsinterpreter.h"
|
2010-06-09 15:56:03 +02:00
|
|
|
#include "qmljsmodelmanagerinterface.h"
|
2014-01-23 14:28:31 +01:00
|
|
|
#include "qmljsplugindumper.h"
|
|
|
|
#include "qmljstypedescriptionreader.h"
|
2014-07-22 19:06:44 +02:00
|
|
|
#include "qmljsdialect.h"
|
2015-03-04 16:46:23 +01:00
|
|
|
#include "qmljsviewercontext.h"
|
2017-09-28 16:24:13 +02:00
|
|
|
#include "qmljsutils.h"
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
#include <cplusplus/cppmodelmanagerbase.h>
|
2016-08-03 23:29:58 +03:00
|
|
|
#include <utils/algorithm.h>
|
2014-01-23 14:28:31 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2014-04-11 23:07:52 +02:00
|
|
|
#include <utils/runextensions.h>
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
#include <QDir>
|
2020-03-26 12:17:03 +01:00
|
|
|
#include <QDirIterator>
|
2014-01-23 14:28:31 +01:00
|
|
|
#include <QFile>
|
2014-01-22 18:38:45 +01:00
|
|
|
#include <QFileInfo>
|
2016-01-27 22:36:48 +02:00
|
|
|
#include <QMetaObject>
|
2014-01-23 14:28:31 +01:00
|
|
|
#include <QRegExp>
|
|
|
|
#include <QTextDocument>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QtAlgorithms>
|
2014-04-11 23:07:52 +02:00
|
|
|
#include <QLibraryInfo>
|
2014-01-23 14:28:31 +01:00
|
|
|
|
2019-02-07 17:22:39 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
namespace QmlJS {
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2018-10-12 09:33:30 +03:00
|
|
|
QMLJS_EXPORT Q_LOGGING_CATEGORY(qmljsLog, "qtc.qmljs.common", QtWarningMsg)
|
2014-05-27 10:39:50 +02:00
|
|
|
|
2011-08-30 09:19:56 +02:00
|
|
|
/*!
|
|
|
|
\class QmlJS::ModelManagerInterface
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The ModelManagerInterface class acts as an interface to the
|
|
|
|
global state of the QmlJS code model.
|
2011-08-30 09:19:56 +02:00
|
|
|
\sa QmlJS::Document QmlJS::Snapshot QmlJSTools::Internal::ModelManager
|
|
|
|
|
|
|
|
The ModelManagerInterface is an interface for global state and actions in
|
|
|
|
the QmlJS code model. It is implemented by \l{QmlJSTools::Internal::ModelManager}
|
|
|
|
and the instance can be accessed through ModelManagerInterface::instance().
|
|
|
|
|
|
|
|
One of its primary concerns is to keep the Snapshots it
|
|
|
|
maintains up to date by parsing documents and finding QML modules.
|
|
|
|
|
|
|
|
It has a Snapshot that contains only valid Documents,
|
|
|
|
accessible through ModelManagerInterface::snapshot() and a Snapshot with
|
|
|
|
potentially more recent, but invalid documents that is exposed through
|
|
|
|
ModelManagerInterface::newestSnapshot().
|
|
|
|
*/
|
|
|
|
|
2019-01-16 14:28:59 +01:00
|
|
|
static ModelManagerInterface *g_instance = nullptr;
|
2019-10-23 14:03:13 +02:00
|
|
|
static const char *qtQuickUISuffix = "ui.qml";
|
2014-10-13 16:46:30 +02:00
|
|
|
|
2019-10-23 09:14:58 +02:00
|
|
|
static void maybeAddPath(ViewerContext &context, const QString &path)
|
|
|
|
{
|
|
|
|
if (!path.isEmpty() && !context.paths.contains(path))
|
|
|
|
context.paths.append(path);
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
static QStringList environmentImportPaths()
|
|
|
|
{
|
|
|
|
QStringList paths;
|
|
|
|
|
2019-01-18 20:28:55 +01:00
|
|
|
const QStringList importPaths = QString::fromLocal8Bit(qgetenv("QML_IMPORT_PATH")).split(
|
|
|
|
Utils::HostOsInfo::pathListSeparator(), QString::SkipEmptyParts);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
2019-01-18 20:28:55 +01:00
|
|
|
for (const QString &path : importPaths) {
|
|
|
|
const QString canonicalPath = QDir(path).canonicalPath();
|
2014-01-23 14:28:31 +01:00
|
|
|
if (!canonicalPath.isEmpty() && !paths.contains(canonicalPath))
|
|
|
|
paths.append(canonicalPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
ModelManagerInterface::ModelManagerInterface(QObject *parent)
|
2014-01-23 14:28:31 +01:00
|
|
|
: QObject(parent),
|
2019-01-18 20:28:55 +01:00
|
|
|
m_defaultImportPaths(environmentImportPaths()),
|
2014-01-23 14:28:31 +01:00
|
|
|
m_pluginDumper(new PluginDumper(this))
|
2010-06-09 15:56:03 +02:00
|
|
|
{
|
2019-01-18 20:28:55 +01:00
|
|
|
m_indexerDisabled = qEnvironmentVariableIsSet("QTC_NO_CODE_INDEXER");
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
m_updateCppQmlTypesTimer = new QTimer(this);
|
2019-10-23 14:03:13 +02:00
|
|
|
const int second = 1000;
|
|
|
|
m_updateCppQmlTypesTimer->setInterval(second);
|
2014-01-23 14:28:31 +01:00
|
|
|
m_updateCppQmlTypesTimer->setSingleShot(true);
|
2016-06-27 22:25:11 +03:00
|
|
|
connect(m_updateCppQmlTypesTimer, &QTimer::timeout,
|
|
|
|
this, &ModelManagerInterface::startCppQmlTypeUpdate);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
m_asyncResetTimer = new QTimer(this);
|
2019-10-23 14:03:13 +02:00
|
|
|
const int fifteenSeconds = 15000;
|
|
|
|
m_asyncResetTimer->setInterval(fifteenSeconds);
|
2014-01-23 14:28:31 +01:00
|
|
|
m_asyncResetTimer->setSingleShot(true);
|
2016-06-27 22:25:11 +03:00
|
|
|
connect(m_asyncResetTimer, &QTimer::timeout, this, &ModelManagerInterface::resetCodeModel);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
qRegisterMetaType<QmlJS::Document::Ptr>("QmlJS::Document::Ptr");
|
|
|
|
qRegisterMetaType<QmlJS::LibraryInfo>("QmlJS::LibraryInfo");
|
2014-07-22 19:06:44 +02:00
|
|
|
qRegisterMetaType<QmlJS::Dialect>("QmlJS::Dialect");
|
|
|
|
qRegisterMetaType<QmlJS::PathAndLanguage>("QmlJS::PathAndLanguage");
|
|
|
|
qRegisterMetaType<QmlJS::PathsAndLanguages>("QmlJS::PathsAndLanguages");
|
2014-01-23 14:28:31 +01:00
|
|
|
|
2014-09-02 14:42:51 +02:00
|
|
|
m_defaultProjectInfo.qtQmlPath = QFileInfo(
|
|
|
|
QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)).canonicalFilePath();
|
2014-06-30 11:56:28 +02:00
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
updateImportPaths();
|
|
|
|
|
2010-07-08 14:38:47 +02:00
|
|
|
Q_ASSERT(! g_instance);
|
|
|
|
g_instance = this;
|
2010-01-14 16:22:43 +01:00
|
|
|
}
|
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
ModelManagerInterface::~ModelManagerInterface()
|
2009-09-04 16:51:11 +02:00
|
|
|
{
|
2014-02-13 11:11:40 +01:00
|
|
|
m_cppQmlTypesUpdater.cancel();
|
|
|
|
m_cppQmlTypesUpdater.waitForFinished();
|
2010-11-11 10:05:05 +01:00
|
|
|
Q_ASSERT(g_instance == this);
|
2019-01-16 14:28:59 +01:00
|
|
|
g_instance = nullptr;
|
2010-06-09 15:56:03 +02:00
|
|
|
}
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
static QHash<QString, Dialect> defaultLanguageMapping()
|
2014-01-22 18:38:45 +01:00
|
|
|
{
|
2016-06-20 13:42:26 +02:00
|
|
|
static QHash<QString, Dialect> res{
|
|
|
|
{QLatin1String("js"), Dialect::JavaScript},
|
|
|
|
{QLatin1String("qml"), Dialect::Qml},
|
|
|
|
{QLatin1String("qmltypes"), Dialect::QmlTypeInfo},
|
|
|
|
{QLatin1String("qmlproject"), Dialect::QmlProject},
|
|
|
|
{QLatin1String("json"), Dialect::Json},
|
|
|
|
{QLatin1String("qbs"), Dialect::QmlQbs},
|
|
|
|
{QLatin1String(qtQuickUISuffix), Dialect::QmlQtQuick2Ui}
|
|
|
|
};
|
2014-01-22 18:38:45 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
|
2014-01-22 18:38:45 +01:00
|
|
|
{
|
2014-07-22 19:06:44 +02:00
|
|
|
QHash<QString, Dialect> lMapping;
|
2014-01-22 18:38:45 +01:00
|
|
|
if (instance())
|
|
|
|
lMapping = instance()->languageForSuffix();
|
|
|
|
else
|
|
|
|
lMapping = defaultLanguageMapping();
|
|
|
|
const QFileInfo info(fileName);
|
2014-10-13 16:46:30 +02:00
|
|
|
QString fileSuffix = info.suffix();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I was reluctant to use complete suffix in all cases, because it is a huge
|
|
|
|
* change in behaivour. But in case of .qml this should be safe.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (fileSuffix == QLatin1String("qml"))
|
|
|
|
fileSuffix = info.completeSuffix();
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
return lMapping.value(fileSuffix, Dialect::NoLanguage);
|
2014-01-22 18:38:45 +01:00
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
QStringList ModelManagerInterface::globPatternsForLanguages(const QList<Dialect> &languages)
|
2014-01-22 18:38:45 +01:00
|
|
|
{
|
|
|
|
QStringList patterns;
|
2019-07-24 13:43:54 +02:00
|
|
|
const QHash<QString, Dialect> lMapping =
|
|
|
|
instance() ? instance()->languageForSuffix() : defaultLanguageMapping();
|
|
|
|
for (auto i = lMapping.cbegin(), end = lMapping.cend(); i != end; ++i) {
|
2014-01-22 18:38:45 +01:00
|
|
|
if (languages.contains(i.value()))
|
|
|
|
patterns << QLatin1String("*.") + i.key();
|
|
|
|
}
|
|
|
|
return patterns;
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:38:47 +02:00
|
|
|
ModelManagerInterface *ModelManagerInterface::instance()
|
|
|
|
{
|
|
|
|
return g_instance;
|
|
|
|
}
|
2012-12-06 17:20:58 +01:00
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
void ModelManagerInterface::writeWarning(const QString &msg)
|
|
|
|
{
|
|
|
|
if (ModelManagerInterface *i = instance())
|
|
|
|
i->writeMessageInternal(msg);
|
|
|
|
else
|
2014-05-27 10:39:50 +02:00
|
|
|
qCWarning(qmljsLog) << msg;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ModelManagerInterface::WorkingCopy ModelManagerInterface::workingCopy()
|
|
|
|
{
|
|
|
|
if (ModelManagerInterface *i = instance())
|
|
|
|
return i->workingCopyInternal();
|
|
|
|
return WorkingCopy();
|
|
|
|
}
|
|
|
|
|
2014-04-29 16:39:16 +02:00
|
|
|
void ModelManagerInterface::activateScan()
|
|
|
|
{
|
|
|
|
if (!m_shouldScanImports) {
|
|
|
|
m_shouldScanImports = true;
|
|
|
|
updateImportPaths();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
QHash<QString, Dialect> ModelManagerInterface::languageForSuffix() const
|
2014-01-22 18:38:45 +01:00
|
|
|
{
|
|
|
|
return defaultLanguageMapping();
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
void ModelManagerInterface::writeMessageInternal(const QString &msg) const
|
|
|
|
{
|
2014-07-22 17:05:28 +02:00
|
|
|
qCDebug(qmljsLog) << msg;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ModelManagerInterface::WorkingCopy ModelManagerInterface::workingCopyInternal() const
|
|
|
|
{
|
|
|
|
ModelManagerInterface::WorkingCopy res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
void ModelManagerInterface::addTaskInternal(const QFuture<void> &result, const QString &msg,
|
2014-01-23 14:28:31 +01:00
|
|
|
const char *taskId) const
|
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(result)
|
2014-05-27 10:39:50 +02:00
|
|
|
qCDebug(qmljsLog) << "started " << taskId << " " << msg;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::loadQmlTypeDescriptionsInternal(const QString &resourcePath)
|
|
|
|
{
|
|
|
|
const QDir typeFileDir(resourcePath + QLatin1String("/qml-type-descriptions"));
|
2017-02-07 16:59:21 +01:00
|
|
|
const QStringList qmlTypesExtensions = QStringList("*.qmltypes");
|
2014-01-23 14:28:31 +01:00
|
|
|
QFileInfoList qmlTypesFiles = typeFileDir.entryInfoList(
|
|
|
|
qmlTypesExtensions,
|
|
|
|
QDir::Files,
|
|
|
|
QDir::Name);
|
|
|
|
|
|
|
|
QStringList errors;
|
|
|
|
QStringList warnings;
|
|
|
|
|
|
|
|
// filter out the actual Qt builtins
|
|
|
|
for (int i = 0; i < qmlTypesFiles.size(); ++i) {
|
|
|
|
if (qmlTypesFiles.at(i).baseName() == QLatin1String("builtins")) {
|
|
|
|
QFileInfoList list;
|
|
|
|
list.append(qmlTypesFiles.at(i));
|
|
|
|
CppQmlTypesLoader::defaultQtObjects =
|
|
|
|
CppQmlTypesLoader::loadQmlTypes(list, &errors, &warnings);
|
|
|
|
qmlTypesFiles.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// load the fallbacks for libraries
|
|
|
|
CppQmlTypesLoader::defaultLibraryObjects.unite(
|
|
|
|
CppQmlTypesLoader::loadQmlTypes(qmlTypesFiles, &errors, &warnings));
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &error : qAsConst(errors))
|
2014-01-23 14:28:31 +01:00
|
|
|
writeMessageInternal(error);
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &warning : qAsConst(warnings))
|
2014-01-23 14:28:31 +01:00
|
|
|
writeMessageInternal(warning);
|
|
|
|
}
|
|
|
|
|
2014-06-30 11:56:28 +02:00
|
|
|
void ModelManagerInterface::setDefaultProject(const ModelManagerInterface::ProjectInfo &pInfo,
|
|
|
|
ProjectExplorer::Project *p)
|
|
|
|
{
|
|
|
|
QMutexLocker l(mutex());
|
|
|
|
m_defaultProject = p;
|
|
|
|
m_defaultProjectInfo = pInfo;
|
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
Snapshot ModelManagerInterface::snapshot() const
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2014-02-13 11:11:40 +01:00
|
|
|
return m_validSnapshot;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Snapshot ModelManagerInterface::newestSnapshot() const
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2014-02-13 11:11:40 +01:00
|
|
|
return m_newestSnapshot;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::updateSourceFiles(const QStringList &files,
|
2019-10-23 14:03:13 +02:00
|
|
|
bool emitDocumentOnDiskChanged)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
2019-01-18 20:28:55 +01:00
|
|
|
if (m_indexerDisabled)
|
2014-09-08 17:59:25 +02:00
|
|
|
return;
|
2014-01-23 14:28:31 +01:00
|
|
|
refreshSourceFiles(files, emitDocumentOnDiskChanged);
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:04:52 +01:00
|
|
|
void ModelManagerInterface::cleanupFutures()
|
|
|
|
{
|
2019-10-23 14:03:13 +02:00
|
|
|
const int maxFutures = 10;
|
|
|
|
if (m_futures.size() > maxFutures) {
|
|
|
|
const QList<QFuture<void>> futures = m_futures;
|
2016-01-22 11:04:52 +01:00
|
|
|
m_futures.clear();
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QFuture<void> &future : futures) {
|
2016-01-22 11:04:52 +01:00
|
|
|
if (!(future.isFinished() || future.isCanceled()))
|
|
|
|
m_futures.append(future);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourceFiles,
|
2019-10-23 14:03:13 +02:00
|
|
|
bool emitDocumentOnDiskChanged)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
if (sourceFiles.isEmpty())
|
|
|
|
return QFuture<void>();
|
|
|
|
|
2016-02-08 16:26:19 +01:00
|
|
|
QFuture<void> result = Utils::runAsync(&ModelManagerInterface::parse,
|
|
|
|
workingCopyInternal(), sourceFiles,
|
|
|
|
this, Dialect(Dialect::Qml),
|
|
|
|
emitDocumentOnDiskChanged);
|
2016-01-22 11:04:52 +01:00
|
|
|
cleanupFutures();
|
|
|
|
m_futures.append(result);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
if (sourceFiles.count() > 1)
|
2014-04-17 15:14:14 +02:00
|
|
|
addTaskInternal(result, tr("Parsing QML Files"), Constants::TASK_INDEX);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
if (sourceFiles.count() > 1 && !m_shouldScanImports) {
|
|
|
|
bool scan = false;
|
|
|
|
{
|
|
|
|
QMutexLocker l(&m_mutex);
|
|
|
|
if (!m_shouldScanImports) {
|
|
|
|
m_shouldScanImports = true;
|
|
|
|
scan = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scan)
|
|
|
|
updateImportPaths();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ModelManagerInterface::fileChangedOnDisk(const QString &path)
|
|
|
|
{
|
2016-02-08 16:26:19 +01:00
|
|
|
Utils::runAsync(&ModelManagerInterface::parse,
|
2017-02-07 16:59:21 +01:00
|
|
|
workingCopyInternal(), QStringList(path),
|
2016-02-08 16:26:19 +01:00
|
|
|
this, Dialect(Dialect::AnyLanguage), true);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::removeFiles(const QStringList &files)
|
|
|
|
{
|
|
|
|
emit aboutToRemoveFiles(files);
|
|
|
|
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &file : files) {
|
2014-02-13 11:11:40 +01:00
|
|
|
m_validSnapshot.remove(file);
|
|
|
|
m_newestSnapshot.remove(file);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2019-10-23 14:03:13 +02:00
|
|
|
bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1,
|
|
|
|
const ModelManagerInterface::ProjectInfo &p2)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
QStringList s1 = p1.activeResourceFiles;
|
|
|
|
QStringList s2 = p2.activeResourceFiles;
|
|
|
|
if (s1.size() < s2.size())
|
|
|
|
return true;
|
|
|
|
if (s1.size() > s2.size())
|
|
|
|
return false;
|
|
|
|
for (int i = 0; i < s1.size(); ++i) {
|
|
|
|
if (s1.at(i) < s2.at(i))
|
|
|
|
return true;
|
2019-10-23 14:03:13 +02:00
|
|
|
if (s1.at(i) > s2.at(i))
|
2014-01-23 14:28:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
bool pInfoLessThanAll(const ModelManagerInterface::ProjectInfo &p1,
|
|
|
|
const ModelManagerInterface::ProjectInfo &p2)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
QStringList s1 = p1.allResourceFiles;
|
|
|
|
QStringList s2 = p2.allResourceFiles;
|
|
|
|
if (s1.size() < s2.size())
|
|
|
|
return true;
|
|
|
|
if (s1.size() > s2.size())
|
|
|
|
return false;
|
|
|
|
for (int i = 0; i < s1.size(); ++i) {
|
|
|
|
if (s1.at(i) < s2.at(i))
|
|
|
|
return true;
|
2019-10-23 14:03:13 +02:00
|
|
|
if (s1.at(i) > s2.at(i))
|
2014-01-23 14:28:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1,
|
|
|
|
const ModelManagerInterface::ProjectInfo &p2)
|
2014-04-11 23:07:52 +02:00
|
|
|
{
|
|
|
|
if (p1.qtQmlPath < p2.qtQmlPath)
|
|
|
|
return true;
|
|
|
|
if (p1.qtQmlPath > p2.qtQmlPath)
|
|
|
|
return false;
|
2014-07-22 19:06:44 +02:00
|
|
|
const PathsAndLanguages &s1 = p1.importPaths;
|
|
|
|
const PathsAndLanguages &s2 = p2.importPaths;
|
2014-04-11 23:07:52 +02:00
|
|
|
if (s1.size() < s2.size())
|
|
|
|
return true;
|
|
|
|
if (s1.size() > s2.size())
|
|
|
|
return false;
|
|
|
|
for (int i = 0; i < s1.size(); ++i) {
|
|
|
|
if (s1.at(i) < s2.at(i))
|
|
|
|
return true;
|
2019-10-23 14:03:13 +02:00
|
|
|
if (s2.at(i) < s1.at(i))
|
2014-04-11 23:07:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
void ModelManagerInterface::iterateQrcFiles(
|
|
|
|
ProjectExplorer::Project *project, QrcResourceSelector resources,
|
|
|
|
const std::function<void(QrcParser::ConstPtr)> &callback)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
QList<ProjectInfo> pInfos;
|
2016-03-18 17:43:33 +01:00
|
|
|
if (project) {
|
2014-01-23 14:28:31 +01:00
|
|
|
pInfos.append(projectInfo(project));
|
2016-03-18 17:43:33 +01:00
|
|
|
} else {
|
2014-01-23 14:28:31 +01:00
|
|
|
pInfos = projectInfos();
|
2016-03-18 17:43:33 +01:00
|
|
|
if (resources == ActiveQrcResources) // make the result predictable
|
2016-08-03 23:29:58 +03:00
|
|
|
Utils::sort(pInfos, &pInfoLessThanActive);
|
2016-03-18 17:43:33 +01:00
|
|
|
else
|
2016-08-03 23:29:58 +03:00
|
|
|
Utils::sort(pInfos, &pInfoLessThanAll);
|
2016-03-18 17:43:33 +01:00
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
QSet<QString> pathsChecked;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const ModelManagerInterface::ProjectInfo &pInfo : qAsConst(pInfos)) {
|
2014-01-23 14:28:31 +01:00
|
|
|
QStringList qrcFilePaths;
|
|
|
|
if (resources == ActiveQrcResources)
|
|
|
|
qrcFilePaths = pInfo.activeResourceFiles;
|
|
|
|
else
|
|
|
|
qrcFilePaths = pInfo.allResourceFiles;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &qrcFilePath : qAsConst(qrcFilePaths)) {
|
2014-01-23 14:28:31 +01:00
|
|
|
if (pathsChecked.contains(qrcFilePath))
|
|
|
|
continue;
|
|
|
|
pathsChecked.insert(qrcFilePath);
|
|
|
|
QrcParser::ConstPtr qrcFile = m_qrcCache.parsedPath(qrcFilePath);
|
|
|
|
if (qrcFile.isNull())
|
|
|
|
continue;
|
2016-03-18 17:43:33 +01:00
|
|
|
callback(qrcFile);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-18 17:43:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ModelManagerInterface::qrcPathsForFile(const QString &file, const QLocale *locale,
|
|
|
|
ProjectExplorer::Project *project,
|
|
|
|
QrcResourceSelector resources)
|
|
|
|
{
|
|
|
|
QStringList res;
|
2019-10-23 14:03:13 +02:00
|
|
|
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
|
2016-03-18 17:43:33 +01:00
|
|
|
qrcFile->collectResourceFilesForSourceFile(file, &res, locale);
|
|
|
|
});
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ModelManagerInterface::filesAtQrcPath(const QString &path, const QLocale *locale,
|
|
|
|
ProjectExplorer::Project *project,
|
|
|
|
QrcResourceSelector resources)
|
|
|
|
{
|
|
|
|
QString normPath = QrcParser::normalizedQrcFilePath(path);
|
|
|
|
QStringList res;
|
2019-10-23 14:03:13 +02:00
|
|
|
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
|
2016-03-18 17:43:33 +01:00
|
|
|
qrcFile->collectFilesAtPath(normPath, &res, locale);
|
|
|
|
});
|
2014-01-23 14:28:31 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMap<QString, QStringList> ModelManagerInterface::filesInQrcPath(const QString &path,
|
|
|
|
const QLocale *locale,
|
|
|
|
ProjectExplorer::Project *project,
|
|
|
|
bool addDirs,
|
|
|
|
QrcResourceSelector resources)
|
|
|
|
{
|
|
|
|
QString normPath = QrcParser::normalizedQrcDirectoryPath(path);
|
|
|
|
QMap<QString, QStringList> res;
|
2019-10-23 14:03:13 +02:00
|
|
|
iterateQrcFiles(project, resources, [&](const QrcParser::ConstPtr &qrcFile) {
|
2016-03-18 17:43:33 +01:00
|
|
|
qrcFile->collectFilesInPath(normPath, &res, addDirs, locale);
|
|
|
|
});
|
2014-01-23 14:28:31 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::projectInfos() const
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
|
|
|
|
return m_projects.values();
|
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
bool ModelManagerInterface::containsProject(ProjectExplorer::Project *project) const
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2019-10-23 14:03:13 +02:00
|
|
|
return m_projects.contains(project);
|
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfo(
|
|
|
|
ProjectExplorer::Project *project) const
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
return m_projects.value(project);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p)
|
|
|
|
{
|
2019-10-23 14:03:13 +02:00
|
|
|
if (pinfo.project.isNull() || !p || m_indexerDisabled)
|
2014-01-23 14:28:31 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
Snapshot snapshot;
|
|
|
|
ProjectInfo oldInfo;
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
oldInfo = m_projects.value(p);
|
|
|
|
m_projects.insert(p, pinfo);
|
2014-06-30 11:56:28 +02:00
|
|
|
if (p == m_defaultProject)
|
|
|
|
m_defaultProjectInfo = pinfo;
|
2014-02-13 11:11:40 +01:00
|
|
|
snapshot = m_validSnapshot;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (oldInfo.qmlDumpPath != pinfo.qmlDumpPath
|
|
|
|
|| oldInfo.qmlDumpEnvironment != pinfo.qmlDumpEnvironment) {
|
|
|
|
m_pluginDumper->scheduleRedumpPlugins();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateImportPaths();
|
|
|
|
|
|
|
|
// remove files that are no longer in the project and have been deleted
|
|
|
|
QStringList deletedFiles;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &oldFile : qAsConst(oldInfo.sourceFiles)) {
|
2014-01-23 14:28:31 +01:00
|
|
|
if (snapshot.document(oldFile)
|
|
|
|
&& !pinfo.sourceFiles.contains(oldFile)
|
|
|
|
&& !QFile::exists(oldFile)) {
|
|
|
|
deletedFiles += oldFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeFiles(deletedFiles);
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &oldFile : qAsConst(deletedFiles))
|
2014-01-23 14:28:31 +01:00
|
|
|
m_fileToProject.remove(oldFile, p);
|
|
|
|
|
|
|
|
// parse any files not yet in the snapshot
|
|
|
|
QStringList newFiles;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &file : qAsConst(pinfo.sourceFiles)) {
|
2014-01-23 14:28:31 +01:00
|
|
|
if (!snapshot.document(file))
|
|
|
|
newFiles += file;
|
|
|
|
}
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &newFile : qAsConst(newFiles))
|
2014-01-23 14:28:31 +01:00
|
|
|
m_fileToProject.insert(newFile, p);
|
2014-12-02 13:24:25 +01:00
|
|
|
updateSourceFiles(newFiles, false);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
// update qrc cache
|
2016-10-24 19:30:24 +02:00
|
|
|
m_qrcContents = pinfo.resourceFileContents;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &newQrc : qAsConst(pinfo.allResourceFiles))
|
2016-10-24 19:30:24 +02:00
|
|
|
m_qrcCache.addPath(newQrc, m_qrcContents.value(newQrc));
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &oldQrc : qAsConst(oldInfo.allResourceFiles))
|
2014-01-23 14:28:31 +01:00
|
|
|
m_qrcCache.removePath(oldQrc);
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
m_pluginDumper->loadBuiltinTypes(pinfo);
|
2014-01-23 14:28:31 +01:00
|
|
|
emit projectInfoUpdated(pinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ModelManagerInterface::removeProjectInfo(ProjectExplorer::Project *project)
|
|
|
|
{
|
|
|
|
ProjectInfo info;
|
|
|
|
info.sourceFiles.clear();
|
|
|
|
// update with an empty project info to clear data
|
|
|
|
updateProjectInfo(info, project);
|
|
|
|
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
m_projects.remove(project);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 23:59:36 +03:00
|
|
|
/*!
|
|
|
|
Returns project info with summarized info for \a path
|
|
|
|
|
|
|
|
\note Project pointer will be empty
|
|
|
|
*/
|
2019-10-23 14:03:13 +02:00
|
|
|
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(
|
|
|
|
const QString &path) const
|
2015-04-26 23:59:36 +03:00
|
|
|
{
|
|
|
|
ProjectInfo res;
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto allProjectInfos = allProjectInfosForPath(path);
|
|
|
|
for (const ProjectInfo &pInfo : allProjectInfos) {
|
2015-04-26 23:59:36 +03:00
|
|
|
if (res.qtQmlPath.isEmpty())
|
|
|
|
res.qtQmlPath = pInfo.qtQmlPath;
|
2019-10-22 16:29:40 +02:00
|
|
|
res.applicationDirectories.append(pInfo.applicationDirectories);
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const auto &importPath : pInfo.importPaths)
|
|
|
|
res.importPaths.maybeInsert(importPath);
|
2015-04-26 23:59:36 +03:00
|
|
|
}
|
2019-10-22 16:29:40 +02:00
|
|
|
res.applicationDirectories = Utils::filteredUnique(res.applicationDirectories);
|
2015-04-26 23:59:36 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns list of project infos for \a path
|
|
|
|
*/
|
2019-10-23 14:03:13 +02:00
|
|
|
QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfosForPath(
|
|
|
|
const QString &path) const
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
2014-04-11 23:07:52 +02:00
|
|
|
QList<ProjectExplorer::Project *> projects;
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
projects = m_fileToProject.values(path);
|
2014-12-02 13:24:25 +01:00
|
|
|
if (projects.isEmpty()) {
|
|
|
|
QFileInfo fInfo(path);
|
|
|
|
projects = m_fileToProject.values(fInfo.canonicalFilePath());
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
|
|
|
QList<ProjectInfo> infos;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (ProjectExplorer::Project *project : qAsConst(projects)) {
|
2014-04-11 23:07:52 +02:00
|
|
|
ProjectInfo info = projectInfo(project);
|
2019-10-23 14:03:13 +02:00
|
|
|
if (!info.project.isNull())
|
2014-04-11 23:07:52 +02:00
|
|
|
infos.append(info);
|
|
|
|
}
|
|
|
|
std::sort(infos.begin(), infos.end(), &pInfoLessThanImports);
|
2014-12-02 13:24:25 +01:00
|
|
|
infos.append(m_defaultProjectInfo);
|
2015-04-26 23:59:36 +03:00
|
|
|
return infos;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 16:24:26 +01:00
|
|
|
bool ModelManagerInterface::isIdle() const
|
|
|
|
{
|
2016-01-22 11:04:52 +01:00
|
|
|
return m_futures.isEmpty();
|
2014-11-06 16:24:26 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
|
2019-10-23 14:03:13 +02:00
|
|
|
{
|
|
|
|
emit documentChangedOnDisk(std::move(doc));
|
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
void ModelManagerInterface::updateQrcFile(const QString &path)
|
|
|
|
{
|
2016-10-24 19:30:24 +02:00
|
|
|
m_qrcCache.updatePath(path, m_qrcContents.value(path));
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
void ModelManagerInterface::updateDocument(const Document::Ptr &doc)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2014-02-13 11:11:40 +01:00
|
|
|
m_validSnapshot.insert(doc);
|
|
|
|
m_newestSnapshot.insert(doc, true);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
emit documentUpdated(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::updateLibraryInfo(const QString &path, const LibraryInfo &info)
|
|
|
|
{
|
|
|
|
if (!info.pluginTypeInfoError().isEmpty())
|
2014-07-22 17:05:28 +02:00
|
|
|
qCDebug(qmljsLog) << "Dumping errors for " << path << ":" << info.pluginTypeInfoError();
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2014-02-13 11:11:40 +01:00
|
|
|
m_validSnapshot.insertLibraryInfo(path, info);
|
|
|
|
m_newestSnapshot.insertLibraryInfo(path, info);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
// only emit if we got new useful information
|
|
|
|
if (info.isValid())
|
|
|
|
emit libraryInfoUpdated(path, info);
|
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
static QStringList filesInDirectoryForLanguages(const QString &path,
|
|
|
|
const QList<Dialect> &languages)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
const QStringList pattern = ModelManagerInterface::globPatternsForLanguages(languages);
|
|
|
|
QStringList files;
|
|
|
|
|
|
|
|
const QDir dir(path);
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto entries = dir.entryInfoList(pattern, QDir::Files);
|
|
|
|
for (const QFileInfo &fi : entries)
|
2014-01-23 14:28:31 +01:00
|
|
|
files += fi.absoluteFilePath();
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
2019-10-23 14:03:13 +02:00
|
|
|
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
// 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()) {
|
2019-10-23 14:03:13 +02:00
|
|
|
if (!scannedPaths->contains(doc->path())) {
|
2014-01-23 14:28:31 +01:00
|
|
|
*importedFiles += filesInDirectoryForLanguages(doc->path(),
|
2019-10-23 14:03:13 +02:00
|
|
|
doc->language().companionLanguages());
|
2014-01-23 14:28:31 +01:00
|
|
|
scannedPaths->insert(doc->path());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
|
|
|
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
|
|
|
{
|
|
|
|
// scan files and directories that are explicitly imported
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto imports = doc->bind()->imports();
|
|
|
|
for (const ImportInfo &import : imports) {
|
2014-01-23 14:28:31 +01:00
|
|
|
const QString &importName = import.path();
|
|
|
|
if (import.type() == ImportType::File) {
|
|
|
|
if (! snapshot.document(importName))
|
|
|
|
*importedFiles += importName;
|
|
|
|
} else if (import.type() == ImportType::Directory) {
|
|
|
|
if (snapshot.documentsInDirectory(importName).isEmpty()) {
|
|
|
|
if (! scannedPaths->contains(importName)) {
|
2019-10-23 14:03:13 +02:00
|
|
|
*importedFiles += filesInDirectoryForLanguages(
|
|
|
|
importName, doc->language().companionLanguages());
|
2014-01-23 14:28:31 +01:00
|
|
|
scannedPaths->insert(importName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (import.type() == ImportType::QrcFile) {
|
2019-10-23 14:03:13 +02:00
|
|
|
const QStringList importPaths
|
|
|
|
= ModelManagerInterface::instance()->filesAtQrcPath(importName);
|
|
|
|
for (const QString &importPath : importPaths) {
|
|
|
|
if (!snapshot.document(importPath))
|
2014-01-23 14:28:31 +01:00
|
|
|
*importedFiles += importPath;
|
|
|
|
}
|
|
|
|
} else if (import.type() == ImportType::QrcDirectory) {
|
2019-10-23 14:03:13 +02:00
|
|
|
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;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 16:29:40 +02:00
|
|
|
enum class LibraryStatus {
|
|
|
|
Accepted,
|
|
|
|
Rejected,
|
|
|
|
Unknown
|
|
|
|
};
|
|
|
|
|
|
|
|
static LibraryStatus libraryStatus(const QString &path, const Snapshot &snapshot,
|
|
|
|
QSet<QString> *newLibraries)
|
|
|
|
{
|
|
|
|
if (path.isEmpty())
|
|
|
|
return LibraryStatus::Rejected;
|
|
|
|
// if we know there is a library, done
|
|
|
|
const LibraryInfo &existingInfo = snapshot.libraryInfo(path);
|
|
|
|
if (existingInfo.isValid())
|
|
|
|
return LibraryStatus::Accepted;
|
|
|
|
if (newLibraries->contains(path))
|
|
|
|
return LibraryStatus::Accepted;
|
|
|
|
// if we looked at the path before, done
|
|
|
|
return existingInfo.wasScanned()
|
|
|
|
? LibraryStatus::Rejected
|
|
|
|
: LibraryStatus::Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool findNewQmlApplicationInPath(const QString &path,
|
|
|
|
const Snapshot &snapshot,
|
|
|
|
ModelManagerInterface *modelManager,
|
|
|
|
QSet<QString> *newLibraries)
|
|
|
|
{
|
|
|
|
switch (libraryStatus(path, snapshot, newLibraries)) {
|
|
|
|
case LibraryStatus::Accepted: return true;
|
|
|
|
case LibraryStatus::Rejected: return false;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2020-03-26 12:17:03 +01:00
|
|
|
QString qmltypesFile;
|
|
|
|
|
|
|
|
QDir dir(path);
|
|
|
|
QDirIterator it(path, QStringList { "*.qmltypes" }, QDir::Files);
|
|
|
|
|
|
|
|
if (!it.hasNext())
|
2019-10-22 16:29:40 +02:00
|
|
|
return false;
|
|
|
|
|
2020-03-26 12:17:03 +01:00
|
|
|
qmltypesFile = it.next();
|
|
|
|
|
|
|
|
LibraryInfo libraryInfo = LibraryInfo(QmlDirParser::TypeInfo(qmltypesFile));
|
2019-10-22 16:29:40 +02:00
|
|
|
const QString libraryPath = dir.absolutePath();
|
|
|
|
newLibraries->insert(libraryPath);
|
|
|
|
modelManager->updateLibraryInfo(path, libraryInfo);
|
|
|
|
modelManager->loadPluginTypes(QFileInfo(libraryPath).canonicalFilePath(), libraryPath,
|
|
|
|
QString(), QString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
static bool findNewQmlLibraryInPath(const QString &path,
|
|
|
|
const Snapshot &snapshot,
|
|
|
|
ModelManagerInterface *modelManager,
|
|
|
|
QStringList *importedFiles,
|
|
|
|
QSet<QString> *scannedPaths,
|
|
|
|
QSet<QString> *newLibraries,
|
|
|
|
bool ignoreMissing)
|
|
|
|
{
|
2019-10-22 16:29:40 +02:00
|
|
|
switch (libraryStatus(path, snapshot, newLibraries)) {
|
|
|
|
case LibraryStatus::Accepted: return true;
|
|
|
|
case LibraryStatus::Rejected: return false;
|
|
|
|
default: break;
|
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
const QDir dir(path);
|
|
|
|
QFile qmldirFile(dir.filePath(QLatin1String("qmldir")));
|
|
|
|
if (!qmldirFile.exists()) {
|
|
|
|
if (!ignoreMissing) {
|
|
|
|
LibraryInfo libraryInfo(LibraryInfo::NotFound);
|
|
|
|
modelManager->updateLibraryInfo(path, libraryInfo);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
// QTCREATORBUG-3402 - be case sensitive even here?
|
|
|
|
}
|
|
|
|
|
|
|
|
// found a new library!
|
2017-04-06 12:42:23 +02:00
|
|
|
if (!qmldirFile.open(QFile::ReadOnly))
|
|
|
|
return false;
|
2014-01-23 14:28:31 +01:00
|
|
|
QString qmldirData = QString::fromUtf8(qmldirFile.readAll());
|
|
|
|
|
|
|
|
QmlDirParser qmldirParser;
|
|
|
|
qmldirParser.parse(qmldirData);
|
|
|
|
|
|
|
|
const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
|
|
|
|
newLibraries->insert(libraryPath);
|
|
|
|
modelManager->updateLibraryInfo(libraryPath, LibraryInfo(qmldirParser));
|
2014-06-30 12:46:40 +02:00
|
|
|
modelManager->loadPluginTypes(QFileInfo(libraryPath).canonicalFilePath(), libraryPath,
|
|
|
|
QString(), QString());
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
// scan the qml files in the library
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto components = qmldirParser.components();
|
|
|
|
for (const QmlDirParser::Component &component : components) {
|
|
|
|
if (!component.fileName.isEmpty()) {
|
2014-01-23 14:28:31 +01:00
|
|
|
const QFileInfo componentFileInfo(dir.filePath(component.fileName));
|
|
|
|
const QString path = QDir::cleanPath(componentFileInfo.absolutePath());
|
2019-10-23 14:03:13 +02:00
|
|
|
if (!scannedPaths->contains(path)) {
|
|
|
|
*importedFiles += filesInDirectoryForLanguages(path, Dialect(Dialect::AnyLanguage)
|
|
|
|
.companionLanguages());
|
2014-01-23 14:28:31 +01:00
|
|
|
scannedPaths->insert(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-28 16:24:13 +02:00
|
|
|
static QString modulePath(const ImportInfo &import, const QStringList &paths)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
2017-09-28 16:24:13 +02:00
|
|
|
if (!import.version().isValid())
|
|
|
|
return QString();
|
|
|
|
return modulePath(import.name(), import.version().toString(), paths);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
2019-10-23 14:03:13 +02:00
|
|
|
ModelManagerInterface *modelManager, QStringList *importedFiles,
|
|
|
|
QSet<QString> *scannedPaths, QSet<QString> *newLibraries)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
// scan current dir
|
|
|
|
findNewQmlLibraryInPath(doc->path(), snapshot, modelManager,
|
|
|
|
importedFiles, scannedPaths, newLibraries, false);
|
|
|
|
|
|
|
|
// scan dir and lib imports
|
2017-09-28 16:24:13 +02:00
|
|
|
const QStringList importPaths = modelManager->importPathsNames();
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto imports = doc->bind()->imports();
|
|
|
|
for (const ImportInfo &import : imports) {
|
|
|
|
switch (import.type()) {
|
|
|
|
case ImportType::Directory:
|
|
|
|
findNewQmlLibraryInPath(import.path(), snapshot, modelManager,
|
2014-01-23 14:28:31 +01:00
|
|
|
importedFiles, scannedPaths, newLibraries, false);
|
2019-10-23 14:03:13 +02:00
|
|
|
break;
|
|
|
|
case ImportType::Library:
|
|
|
|
findNewQmlLibraryInPath(modulePath(import, importPaths), snapshot, modelManager,
|
|
|
|
importedFiles, scannedPaths, newLibraries, false);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
2019-10-23 14:03:13 +02:00
|
|
|
QSet<QString> &newLibraries,
|
|
|
|
const WorkingCopy &workingCopy,
|
|
|
|
QStringList files,
|
|
|
|
ModelManagerInterface *modelManager,
|
|
|
|
Dialect mainLanguage,
|
|
|
|
bool emitDocChangedOnDisk,
|
|
|
|
const std::function<bool(qreal)> &reportProgress)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < files.size(); ++i) {
|
|
|
|
if (!reportProgress(qreal(i) / files.size()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const QString fileName = files.at(i);
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect language = guessLanguageOfFile(fileName);
|
|
|
|
if (language == Dialect::NoLanguage) {
|
2014-01-23 14:28:31 +01:00
|
|
|
if (fileName.endsWith(QLatin1String(".qrc")))
|
|
|
|
modelManager->updateQrcFile(fileName);
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-22 19:06:44 +02:00
|
|
|
if (language == Dialect::Qml
|
2018-02-19 12:26:51 +01:00
|
|
|
&& (mainLanguage == Dialect::QmlQtQuick2))
|
2014-01-23 14:28:31 +01:00
|
|
|
language = mainLanguage;
|
2014-10-13 16:46:30 +02:00
|
|
|
if (language == Dialect::Qml && mainLanguage == Dialect::QmlQtQuick2Ui)
|
|
|
|
language = Dialect::QmlQtQuick2;
|
2014-11-20 16:13:32 +01:00
|
|
|
if (language == Dialect::QmlTypeInfo || language == Dialect::QmlProject)
|
|
|
|
continue;
|
2014-01-23 14:28:31 +01:00
|
|
|
QString contents;
|
|
|
|
int documentRevision = 0;
|
|
|
|
|
|
|
|
if (workingCopy.contains(fileName)) {
|
|
|
|
QPair<QString, int> entry = workingCopy.get(fileName);
|
|
|
|
contents = entry.first;
|
|
|
|
documentRevision = entry.second;
|
|
|
|
} else {
|
|
|
|
QFile inFile(fileName);
|
|
|
|
|
|
|
|
if (inFile.open(QIODevice::ReadOnly)) {
|
|
|
|
QTextStream ins(&inFile);
|
|
|
|
contents = ins.readAll();
|
|
|
|
inFile.close();
|
2017-12-06 16:01:52 +01:00
|
|
|
} else {
|
|
|
|
continue;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Document::MutablePtr doc = Document::create(fileName, language);
|
|
|
|
doc->setEditorRevision(documentRevision);
|
|
|
|
doc->setSource(contents);
|
|
|
|
doc->parse();
|
|
|
|
|
|
|
|
// update snapshot. requires synchronization, but significantly reduces amount of file
|
|
|
|
// system queries for library imports because queries are cached in libraryInfo
|
|
|
|
const Snapshot snapshot = modelManager->snapshot();
|
|
|
|
|
|
|
|
// get list of referenced files not yet in snapshot or in directories already scanned
|
|
|
|
QStringList importedFiles;
|
|
|
|
findNewImplicitImports(doc, snapshot, &importedFiles, &scannedPaths);
|
|
|
|
findNewFileImports(doc, snapshot, &importedFiles, &scannedPaths);
|
2019-10-23 14:03:13 +02:00
|
|
|
findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths,
|
|
|
|
&newLibraries);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
// add new files to parse list
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &file : qAsConst(importedFiles)) {
|
|
|
|
if (!files.contains(file))
|
2014-01-23 14:28:31 +01:00
|
|
|
files.append(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
modelManager->updateDocument(doc);
|
|
|
|
if (emitDocChangedOnDisk)
|
|
|
|
modelManager->emitDocumentChangedOnDisk(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FutureReporter
|
|
|
|
{
|
|
|
|
public:
|
2019-10-23 14:03:13 +02:00
|
|
|
FutureReporter(QFutureInterface<void> &future, int multiplier, int base)
|
|
|
|
: future(future), multiplier(multiplier), base(base)
|
|
|
|
{}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
bool operator()(qreal val)
|
|
|
|
{
|
|
|
|
if (future.isCanceled())
|
|
|
|
return false;
|
|
|
|
future.setProgressValue(int(base + multiplier * val));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
QFutureInterface<void> &future;
|
|
|
|
int multiplier;
|
|
|
|
int base;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ModelManagerInterface::parse(QFutureInterface<void> &future,
|
2019-10-23 14:03:13 +02:00
|
|
|
const WorkingCopy &workingCopy,
|
|
|
|
QStringList files,
|
|
|
|
ModelManagerInterface *modelManager,
|
|
|
|
Dialect mainLanguage,
|
|
|
|
bool emitDocChangedOnDisk)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
2019-10-23 14:03:13 +02:00
|
|
|
const int progressMax = 100;
|
|
|
|
FutureReporter reporter(future, progressMax, 0);
|
|
|
|
future.setProgressRange(0, progressMax);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
// 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;
|
2019-10-23 14:03:13 +02:00
|
|
|
parseLoop(scannedPaths, newLibraries, workingCopy, std::move(files), modelManager, mainLanguage,
|
2014-01-23 14:28:31 +01:00
|
|
|
emitDocChangedOnDisk, reporter);
|
2019-10-23 14:03:13 +02:00
|
|
|
future.setProgressValue(progressMax);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ScanItem {
|
|
|
|
QString path;
|
2019-10-23 14:03:13 +02:00
|
|
|
int depth = 0;
|
|
|
|
Dialect language = Dialect::AnyLanguage;
|
2014-01-23 14:28:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
2019-10-23 14:03:13 +02:00
|
|
|
const ModelManagerInterface::WorkingCopy &workingCopy,
|
|
|
|
const PathsAndLanguages &paths,
|
|
|
|
ModelManagerInterface *modelManager,
|
|
|
|
bool emitDocChangedOnDisk, bool libOnly, bool forceRescan)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
// paths we have scanned for files and added to the files list
|
2014-07-29 20:03:48 +02:00
|
|
|
QSet<QString> scannedPaths;
|
|
|
|
{
|
|
|
|
QMutexLocker l(&modelManager->m_mutex);
|
|
|
|
scannedPaths = modelManager->m_scannedPaths;
|
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
// libraries we've found while scanning imports
|
|
|
|
QSet<QString> newLibraries;
|
|
|
|
|
|
|
|
QVector<ScanItem> pathsToScan;
|
|
|
|
pathsToScan.reserve(paths.size());
|
|
|
|
{
|
|
|
|
QMutexLocker l(&modelManager->m_mutex);
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const auto &path : paths) {
|
|
|
|
QString cPath = QDir::cleanPath(path.path().toString());
|
2017-03-07 15:49:02 +01:00
|
|
|
if (!forceRescan && modelManager->m_scannedPaths.contains(cPath))
|
2014-01-23 14:28:31 +01:00
|
|
|
continue;
|
2019-10-23 14:03:13 +02:00
|
|
|
pathsToScan.append({cPath, 0, path.language()});
|
2014-01-23 14:28:31 +01:00
|
|
|
modelManager->m_scannedPaths.insert(cPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const int maxScanDepth = 5;
|
|
|
|
int progressRange = pathsToScan.size() * (1 << (2 + maxScanDepth));
|
2019-10-23 14:03:13 +02:00
|
|
|
int totalWork = progressRange;
|
|
|
|
int workDone = 0;
|
2014-01-23 14:28:31 +01:00
|
|
|
future.setProgressRange(0, progressRange); // update max length while iterating?
|
|
|
|
const Snapshot snapshot = modelManager->snapshot();
|
2014-12-04 13:20:18 +01:00
|
|
|
bool isCanceled = future.isCanceled();
|
|
|
|
while (!pathsToScan.isEmpty() && !isCanceled) {
|
2014-01-23 14:28:31 +01:00
|
|
|
ScanItem toScan = pathsToScan.last();
|
|
|
|
pathsToScan.pop_back();
|
2014-05-26 18:20:00 +02:00
|
|
|
int pathBudget = (1 << (maxScanDepth + 2 - toScan.depth));
|
2017-03-07 15:49:02 +01:00
|
|
|
if (forceRescan || !scannedPaths.contains(toScan.path)) {
|
2014-01-23 14:28:31 +01:00
|
|
|
QStringList importedFiles;
|
2017-03-07 15:49:02 +01:00
|
|
|
if (forceRescan ||
|
|
|
|
(!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles,
|
2019-10-23 14:03:13 +02:00
|
|
|
&scannedPaths, &newLibraries, true)
|
2017-03-07 15:49:02 +01:00
|
|
|
&& !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty())) {
|
2014-01-23 14:28:31 +01:00
|
|
|
importedFiles += filesInDirectoryForLanguages(toScan.path,
|
2019-10-23 14:03:13 +02:00
|
|
|
toScan.language.companionLanguages());
|
2017-03-07 15:49:02 +01:00
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
workDone += 1;
|
|
|
|
future.setProgressValue(progressRange * workDone / totalWork);
|
|
|
|
if (!importedFiles.isEmpty()) {
|
|
|
|
FutureReporter reporter(future, progressRange * pathBudget / (4 * totalWork),
|
|
|
|
progressRange * workDone / totalWork);
|
|
|
|
parseLoop(scannedPaths, newLibraries, workingCopy, importedFiles, modelManager,
|
2014-07-22 19:06:44 +02:00
|
|
|
toScan.language, emitDocChangedOnDisk, reporter); // run in parallel??
|
2014-01-23 14:28:31 +01:00
|
|
|
importedFiles.clear();
|
|
|
|
}
|
|
|
|
workDone += pathBudget / 4 - 1;
|
|
|
|
future.setProgressValue(progressRange * workDone / totalWork);
|
|
|
|
} else {
|
|
|
|
workDone += pathBudget / 4;
|
|
|
|
}
|
|
|
|
// always descend tree, as we might have just scanned with a smaller depth
|
|
|
|
if (toScan.depth < maxScanDepth) {
|
|
|
|
QDir dir(toScan.path);
|
2014-05-26 18:20:00 +02:00
|
|
|
QStringList subDirs(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot));
|
2014-01-23 14:28:31 +01:00
|
|
|
workDone += 1;
|
|
|
|
totalWork += pathBudget / 2 * subDirs.size() - pathBudget * 3 / 4 + 1;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &path : qAsConst(subDirs))
|
|
|
|
pathsToScan.append({dir.absoluteFilePath(path), toScan.depth + 1, toScan.language});
|
2014-01-23 14:28:31 +01:00
|
|
|
} else {
|
2014-06-02 16:46:39 +02:00
|
|
|
workDone += pathBudget * 3 / 4;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
future.setProgressValue(progressRange * workDone / totalWork);
|
2014-12-04 13:20:18 +01:00
|
|
|
isCanceled = future.isCanceled();
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
future.setProgressValue(progressRange);
|
2014-12-04 13:20:18 +01:00
|
|
|
if (isCanceled) {
|
2014-01-23 14:28:31 +01:00
|
|
|
// assume no work has been done
|
|
|
|
QMutexLocker l(&modelManager->m_mutex);
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const auto &path : paths)
|
|
|
|
modelManager->m_scannedPaths.remove(path.path().toString());
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 16:24:13 +02:00
|
|
|
QStringList ModelManagerInterface::importPathsNames() const
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
2017-09-28 16:24:13 +02:00
|
|
|
QStringList names;
|
2014-01-23 14:28:31 +01:00
|
|
|
QMutexLocker l(&m_mutex);
|
2017-09-28 16:24:13 +02:00
|
|
|
names.reserve(m_allImportPaths.size());
|
|
|
|
for (const PathAndLanguage &x: m_allImportPaths)
|
|
|
|
names << x.path().toString();
|
|
|
|
return names;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlLanguageBundles ModelManagerInterface::activeBundles() const
|
|
|
|
{
|
|
|
|
QMutexLocker l(&m_mutex);
|
|
|
|
return m_activeBundles;
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlLanguageBundles ModelManagerInterface::extendedBundles() const
|
|
|
|
{
|
|
|
|
QMutexLocker l(&m_mutex);
|
|
|
|
return m_extendedBundles;
|
|
|
|
}
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
|
2014-04-08 11:36:03 +02:00
|
|
|
{
|
2019-01-18 20:28:55 +01:00
|
|
|
if (m_indexerDisabled)
|
2014-09-08 17:59:25 +02:00
|
|
|
return;
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages pathToScan;
|
2014-04-08 11:36:03 +02:00
|
|
|
{
|
|
|
|
QMutexLocker l(&m_mutex);
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const PathAndLanguage &importPath : importPaths)
|
2014-07-22 19:06:44 +02:00
|
|
|
if (!m_scannedPaths.contains(importPath.path().toString()))
|
|
|
|
pathToScan.maybeInsert(importPath);
|
2014-04-08 11:36:03 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
if (pathToScan.length() > 1) {
|
2016-02-08 16:26:19 +01:00
|
|
|
QFuture<void> result = Utils::runAsync(&ModelManagerInterface::importScan,
|
|
|
|
workingCopyInternal(), pathToScan,
|
2017-03-07 15:49:02 +01:00
|
|
|
this, true, true, false);
|
2016-01-22 11:04:52 +01:00
|
|
|
cleanupFutures();
|
|
|
|
m_futures.append(result);
|
2014-04-08 11:36:03 +02:00
|
|
|
|
2014-05-02 10:00:20 +02:00
|
|
|
addTaskInternal(result, tr("Scanning QML Imports"), Constants::TASK_IMPORT_SCAN);
|
2014-04-08 11:36:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
void ModelManagerInterface::updateImportPaths()
|
|
|
|
{
|
2019-01-18 20:28:55 +01:00
|
|
|
if (m_indexerDisabled)
|
2014-09-08 17:59:25 +02:00
|
|
|
return;
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages allImportPaths;
|
2019-10-22 16:29:40 +02:00
|
|
|
QStringList allApplicationDirectories;
|
2014-01-23 14:28:31 +01:00
|
|
|
QmlLanguageBundles activeBundles;
|
|
|
|
QmlLanguageBundles extendedBundles;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
|
|
|
|
for (const auto &importPath : pInfo.importPaths) {
|
|
|
|
const QString canonicalPath = importPath.path().toFileInfo().canonicalFilePath();
|
|
|
|
if (!canonicalPath.isEmpty()) {
|
2019-05-28 13:49:26 +02:00
|
|
|
allImportPaths.maybeInsert(Utils::FilePath::fromString(canonicalPath),
|
2019-10-23 14:03:13 +02:00
|
|
|
importPath.language());
|
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
2019-10-22 16:29:40 +02:00
|
|
|
allApplicationDirectories.append(pInfo.applicationDirectories);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
2019-10-23 14:03:13 +02:00
|
|
|
|
|
|
|
for (const ViewerContext &vContext : qAsConst(m_defaultVContexts)) {
|
|
|
|
for (const QString &path : vContext.paths)
|
|
|
|
allImportPaths.maybeInsert(Utils::FilePath::fromString(path), vContext.language);
|
2019-10-22 16:29:40 +02:00
|
|
|
allApplicationDirectories.append(vContext.applicationDirectories);
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
2019-10-23 14:03:13 +02:00
|
|
|
|
|
|
|
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) {
|
2014-01-23 14:28:31 +01:00
|
|
|
const QString canonicalPath = QFileInfo(path).canonicalFilePath();
|
|
|
|
if (!canonicalPath.isEmpty())
|
2019-05-28 13:49:26 +02:00
|
|
|
allImportPaths.maybeInsert(Utils::FilePath::fromString(canonicalPath), l);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-23 14:03:13 +02:00
|
|
|
|
|
|
|
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
|
|
|
|
if (!pInfo.qtQmlPath.isEmpty()) {
|
|
|
|
allImportPaths.maybeInsert(Utils::FilePath::fromString(pInfo.qtQmlPath),
|
|
|
|
Dialect::QmlQtQuick2);
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
2019-10-23 14:03:13 +02:00
|
|
|
|
2014-04-11 23:07:52 +02:00
|
|
|
{
|
2019-10-23 14:03:13 +02:00
|
|
|
const QString pathAtt = defaultProjectInfo().qtQmlPath;
|
2014-07-22 19:06:44 +02:00
|
|
|
if (!pathAtt.isEmpty())
|
2019-05-28 13:49:26 +02:00
|
|
|
allImportPaths.maybeInsert(Utils::FilePath::fromString(pathAtt), Dialect::QmlQtQuick2);
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
2018-02-19 12:26:51 +01:00
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &path : qAsConst(m_defaultImportPaths))
|
2019-05-28 13:49:26 +02:00
|
|
|
allImportPaths.maybeInsert(Utils::FilePath::fromString(path), Dialect::Qml);
|
2014-07-22 19:06:44 +02:00
|
|
|
allImportPaths.compact();
|
2019-10-22 16:29:40 +02:00
|
|
|
allApplicationDirectories = Utils::filteredUnique(allApplicationDirectories);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
QMutexLocker l(&m_mutex);
|
|
|
|
m_allImportPaths = allImportPaths;
|
|
|
|
m_activeBundles = activeBundles;
|
|
|
|
m_extendedBundles = extendedBundles;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// check if any file in the snapshot imports something new in the new paths
|
2014-02-13 11:11:40 +01:00
|
|
|
Snapshot snapshot = m_validSnapshot;
|
2014-01-23 14:28:31 +01:00
|
|
|
QStringList importedFiles;
|
|
|
|
QSet<QString> scannedPaths;
|
|
|
|
QSet<QString> newLibraries;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const Document::Ptr &doc : qAsConst(snapshot))
|
2014-01-23 14:28:31 +01:00
|
|
|
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
|
2019-10-22 16:29:40 +02:00
|
|
|
for (const QString &path : allApplicationDirectories)
|
|
|
|
findNewQmlApplicationInPath(path, snapshot, this, &newLibraries);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
updateSourceFiles(importedFiles, true);
|
|
|
|
|
|
|
|
if (!m_shouldScanImports)
|
|
|
|
return;
|
2014-07-22 19:06:44 +02:00
|
|
|
maybeScan(allImportPaths);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::loadPluginTypes(const QString &libraryPath, const QString &importPath,
|
|
|
|
const QString &importUri, const QString &importVersion)
|
|
|
|
{
|
|
|
|
m_pluginDumper->loadPluginTypes(libraryPath, importPath, importUri, importVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
// is called *inside a c++ parsing thread*, to allow hanging on to source and ast
|
|
|
|
void ModelManagerInterface::maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc)
|
|
|
|
{
|
|
|
|
// avoid scanning documents without source code available
|
|
|
|
doc->keepSourceAndAST();
|
|
|
|
if (doc->utf8Source().isEmpty()) {
|
|
|
|
doc->releaseSourceAndAST();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// keep source and AST alive if we want to scan for register calls
|
|
|
|
const bool scan = FindExportedCppTypes::maybeExportsTypes(doc);
|
|
|
|
if (!scan)
|
|
|
|
doc->releaseSourceAndAST();
|
|
|
|
|
|
|
|
// delegate actual queuing to the gui thread
|
2016-01-27 22:36:48 +02:00
|
|
|
QMetaObject::invokeMethod(this, "queueCppQmlTypeUpdate",
|
|
|
|
Q_ARG(CPlusPlus::Document::Ptr, doc), Q_ARG(bool, scan));
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan)
|
|
|
|
{
|
|
|
|
QPair<CPlusPlus::Document::Ptr, bool> prev = m_queuedCppDocuments.value(doc->fileName());
|
|
|
|
if (prev.first && prev.second)
|
|
|
|
prev.first->releaseSourceAndAST();
|
2017-04-26 13:18:26 +02:00
|
|
|
m_queuedCppDocuments.insert(doc->fileName(), {doc, scan});
|
2014-01-23 14:28:31 +01:00
|
|
|
m_updateCppQmlTypesTimer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::startCppQmlTypeUpdate()
|
|
|
|
{
|
|
|
|
// if a future is still running, delay
|
|
|
|
if (m_cppQmlTypesUpdater.isRunning()) {
|
|
|
|
m_updateCppQmlTypesTimer->start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPlusPlus::CppModelManagerBase *cppModelManager =
|
|
|
|
CPlusPlus::CppModelManagerBase::instance();
|
|
|
|
if (!cppModelManager)
|
|
|
|
return;
|
|
|
|
|
2016-02-08 16:26:19 +01:00
|
|
|
m_cppQmlTypesUpdater = Utils::runAsync(&ModelManagerInterface::updateCppQmlTypes,
|
2014-01-23 14:28:31 +01:00
|
|
|
this, cppModelManager->snapshot(), m_queuedCppDocuments);
|
|
|
|
m_queuedCppDocuments.clear();
|
|
|
|
}
|
|
|
|
|
2014-06-30 11:56:28 +02:00
|
|
|
QMutex *ModelManagerInterface::mutex() const
|
|
|
|
{
|
|
|
|
return &m_mutex;
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
void ModelManagerInterface::asyncReset()
|
|
|
|
{
|
|
|
|
m_asyncResetTimer->start();
|
|
|
|
}
|
|
|
|
|
2016-07-08 13:09:56 +02:00
|
|
|
bool rescanExports(const QString &fileName, FindExportedCppTypes &finder,
|
|
|
|
ModelManagerInterface::CppDataHash &newData)
|
|
|
|
{
|
|
|
|
bool hasNewInfo = false;
|
|
|
|
|
|
|
|
QList<LanguageUtils::FakeMetaObject::ConstPtr> exported = finder.exportedTypes();
|
|
|
|
QHash<QString, QString> contextProperties = finder.contextProperties();
|
|
|
|
if (exported.isEmpty() && contextProperties.isEmpty()) {
|
|
|
|
hasNewInfo = hasNewInfo || newData.remove(fileName) > 0;
|
|
|
|
} else {
|
|
|
|
ModelManagerInterface::CppData &data = newData[fileName];
|
|
|
|
if (!hasNewInfo && (data.exportedTypes.size() != exported.size()
|
2019-10-23 14:03:13 +02:00
|
|
|
|| data.contextProperties != contextProperties)) {
|
2016-07-08 13:09:56 +02:00
|
|
|
hasNewInfo = true;
|
2019-10-23 14:03:13 +02:00
|
|
|
}
|
2016-07-08 13:09:56 +02:00
|
|
|
if (!hasNewInfo) {
|
|
|
|
QHash<QString, QByteArray> newFingerprints;
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const auto &newType : qAsConst(exported))
|
2016-07-08 13:09:56 +02:00
|
|
|
newFingerprints[newType->className()]=newType->fingerprint();
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const auto &oldType : qAsConst(data.exportedTypes)) {
|
2016-07-08 13:09:56 +02:00
|
|
|
if (newFingerprints.value(oldType->className()) != oldType->fingerprint()) {
|
|
|
|
hasNewInfo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.exportedTypes = exported;
|
|
|
|
data.contextProperties = contextProperties;
|
|
|
|
}
|
|
|
|
return hasNewInfo;
|
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
void ModelManagerInterface::updateCppQmlTypes(
|
|
|
|
QFutureInterface<void> &futureInterface, ModelManagerInterface *qmlModelManager,
|
|
|
|
const CPlusPlus::Snapshot &snapshot,
|
|
|
|
const QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> &documents)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
2017-08-17 11:31:31 +02:00
|
|
|
futureInterface.setProgressRange(0, documents.size());
|
|
|
|
futureInterface.setProgressValue(0);
|
2016-07-08 13:09:56 +02:00
|
|
|
|
|
|
|
CppDataHash newData;
|
2019-10-23 14:03:13 +02:00
|
|
|
QHash<QString, QList<CPlusPlus::Document::Ptr>> newDeclarations;
|
2016-07-08 13:09:56 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&qmlModelManager->m_cppDataMutex);
|
|
|
|
newData = qmlModelManager->m_cppDataHash;
|
|
|
|
newDeclarations = qmlModelManager->m_cppDeclarationFiles;
|
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
FindExportedCppTypes finder(snapshot);
|
|
|
|
|
|
|
|
bool hasNewInfo = false;
|
2019-10-23 14:03:13 +02:00
|
|
|
using DocScanPair = QPair<CPlusPlus::Document::Ptr, bool>;
|
|
|
|
for (const DocScanPair &pair : documents) {
|
2017-08-17 11:31:31 +02:00
|
|
|
if (futureInterface.isCanceled())
|
2014-01-23 14:28:31 +01:00
|
|
|
return;
|
2017-08-17 11:31:31 +02:00
|
|
|
futureInterface.setProgressValue(futureInterface.progressValue() + 1);
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
CPlusPlus::Document::Ptr doc = pair.first;
|
|
|
|
const bool scan = pair.second;
|
|
|
|
const QString fileName = doc->fileName();
|
|
|
|
if (!scan) {
|
2016-07-08 13:09:56 +02:00
|
|
|
hasNewInfo = newData.remove(fileName) > 0 || hasNewInfo;
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto savedDocs = newDeclarations.value(fileName);
|
|
|
|
for (const CPlusPlus::Document::Ptr &savedDoc : savedDocs) {
|
2016-10-28 12:53:24 +02:00
|
|
|
finder(savedDoc);
|
|
|
|
hasNewInfo = rescanExports(savedDoc->fileName(), finder, newData) || hasNewInfo;
|
2016-07-08 13:09:56 +02:00
|
|
|
}
|
2014-01-23 14:28:31 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-07-08 13:09:56 +02:00
|
|
|
for (auto it = newDeclarations.begin(), end = newDeclarations.end(); it != end;) {
|
2016-10-28 12:53:24 +02:00
|
|
|
for (auto docIt = it->begin(), endDocIt = it->end(); docIt != endDocIt;) {
|
2019-10-23 14:03:13 +02:00
|
|
|
const CPlusPlus::Document::Ptr &savedDoc = *docIt;
|
2016-10-28 12:53:24 +02:00
|
|
|
if (savedDoc->fileName() == fileName) {
|
|
|
|
savedDoc->releaseSourceAndAST();
|
|
|
|
it->erase(docIt);
|
|
|
|
break;
|
2014-07-14 18:39:18 +02:00
|
|
|
}
|
2019-10-23 14:03:13 +02:00
|
|
|
++docIt;
|
2014-07-14 18:39:18 +02:00
|
|
|
}
|
2016-10-28 12:53:24 +02:00
|
|
|
if (it->isEmpty())
|
|
|
|
it = newDeclarations.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
2016-07-08 13:09:56 +02:00
|
|
|
}
|
|
|
|
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto found = finder(doc);
|
|
|
|
for (const QString &declarationFile : found) {
|
2016-10-28 12:53:24 +02:00
|
|
|
newDeclarations[declarationFile].append(doc);
|
2016-07-08 13:09:56 +02:00
|
|
|
doc->keepSourceAndAST(); // keep for later reparsing when dependent doc changes
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
2016-10-28 12:53:24 +02:00
|
|
|
hasNewInfo = rescanExports(fileName, finder, newData) || hasNewInfo;
|
2014-01-23 14:28:31 +01:00
|
|
|
doc->releaseSourceAndAST();
|
|
|
|
}
|
|
|
|
|
|
|
|
QMutexLocker locker(&qmlModelManager->m_cppDataMutex);
|
|
|
|
qmlModelManager->m_cppDataHash = newData;
|
2016-07-08 13:09:56 +02:00
|
|
|
qmlModelManager->m_cppDeclarationFiles = newDeclarations;
|
2014-01-23 14:28:31 +01:00
|
|
|
if (hasNewInfo)
|
|
|
|
// one could get away with re-linking the cpp types...
|
2016-01-27 22:36:48 +02:00
|
|
|
QMetaObject::invokeMethod(qmlModelManager, "asyncReset");
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ModelManagerInterface::CppDataHash ModelManagerInterface::cppData() const
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_cppDataMutex);
|
|
|
|
return m_cppDataHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
LibraryInfo ModelManagerInterface::builtins(const Document::Ptr &doc) const
|
|
|
|
{
|
2019-01-17 14:06:53 +01:00
|
|
|
const ProjectInfo info = projectInfoForPath(doc->fileName());
|
2020-04-21 13:46:27 +02:00
|
|
|
if (!info.qtQmlPath.isEmpty())
|
2014-11-24 18:03:23 +01:00
|
|
|
return m_validSnapshot.libraryInfo(info.qtQmlPath);
|
2019-01-17 14:06:53 +01:00
|
|
|
return LibraryInfo();
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
|
2014-04-11 23:07:52 +02:00
|
|
|
const Document::Ptr &doc) const
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
ViewerContext res = vCtx;
|
2014-04-11 23:07:52 +02:00
|
|
|
|
2014-07-01 19:58:23 +02:00
|
|
|
if (!doc.isNull()
|
2014-07-22 19:06:44 +02:00
|
|
|
&& ((vCtx.language == Dialect::AnyLanguage && doc->language() != Dialect::NoLanguage)
|
|
|
|
|| (vCtx.language == Dialect::Qml
|
2018-02-19 12:26:51 +01:00
|
|
|
&& (doc->language() == Dialect::QmlQtQuick2
|
2014-10-13 16:46:30 +02:00
|
|
|
|| doc->language() == Dialect::QmlQtQuick2Ui))))
|
2014-04-11 23:07:52 +02:00
|
|
|
res.language = doc->language();
|
|
|
|
ProjectInfo info;
|
|
|
|
if (!doc.isNull())
|
2014-12-02 13:24:25 +01:00
|
|
|
info = projectInfoForPath(doc->fileName());
|
2019-01-16 14:28:59 +01:00
|
|
|
ViewerContext defaultVCtx = defaultVContext(res.language, Document::Ptr(nullptr), false);
|
2014-04-11 23:07:52 +02:00
|
|
|
ProjectInfo defaultInfo = defaultProjectInfo();
|
|
|
|
if (info.qtQmlPath.isEmpty())
|
|
|
|
info.qtQmlPath = defaultInfo.qtQmlPath;
|
2019-10-22 16:29:40 +02:00
|
|
|
info.applicationDirectories = Utils::filteredUnique(info.applicationDirectories
|
|
|
|
+ defaultInfo.applicationDirectories);
|
2014-01-23 14:28:31 +01:00
|
|
|
switch (res.flags) {
|
|
|
|
case ViewerContext::Complete:
|
|
|
|
break;
|
2014-04-11 23:07:52 +02:00
|
|
|
case ViewerContext::AddAllPathsAndDefaultSelectors:
|
|
|
|
res.selectors.append(defaultVCtx.selectors);
|
2018-01-10 16:51:58 +01:00
|
|
|
Q_FALLTHROUGH();
|
2014-01-23 14:28:31 +01:00
|
|
|
case ViewerContext::AddAllPaths:
|
2014-04-11 23:07:52 +02:00
|
|
|
{
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &path : qAsConst(defaultVCtx.paths))
|
2019-10-23 09:14:58 +02:00
|
|
|
maybeAddPath(res, path);
|
2014-07-22 19:06:44 +02:00
|
|
|
switch (res.language.dialect()) {
|
|
|
|
case Dialect::AnyLanguage:
|
|
|
|
case Dialect::Qml:
|
2019-10-23 09:14:58 +02:00
|
|
|
maybeAddPath(res, info.qtQmlPath);
|
2018-01-10 16:51:58 +01:00
|
|
|
Q_FALLTHROUGH();
|
2014-07-22 19:06:44 +02:00
|
|
|
case Dialect::QmlQtQuick2:
|
2014-10-13 16:46:30 +02:00
|
|
|
case Dialect::QmlQtQuick2Ui:
|
2014-04-11 23:07:52 +02:00
|
|
|
{
|
2014-10-13 16:46:30 +02:00
|
|
|
if (res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui)
|
2019-10-23 09:14:58 +02:00
|
|
|
maybeAddPath(res, info.qtQmlPath);
|
2014-04-11 23:07:52 +02:00
|
|
|
QList<ProjectInfo> allProjects;
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
allProjects = m_projects.values();
|
|
|
|
}
|
|
|
|
std::sort(allProjects.begin(), allProjects.end(), &pInfoLessThanImports);
|
2014-07-22 19:06:44 +02:00
|
|
|
QList<Dialect> languages = res.language.companionLanguages();
|
2019-10-23 14:03:13 +02:00
|
|
|
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());
|
|
|
|
}
|
2014-07-22 19:06:44 +02:00
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto environmentPaths = environmentImportPaths();
|
|
|
|
for (const QString &path : environmentPaths)
|
2019-10-23 09:14:58 +02:00
|
|
|
maybeAddPath(res, path);
|
2014-04-11 23:07:52 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-07-22 19:06:44 +02:00
|
|
|
case Dialect::NoLanguage:
|
|
|
|
case Dialect::JavaScript:
|
|
|
|
case Dialect::QmlTypeInfo:
|
|
|
|
case Dialect::Json:
|
|
|
|
case Dialect::QmlQbs:
|
|
|
|
case Dialect::QmlProject:
|
2014-04-11 23:07:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ViewerContext::AddDefaultPathsAndSelectors:
|
|
|
|
res.selectors.append(defaultVCtx.selectors);
|
2018-01-10 16:51:58 +01:00
|
|
|
Q_FALLTHROUGH();
|
2014-04-11 23:07:52 +02:00
|
|
|
case ViewerContext::AddDefaultPaths:
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const QString &path : qAsConst(defaultVCtx.paths))
|
2019-10-23 09:14:58 +02:00
|
|
|
maybeAddPath(res, path);
|
2018-02-19 12:26:51 +01:00
|
|
|
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml)
|
2019-10-23 09:14:58 +02:00
|
|
|
maybeAddPath(res, info.qtQmlPath);
|
2014-09-16 15:17:21 +02:00
|
|
|
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
2018-02-19 12:26:51 +01:00
|
|
|
|| res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui) {
|
2019-10-23 14:03:13 +02:00
|
|
|
const auto environemntPaths = environmentImportPaths();
|
|
|
|
for (const QString &path : environemntPaths)
|
2019-10-23 09:14:58 +02:00
|
|
|
maybeAddPath(res, path);
|
2014-09-04 11:48:17 +02:00
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
break;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
res.flags = ViewerContext::Complete;
|
2019-10-22 16:29:40 +02:00
|
|
|
res.applicationDirectories = info.applicationDirectories;
|
2014-01-23 14:28:31 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
ViewerContext ModelManagerInterface::defaultVContext(Dialect language,
|
2014-04-11 23:07:52 +02:00
|
|
|
const Document::Ptr &doc,
|
|
|
|
bool autoComplete) const
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
2014-04-11 23:07:52 +02:00
|
|
|
if (!doc.isNull()) {
|
2014-07-22 19:06:44 +02:00
|
|
|
if (language == Dialect::AnyLanguage && doc->language() != Dialect::NoLanguage)
|
2014-04-11 23:07:52 +02:00
|
|
|
language = doc->language();
|
2014-07-22 19:06:44 +02:00
|
|
|
else if (language == Dialect::Qml &&
|
2018-02-19 12:26:51 +01:00
|
|
|
(doc->language() == Dialect::QmlQtQuick2
|
2014-10-13 16:46:30 +02:00
|
|
|
|| doc->language() == Dialect::QmlQtQuick2Ui))
|
2014-04-11 23:07:52 +02:00
|
|
|
language = doc->language();
|
|
|
|
}
|
|
|
|
ViewerContext defaultCtx;
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
defaultCtx = m_defaultVContexts.value(language);
|
|
|
|
}
|
2014-07-01 19:58:23 +02:00
|
|
|
defaultCtx.language = language;
|
2019-10-23 14:03:13 +02:00
|
|
|
return autoComplete ? completeVContext(defaultCtx, doc) : defaultCtx;
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ModelManagerInterface::ProjectInfo ModelManagerInterface::defaultProjectInfo() const
|
|
|
|
{
|
2014-06-30 11:56:28 +02:00
|
|
|
QMutexLocker l(mutex());
|
|
|
|
return m_defaultProjectInfo;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
2014-07-24 11:48:30 +02:00
|
|
|
ModelManagerInterface::ProjectInfo ModelManagerInterface::defaultProjectInfoForProject(
|
|
|
|
ProjectExplorer::Project *) const
|
|
|
|
{
|
|
|
|
return ModelManagerInterface::ProjectInfo();
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
void ModelManagerInterface::setDefaultVContext(const ViewerContext &vContext)
|
|
|
|
{
|
2014-04-11 23:07:52 +02:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
m_defaultVContexts[vContext.language] = vContext;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::joinAllThreads()
|
|
|
|
{
|
2019-10-23 14:03:13 +02:00
|
|
|
for (QFuture<void> &future : m_futures)
|
2014-01-23 14:28:31 +01:00
|
|
|
future.waitForFinished();
|
2016-01-22 11:04:52 +01:00
|
|
|
m_futures.clear();
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
2014-06-26 13:52:36 +02:00
|
|
|
Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &filePath)
|
|
|
|
{
|
|
|
|
QmlJS::Document::Ptr document = newestSnapshot().document(filePath);
|
|
|
|
if (!document) {
|
2014-07-22 19:06:44 +02:00
|
|
|
document = QmlJS::Document::create(filePath, QmlJS::Dialect::Qml);
|
2014-06-26 13:52:36 +02:00
|
|
|
QMutexLocker lock(&m_mutex);
|
|
|
|
|
|
|
|
m_newestSnapshot.insert(document);
|
|
|
|
}
|
|
|
|
|
|
|
|
return document;
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
void ModelManagerInterface::resetCodeModel()
|
|
|
|
{
|
|
|
|
QStringList documents;
|
|
|
|
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
|
|
|
|
// find all documents currently in the code model
|
2019-10-23 14:03:13 +02:00
|
|
|
for (const Document::Ptr &doc : qAsConst(m_validSnapshot))
|
2014-01-23 14:28:31 +01:00
|
|
|
documents.append(doc->fileName());
|
|
|
|
|
|
|
|
// reset the snapshot
|
2014-02-13 11:11:40 +01:00
|
|
|
m_validSnapshot = Snapshot();
|
|
|
|
m_newestSnapshot = Snapshot();
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// start a reparse thread
|
|
|
|
updateSourceFiles(documents, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace QmlJS
|