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>
|
|
|
|
#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
|
|
|
|
|
|
|
#include <stdio.h>
|
2014-01-22 18:38:45 +01:00
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
namespace QmlJS {
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-05-27 10:39:50 +02:00
|
|
|
QMLJS_EXPORT Q_LOGGING_CATEGORY(qmljsLog, "qtc.qmljs.common")
|
|
|
|
|
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().
|
|
|
|
*/
|
|
|
|
|
2010-07-08 14:38:47 +02:00
|
|
|
static ModelManagerInterface *g_instance = 0;
|
|
|
|
|
2014-10-13 16:46:30 +02:00
|
|
|
const char qtQuickUISuffix[] = "ui.qml";
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
static QStringList environmentImportPaths()
|
|
|
|
{
|
|
|
|
QStringList paths;
|
|
|
|
|
|
|
|
QByteArray envImportPath = qgetenv("QML_IMPORT_PATH");
|
|
|
|
|
|
|
|
foreach (const QString &path, QString::fromLatin1(envImportPath)
|
|
|
|
.split(Utils::HostOsInfo::pathListSeparator(), QString::SkipEmptyParts)) {
|
|
|
|
QString canonicalPath = QDir(path).canonicalPath();
|
|
|
|
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),
|
|
|
|
m_shouldScanImports(false),
|
2014-06-30 11:56:28 +02:00
|
|
|
m_defaultProject(0),
|
2014-01-23 14:28:31 +01:00
|
|
|
m_pluginDumper(new PluginDumper(this))
|
2010-06-09 15:56:03 +02:00
|
|
|
{
|
2014-09-08 17:59:25 +02:00
|
|
|
m_indexerEnabled = qgetenv("QTC_NO_CODE_INDEXER") != "1";
|
2014-01-23 14:28:31 +01:00
|
|
|
|
|
|
|
m_updateCppQmlTypesTimer = new QTimer(this);
|
|
|
|
m_updateCppQmlTypesTimer->setInterval(1000);
|
|
|
|
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);
|
|
|
|
m_asyncResetTimer->setInterval(15000);
|
|
|
|
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.qtImportsPath = QFileInfo(
|
|
|
|
QLibraryInfo::location(QLibraryInfo::ImportsPath)).canonicalFilePath();
|
|
|
|
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
|
|
|
m_defaultImportPaths << environmentImportPaths();
|
|
|
|
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);
|
|
|
|
g_instance = 0;
|
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
|
|
|
}
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
QStringList ModelManagerInterface::globPatternsForLanguages(const QList<Dialect> languages)
|
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();
|
|
|
|
QStringList patterns;
|
2014-07-22 19:06:44 +02:00
|
|
|
QHashIterator<QString,Dialect> i(lMapping);
|
2014-01-22 18:38:45 +01:00
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::addTaskInternal(QFuture<void> result, const QString &msg,
|
|
|
|
const char *taskId) const
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
|
|
|
foreach (const QString &error, errors)
|
|
|
|
writeMessageInternal(error);
|
|
|
|
foreach (const QString &warning, warnings)
|
|
|
|
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,
|
|
|
|
bool emitDocumentOnDiskChanged)
|
|
|
|
{
|
2014-09-08 17:59:25 +02:00
|
|
|
if (!m_indexerEnabled)
|
|
|
|
return;
|
2014-01-23 14:28:31 +01:00
|
|
|
refreshSourceFiles(files, emitDocumentOnDiskChanged);
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:04:52 +01:00
|
|
|
void ModelManagerInterface::cleanupFutures()
|
|
|
|
{
|
|
|
|
if (m_futures.size() > 10) {
|
|
|
|
QList<QFuture<void> > futures = m_futures;
|
|
|
|
m_futures.clear();
|
|
|
|
foreach (const QFuture<void> &future, futures) {
|
|
|
|
if (!(future.isFinished() || future.isCanceled()))
|
|
|
|
m_futures.append(future);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourceFiles,
|
|
|
|
bool emitDocumentOnDiskChanged)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
foreach (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 {
|
|
|
|
bool pInfoLessThanActive(const ModelManagerInterface::ProjectInfo &p1, const ModelManagerInterface::ProjectInfo &p2)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
else if (s1.at(i) > s2.at(i))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pInfoLessThanAll(const ModelManagerInterface::ProjectInfo &p1, const ModelManagerInterface::ProjectInfo &p2)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
else if (s1.at(i) > s2.at(i))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
|
|
|
|
bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1, const ModelManagerInterface::ProjectInfo &p2)
|
|
|
|
{
|
|
|
|
if (p1.qtQmlPath < p2.qtQmlPath)
|
|
|
|
return true;
|
|
|
|
if (p1.qtQmlPath > p2.qtQmlPath)
|
|
|
|
return false;
|
|
|
|
if (p1.qtImportsPath < p2.qtImportsPath)
|
|
|
|
return true;
|
|
|
|
if (p1.qtImportsPath > p2.qtImportsPath)
|
|
|
|
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;
|
2014-07-22 19:06:44 +02:00
|
|
|
else 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
|
|
|
}
|
|
|
|
|
2016-03-18 17:43:33 +01:00
|
|
|
void ModelManagerInterface::iterateQrcFiles(ProjectExplorer::Project *project,
|
|
|
|
QrcResourceSelector resources,
|
|
|
|
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;
|
|
|
|
foreach (const ModelManagerInterface::ProjectInfo &pInfo, pInfos) {
|
|
|
|
QStringList qrcFilePaths;
|
|
|
|
if (resources == ActiveQrcResources)
|
|
|
|
qrcFilePaths = pInfo.activeResourceFiles;
|
|
|
|
else
|
|
|
|
qrcFilePaths = pInfo.allResourceFiles;
|
|
|
|
foreach (const QString &qrcFilePath, qrcFilePaths) {
|
|
|
|
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;
|
|
|
|
iterateQrcFiles(project, resources, [&](QrcParser::ConstPtr qrcFile) {
|
|
|
|
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;
|
|
|
|
iterateQrcFiles(project, resources, [&](QrcParser::ConstPtr qrcFile) {
|
|
|
|
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;
|
2016-03-18 17:43:33 +01:00
|
|
|
iterateQrcFiles(project, resources, [&](QrcParser::ConstPtr qrcFile) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-06-30 11:56:28 +02:00
|
|
|
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfo(
|
|
|
|
ProjectExplorer::Project *project,
|
|
|
|
const ModelManagerInterface::ProjectInfo &defaultValue) const
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
|
2014-06-30 11:56:28 +02:00
|
|
|
return m_projects.value(project, defaultValue);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p)
|
|
|
|
{
|
2014-09-08 17:59:25 +02:00
|
|
|
if (! pinfo.isValid() || !p || !m_indexerEnabled)
|
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();
|
|
|
|
m_pluginDumper->scheduleMaybeRedumpBuiltins(pinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateImportPaths();
|
|
|
|
|
|
|
|
// remove files that are no longer in the project and have been deleted
|
|
|
|
QStringList deletedFiles;
|
|
|
|
foreach (const QString &oldFile, oldInfo.sourceFiles) {
|
|
|
|
if (snapshot.document(oldFile)
|
|
|
|
&& !pinfo.sourceFiles.contains(oldFile)
|
|
|
|
&& !QFile::exists(oldFile)) {
|
|
|
|
deletedFiles += oldFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeFiles(deletedFiles);
|
|
|
|
foreach (const QString &oldFile, deletedFiles)
|
|
|
|
m_fileToProject.remove(oldFile, p);
|
|
|
|
|
|
|
|
// parse any files not yet in the snapshot
|
|
|
|
QStringList newFiles;
|
|
|
|
foreach (const QString &file, pinfo.sourceFiles) {
|
|
|
|
if (!snapshot.document(file))
|
|
|
|
newFiles += file;
|
|
|
|
}
|
2014-12-02 13:24:25 +01:00
|
|
|
foreach (const QString &newFile, 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;
|
2014-01-23 14:28:31 +01:00
|
|
|
foreach (const QString &newQrc, pinfo.allResourceFiles)
|
2016-10-24 19:30:24 +02:00
|
|
|
m_qrcCache.addPath(newQrc, m_qrcContents.value(newQrc));
|
2014-01-23 14:28:31 +01:00
|
|
|
foreach (const QString &oldQrc, 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;
|
|
|
|
|
2017-03-15 13:16:27 +01:00
|
|
|
if (majorVersion > 4 || (majorVersion == 4 && (minorVersion > 8 || (minorVersion == 8
|
2014-01-23 14:28:31 +01:00
|
|
|
&& patchVersion >= 5)))) {
|
|
|
|
m_pluginDumper->loadBuiltinTypes(pinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(const QString &path) const
|
|
|
|
{
|
|
|
|
QList<ProjectInfo> infos = allProjectInfosForPath(path);
|
|
|
|
|
|
|
|
ProjectInfo res;
|
|
|
|
foreach (const ProjectInfo &pInfo, infos) {
|
|
|
|
if (res.qtImportsPath.isEmpty())
|
|
|
|
res.qtImportsPath = pInfo.qtImportsPath;
|
|
|
|
if (res.qtQmlPath.isEmpty())
|
|
|
|
res.qtQmlPath = pInfo.qtQmlPath;
|
|
|
|
for (int i = 0; i < pInfo.importPaths.size(); ++i)
|
|
|
|
res.importPaths.maybeInsert(pInfo.importPaths.at(i));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns list of project infos for \a path
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
foreach (ProjectExplorer::Project *project, projects) {
|
|
|
|
ProjectInfo info = projectInfo(project);
|
|
|
|
if (info.isValid())
|
|
|
|
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)
|
|
|
|
{ emit documentChangedOnDisk(doc); }
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::updateDocument(Document::Ptr doc)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
static QStringList filesInDirectoryForLanguages(const QString &path, QList<Dialect> languages)
|
2014-01-23 14:28:31 +01:00
|
|
|
{
|
|
|
|
const QStringList pattern = ModelManagerInterface::globPatternsForLanguages(languages);
|
|
|
|
QStringList files;
|
|
|
|
|
|
|
|
const QDir dir(path);
|
|
|
|
foreach (const QFileInfo &fi, dir.entryInfoList(pattern, QDir::Files))
|
|
|
|
files += fi.absoluteFilePath();
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &snapshot,
|
|
|
|
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())) {
|
|
|
|
*importedFiles += filesInDirectoryForLanguages(doc->path(),
|
2014-07-22 19:06:44 +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
|
|
|
|
foreach (const ImportInfo &import, doc->bind()->imports()) {
|
|
|
|
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)) {
|
|
|
|
*importedFiles += filesInDirectoryForLanguages(importName,
|
2014-07-22 19:06:44 +02:00
|
|
|
doc->language().companionLanguages());
|
2014-01-23 14:28:31 +01:00
|
|
|
scannedPaths->insert(importName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (import.type() == ImportType::QrcFile) {
|
|
|
|
QStringList importPaths = ModelManagerInterface::instance()->filesAtQrcPath(importName);
|
|
|
|
foreach (const QString &importPath, importPaths) {
|
|
|
|
if (! snapshot.document(importPath))
|
|
|
|
*importedFiles += importPath;
|
|
|
|
}
|
|
|
|
} else if (import.type() == ImportType::QrcDirectory) {
|
|
|
|
QMapIterator<QString,QStringList> dirContents(ModelManagerInterface::instance()->filesInQrcPath(importName));
|
|
|
|
while (dirContents.hasNext()) {
|
|
|
|
dirContents.next();
|
2014-07-22 19:06:44 +02:00
|
|
|
if (ModelManagerInterface::guessLanguageOfFile(dirContents.key()).isQmlLikeOrJsLanguage()) {
|
2014-01-23 14:28:31 +01:00
|
|
|
foreach (const QString &filePath, dirContents.value()) {
|
|
|
|
if (! snapshot.document(filePath))
|
|
|
|
*importedFiles += filePath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool findNewQmlLibraryInPath(const QString &path,
|
|
|
|
const Snapshot &snapshot,
|
|
|
|
ModelManagerInterface *modelManager,
|
|
|
|
QStringList *importedFiles,
|
|
|
|
QSet<QString> *scannedPaths,
|
|
|
|
QSet<QString> *newLibraries,
|
|
|
|
bool ignoreMissing)
|
|
|
|
{
|
|
|
|
// if we know there is a library, done
|
|
|
|
const LibraryInfo &existingInfo = snapshot.libraryInfo(path);
|
|
|
|
if (existingInfo.isValid())
|
|
|
|
return true;
|
|
|
|
if (newLibraries->contains(path))
|
|
|
|
return true;
|
|
|
|
// if we looked at the path before, done
|
|
|
|
if (existingInfo.wasScanned())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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
|
|
|
|
foreach (const QmlDirParser::Component &component, qmldirParser.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,
|
2014-07-22 19:06:44 +02:00
|
|
|
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,
|
|
|
|
ModelManagerInterface *modelManager,
|
|
|
|
QStringList *importedFiles, QSet<QString> *scannedPaths, QSet<QString> *newLibraries)
|
|
|
|
{
|
|
|
|
// 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();
|
2014-01-23 14:28:31 +01:00
|
|
|
foreach (const ImportInfo &import, doc->bind()->imports()) {
|
|
|
|
if (import.type() == ImportType::Directory) {
|
|
|
|
const QString targetPath = import.path();
|
|
|
|
findNewQmlLibraryInPath(targetPath, snapshot, modelManager,
|
|
|
|
importedFiles, scannedPaths, newLibraries, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (import.type() == ImportType::Library) {
|
2017-09-28 16:24:13 +02:00
|
|
|
const QString libraryPath = modulePath(import, importPaths);
|
|
|
|
if (libraryPath.isEmpty())
|
2014-01-23 14:28:31 +01:00
|
|
|
continue;
|
2017-09-28 16:24:13 +02:00
|
|
|
findNewQmlLibraryInPath(libraryPath, snapshot, modelManager, importedFiles,
|
|
|
|
scannedPaths, newLibraries, false);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
|
|
|
|
QSet<QString> &newLibraries,
|
|
|
|
WorkingCopy workingCopy,
|
|
|
|
QStringList files,
|
|
|
|
ModelManagerInterface *modelManager,
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect mainLanguage,
|
2014-01-23 14:28:31 +01:00
|
|
|
bool emitDocChangedOnDisk,
|
2014-06-27 22:11:09 +02:00
|
|
|
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
|
|
|
|
&& (mainLanguage == Dialect::QmlQtQuick1 || 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths, &newLibraries);
|
|
|
|
|
|
|
|
// add new files to parse list
|
|
|
|
foreach (const QString &file, importedFiles) {
|
|
|
|
if (! files.contains(file))
|
|
|
|
files.append(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
modelManager->updateDocument(doc);
|
|
|
|
if (emitDocChangedOnDisk)
|
|
|
|
modelManager->emitDocumentChangedOnDisk(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FutureReporter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FutureReporter(QFutureInterface<void> &future, int multiplier = 100, int base = 0)
|
|
|
|
:future(future), multiplier(multiplier), base(base)
|
|
|
|
{ }
|
|
|
|
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,
|
|
|
|
WorkingCopy workingCopy,
|
|
|
|
QStringList files,
|
|
|
|
ModelManagerInterface *modelManager,
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect mainLanguage,
|
2014-01-23 14:28:31 +01:00
|
|
|
bool emitDocChangedOnDisk)
|
|
|
|
{
|
|
|
|
FutureReporter reporter(future);
|
|
|
|
future.setProgressRange(0, 100);
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
emitDocChangedOnDisk, reporter);
|
|
|
|
future.setProgressValue(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ScanItem {
|
|
|
|
QString path;
|
|
|
|
int depth;
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect language;
|
|
|
|
ScanItem(QString path = QString(), int depth = 0, Dialect language = Dialect::AnyLanguage)
|
|
|
|
: path(path), depth(depth), language(language)
|
2014-01-23 14:28:31 +01:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
void ModelManagerInterface::importScan(QFutureInterface<void> &future,
|
|
|
|
ModelManagerInterface::WorkingCopy workingCopy,
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages paths, ModelManagerInterface *modelManager,
|
2017-03-07 15:49:02 +01:00
|
|
|
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);
|
2014-07-22 19:06:44 +02:00
|
|
|
for (int i = 0; i < paths.size(); ++i) {
|
|
|
|
PathAndLanguage pAndL = paths.at(i);
|
|
|
|
QString cPath = QDir::cleanPath(pAndL.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;
|
2014-07-22 19:06:44 +02:00
|
|
|
pathsToScan.append(ScanItem(cPath, 0, pAndL.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));
|
|
|
|
int totalWork(progressRange), workDone(0);
|
|
|
|
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,
|
2014-01-23 14:28:31 +01: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,
|
2014-07-22 19:06:44 +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;
|
2014-07-22 19:06:44 +02:00
|
|
|
foreach (const QString path, subDirs)
|
|
|
|
pathsToScan.append(ScanItem(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);
|
2014-07-22 19:06:44 +02:00
|
|
|
for (int i = 0; i < paths.size(); ++i)
|
|
|
|
modelManager->m_scannedPaths.remove(paths.at(i).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
|
|
|
{
|
2014-09-08 17:59:25 +02:00
|
|
|
if (!m_indexerEnabled)
|
|
|
|
return;
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages pathToScan;
|
2014-04-08 11:36:03 +02:00
|
|
|
{
|
|
|
|
QMutexLocker l(&m_mutex);
|
2014-07-22 19:06:44 +02:00
|
|
|
foreach (const PathAndLanguage &importPath, importPaths)
|
|
|
|
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()
|
|
|
|
{
|
2014-09-08 17:59:25 +02:00
|
|
|
if (!m_indexerEnabled)
|
|
|
|
return;
|
2014-07-22 19:06:44 +02:00
|
|
|
PathsAndLanguages allImportPaths;
|
2014-01-23 14:28:31 +01:00
|
|
|
QmlLanguageBundles activeBundles;
|
|
|
|
QmlLanguageBundles extendedBundles;
|
2014-04-11 23:07:52 +02:00
|
|
|
QMapIterator<ProjectExplorer::Project *, ProjectInfo> pInfoIter(m_projects);
|
2014-07-22 19:06:44 +02:00
|
|
|
QHashIterator<Dialect, QmlJS::ViewerContext> vCtxsIter = m_defaultVContexts;
|
2014-04-11 23:07:52 +02:00
|
|
|
while (pInfoIter.hasNext()) {
|
|
|
|
pInfoIter.next();
|
2014-07-22 19:06:44 +02:00
|
|
|
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();
|
2014-01-23 14:28:31 +01:00
|
|
|
if (!canonicalPath.isEmpty())
|
2014-07-22 19:06:44 +02:00
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(canonicalPath),
|
|
|
|
pAndL.language());
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
while (vCtxsIter.hasNext()) {
|
|
|
|
vCtxsIter.next();
|
2014-07-22 19:06:44 +02:00
|
|
|
foreach (const QString &path, vCtxsIter.value().paths)
|
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(path), vCtxsIter.value().language);
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
|
|
|
pInfoIter.toFront();
|
|
|
|
while (pInfoIter.hasNext()) {
|
|
|
|
pInfoIter.next();
|
|
|
|
activeBundles.mergeLanguageBundles(pInfoIter.value().activeBundle);
|
2014-07-22 19:06:44 +02:00
|
|
|
foreach (Dialect l, pInfoIter.value().activeBundle.languages()) {
|
2014-04-11 23:07:52 +02:00
|
|
|
foreach (const QString &path, pInfoIter.value().activeBundle.bundleForLanguage(l)
|
2014-01-23 14:28:31 +01:00
|
|
|
.searchPaths().stringList()) {
|
|
|
|
const QString canonicalPath = QFileInfo(path).canonicalFilePath();
|
|
|
|
if (!canonicalPath.isEmpty())
|
2014-07-22 19:06:44 +02:00
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(canonicalPath), l);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
pInfoIter.toFront();
|
|
|
|
while (pInfoIter.hasNext()) {
|
|
|
|
pInfoIter.next();
|
|
|
|
QString pathAtt = pInfoIter.value().qtQmlPath;
|
2014-07-22 19:06:44 +02:00
|
|
|
if (!pathAtt.isEmpty())
|
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick2);
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
QString pathAtt = defaultProjectInfo().qtQmlPath;
|
2014-07-22 19:06:44 +02:00
|
|
|
if (!pathAtt.isEmpty())
|
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick2);
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
|
|
|
pInfoIter.toFront();
|
|
|
|
while (pInfoIter.hasNext()) {
|
|
|
|
pInfoIter.next();
|
|
|
|
QString pathAtt = pInfoIter.value().qtImportsPath;
|
2014-07-22 19:06:44 +02:00
|
|
|
if (!pathAtt.isEmpty())
|
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick1);
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
QString pathAtt = defaultProjectInfo().qtImportsPath;
|
2014-07-22 19:06:44 +02:00
|
|
|
if (!pathAtt.isEmpty())
|
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(pathAtt), Dialect::QmlQtQuick1);
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
2014-07-22 19:06:44 +02:00
|
|
|
foreach (const QString &path, m_defaultImportPaths)
|
|
|
|
allImportPaths.maybeInsert(Utils::FileName::fromString(path), Dialect::Qml);
|
|
|
|
allImportPaths.compact();
|
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;
|
|
|
|
foreach (const Document::Ptr &doc, snapshot)
|
|
|
|
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
|
|
|
|
|
|
|
|
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()
|
|
|
|
|| data.contextProperties != contextProperties))
|
|
|
|
hasNewInfo = true;
|
|
|
|
if (!hasNewInfo) {
|
|
|
|
QHash<QString, QByteArray> newFingerprints;
|
|
|
|
foreach (LanguageUtils::FakeMetaObject::ConstPtr newType, exported)
|
|
|
|
newFingerprints[newType->className()]=newType->fingerprint();
|
|
|
|
foreach (LanguageUtils::FakeMetaObject::ConstPtr oldType, data.exportedTypes) {
|
|
|
|
if (newFingerprints.value(oldType->className()) != oldType->fingerprint()) {
|
|
|
|
hasNewInfo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.exportedTypes = exported;
|
|
|
|
data.contextProperties = contextProperties;
|
|
|
|
}
|
|
|
|
return hasNewInfo;
|
|
|
|
}
|
|
|
|
|
2017-08-17 11:31:31 +02:00
|
|
|
void ModelManagerInterface::updateCppQmlTypes(QFutureInterface<void> &futureInterface,
|
2014-01-23 14:28:31 +01:00
|
|
|
ModelManagerInterface *qmlModelManager,
|
|
|
|
CPlusPlus::Snapshot snapshot,
|
|
|
|
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > documents)
|
|
|
|
{
|
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;
|
2016-10-28 12:53:24 +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;
|
|
|
|
typedef QPair<CPlusPlus::Document::Ptr, bool> DocScanPair;
|
|
|
|
foreach (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;
|
2016-10-28 12:53:24 +02:00
|
|
|
foreach (const CPlusPlus::Document::Ptr &savedDoc, newDeclarations.value(fileName)) {
|
|
|
|
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;) {
|
|
|
|
CPlusPlus::Document::Ptr &savedDoc = *docIt;
|
|
|
|
if (savedDoc->fileName() == fileName) {
|
|
|
|
savedDoc->releaseSourceAndAST();
|
|
|
|
it->erase(docIt);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
++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
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QString &declarationFile, finder(doc)) {
|
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
|
|
|
|
{
|
2014-12-02 13:24:25 +01:00
|
|
|
ProjectInfo info = projectInfoForPath(doc->fileName());
|
2014-01-23 14:28:31 +01:00
|
|
|
if (!info.isValid())
|
|
|
|
return LibraryInfo();
|
2014-11-24 18:03:23 +01:00
|
|
|
if (!info.qtQmlPath.isEmpty())
|
|
|
|
return m_validSnapshot.libraryInfo(info.qtQmlPath);
|
2014-02-13 11:11:40 +01:00
|
|
|
return m_validSnapshot.libraryInfo(info.qtImportsPath);
|
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
|
|
|
|
&& (doc->language() == Dialect::QmlQtQuick1
|
2014-10-13 16:46:30 +02:00
|
|
|
|| doc->language() == Dialect::QmlQtQuick2
|
|
|
|
|| 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());
|
2014-04-11 23:07:52 +02:00
|
|
|
ViewerContext defaultVCtx = defaultVContext(res.language, Document::Ptr(0), false);
|
|
|
|
ProjectInfo defaultInfo = defaultProjectInfo();
|
|
|
|
if (info.qtImportsPath.isEmpty())
|
|
|
|
info.qtImportsPath = defaultInfo.qtImportsPath;
|
|
|
|
if (info.qtQmlPath.isEmpty())
|
|
|
|
info.qtQmlPath = defaultInfo.qtQmlPath;
|
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);
|
|
|
|
// fallthrough
|
2014-01-23 14:28:31 +01:00
|
|
|
case ViewerContext::AddAllPaths:
|
2014-04-11 23:07:52 +02:00
|
|
|
{
|
|
|
|
foreach (const QString &path, defaultVCtx.paths)
|
|
|
|
res.maybeAddPath(path);
|
2014-07-22 19:06:44 +02:00
|
|
|
switch (res.language.dialect()) {
|
|
|
|
case Dialect::AnyLanguage:
|
|
|
|
case Dialect::Qml:
|
2014-04-11 23:07:52 +02:00
|
|
|
res.maybeAddPath(info.qtQmlPath);
|
|
|
|
// fallthrough
|
2014-07-22 19:06:44 +02:00
|
|
|
case Dialect::QmlQtQuick1:
|
2014-04-11 23:07:52 +02:00
|
|
|
res.maybeAddPath(info.qtImportsPath);
|
|
|
|
// 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)
|
2014-04-11 23:07:52 +02:00
|
|
|
res.maybeAddPath(info.qtQmlPath);
|
|
|
|
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();
|
2014-04-11 23:07:52 +02:00
|
|
|
foreach (const ProjectInfo &pInfo, allProjects) {
|
2014-07-22 19:06:44 +02:00
|
|
|
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))
|
|
|
|
res.maybeAddPath(pAndL.path().toString());
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
}
|
2014-09-04 11:48:17 +02:00
|
|
|
foreach (const QString &path, environmentImportPaths())
|
|
|
|
res.maybeAddPath(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);
|
|
|
|
// fallthrough
|
|
|
|
case ViewerContext::AddDefaultPaths:
|
|
|
|
foreach (const QString &path, defaultVCtx.paths)
|
|
|
|
res.maybeAddPath(path);
|
2014-07-22 19:06:44 +02:00
|
|
|
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
2014-10-13 16:46:30 +02:00
|
|
|
|| res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui)
|
2014-04-11 23:07:52 +02:00
|
|
|
res.maybeAddPath(info.qtImportsPath);
|
2014-07-22 19:06:44 +02:00
|
|
|
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
|
|
|
|| res.language == Dialect::QmlQtQuick1)
|
2014-04-11 23:07:52 +02:00
|
|
|
res.maybeAddPath(info.qtQmlPath);
|
2014-09-16 15:17:21 +02:00
|
|
|
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|
2014-10-13 16:46:30 +02:00
|
|
|
|| res.language == Dialect::QmlQtQuick1 || res.language == Dialect::QmlQtQuick2
|
|
|
|
|| res.language == Dialect::QmlQtQuick2Ui) {
|
2014-09-04 11:48:17 +02:00
|
|
|
foreach (const QString &path, environmentImportPaths())
|
|
|
|
res.maybeAddPath(path);
|
|
|
|
}
|
2014-04-11 23:07:52 +02:00
|
|
|
break;
|
2014-01-23 14:28:31 +01:00
|
|
|
}
|
|
|
|
res.flags = ViewerContext::Complete;
|
|
|
|
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 &&
|
2014-10-13 16:46:30 +02:00
|
|
|
(doc->language() == Dialect::QmlQtQuick1 || doc->language() == Dialect::QmlQtQuick2
|
|
|
|
|| 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;
|
2014-01-23 14:28:31 +01:00
|
|
|
if (autoComplete)
|
2014-04-11 23:07:52 +02:00
|
|
|
return completeVContext(defaultCtx, doc);
|
2014-01-23 14:28:31 +01:00
|
|
|
else
|
2014-04-11 23:07:52 +02:00
|
|
|
return defaultCtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2016-01-22 11:04:52 +01:00
|
|
|
foreach (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
|
2014-02-13 11:11:40 +01:00
|
|
|
foreach (Document::Ptr doc, 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
|