QmlJS: Delay loading of default QML type descriptions

We definitely do not need to do this during startup of Qt Creator, delay
to first use.

Change-Id: I5942b5346aedc3d6b677918ad28a6c2924d09493
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Eike Ziller
2023-09-06 10:28:36 +02:00
parent 68d12f0724
commit 7082d2a89b
7 changed files with 40 additions and 13 deletions

View File

@@ -1321,10 +1321,32 @@ const Function *Function::asFunction() const
// typing environment // typing environment
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::defaultLibraryObjects; CppQmlTypesLoader::BuiltinObjects sDefaultLibraryObjects;
CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::defaultQtObjects; CppQmlTypesLoader::BuiltinObjects sDefaultQtObjects;
std::function<void()> CppQmlTypesLoader::defaultObjectsInitializer;
CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInfoList &qmlTypeFiles, QStringList *errors, QStringList *warnings) CppQmlTypesLoader::BuiltinObjects &CppQmlTypesLoader::defaultQtObjects()
{
if (defaultObjectsInitializer) {
const std::function<void()> init = defaultObjectsInitializer;
defaultObjectsInitializer = {};
init();
}
return sDefaultLibraryObjects;
}
CppQmlTypesLoader::BuiltinObjects &CppQmlTypesLoader::defaultLibraryObjects()
{
if (defaultObjectsInitializer) {
const std::function<void()> init = defaultObjectsInitializer;
defaultObjectsInitializer = {};
init();
}
return sDefaultQtObjects;
}
CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInfoList &qmlTypeFiles,
QStringList *errors,
QStringList *warnings)
{ {
QHash<QString, FakeMetaObject::ConstPtr> newObjects; QHash<QString, FakeMetaObject::ConstPtr> newObjects;
QStringList newDependencies; QStringList newDependencies;

View File

@@ -689,8 +689,8 @@ public:
static BuiltinObjects loadQmlTypes(const QFileInfoList &qmltypesFiles, static BuiltinObjects loadQmlTypes(const QFileInfoList &qmltypesFiles,
QStringList *errors, QStringList *warnings); QStringList *errors, QStringList *warnings);
static BuiltinObjects defaultQtObjects; static BuiltinObjects &defaultQtObjects();
static BuiltinObjects defaultLibraryObjects; static BuiltinObjects &defaultLibraryObjects();
// parses the contents of a qmltypes file and fills the newObjects map // parses the contents of a qmltypes file and fills the newObjects map
static void parseQmlTypeDescriptions(const QByteArray &contents, static void parseQmlTypeDescriptions(const QByteArray &contents,
@@ -700,6 +700,8 @@ public:
QString *errorMessage, QString *errorMessage,
QString *warningMessage, QString *warningMessage,
const QString &fileName); const QString &fileName);
static std::function<void()> defaultObjectsInitializer;
}; };
class QMLJS_EXPORT FakeMetaObjectWithOrigin class QMLJS_EXPORT FakeMetaObjectWithOrigin

View File

@@ -196,12 +196,12 @@ Context::ImportsPerDocument LinkPrivate::linkImports()
m_valueOwner->cppQmlTypes().load(QLatin1String("<builtins>"), m_builtins.metaObjects()); m_valueOwner->cppQmlTypes().load(QLatin1String("<builtins>"), m_builtins.metaObjects());
} else { } else {
m_valueOwner->cppQmlTypes().load(QLatin1String("<defaults>"), m_valueOwner->cppQmlTypes().load(QLatin1String("<defaults>"),
CppQmlTypesLoader::defaultQtObjects); CppQmlTypesLoader::defaultQtObjects());
} }
// load library objects shipped with Creator // load library objects shipped with Creator
m_valueOwner->cppQmlTypes().load(QLatin1String("<defaultQt4>"), m_valueOwner->cppQmlTypes().load(QLatin1String("<defaultQt4>"),
CppQmlTypesLoader::defaultLibraryObjects); CppQmlTypesLoader::defaultLibraryObjects());
if (document) { if (document) {
// do it on document first, to make sure import errors are shown // do it on document first, to make sure import errors are shown

View File

@@ -279,8 +279,9 @@ void ModelManagerInterface::loadQmlTypeDescriptionsInternal(const QString &resou
if (qmlTypesFiles.at(i).baseName() == QLatin1String("builtins")) { if (qmlTypesFiles.at(i).baseName() == QLatin1String("builtins")) {
QFileInfoList list; QFileInfoList list;
list.append(qmlTypesFiles.at(i)); list.append(qmlTypesFiles.at(i));
CppQmlTypesLoader::defaultQtObjects = CppQmlTypesLoader::defaultQtObjects() = CppQmlTypesLoader::loadQmlTypes(list,
CppQmlTypesLoader::loadQmlTypes(list, &errors, &warnings); &errors,
&warnings);
qmlTypesFiles.removeAt(i); qmlTypesFiles.removeAt(i);
break; break;
} }
@@ -290,7 +291,7 @@ void ModelManagerInterface::loadQmlTypeDescriptionsInternal(const QString &resou
const CppQmlTypesLoader::BuiltinObjects objs = const CppQmlTypesLoader::BuiltinObjects objs =
CppQmlTypesLoader::loadQmlTypes(qmlTypesFiles, &errors, &warnings); CppQmlTypesLoader::loadQmlTypes(qmlTypesFiles, &errors, &warnings);
for (auto it = objs.cbegin(); it != objs.cend(); ++it) for (auto it = objs.cbegin(); it != objs.cend(); ++it)
CppQmlTypesLoader::defaultLibraryObjects.insert(it.key(), it.value()); CppQmlTypesLoader::defaultLibraryObjects().insert(it.key(), it.value());
for (const QString &error : std::as_const(errors)) for (const QString &error : std::as_const(errors))
writeMessageInternal(error); writeMessageInternal(error);

View File

@@ -261,7 +261,7 @@ QHash<QString,Dialect> ModelManager::languageForSuffix() const
ModelManager::ModelManager() ModelManager::ModelManager()
{ {
qRegisterMetaType<QmlJSTools::SemanticInfo>("QmlJSTools::SemanticInfo"); qRegisterMetaType<QmlJSTools::SemanticInfo>("QmlJSTools::SemanticInfo");
loadDefaultQmlTypeDescriptions(); CppQmlTypesLoader::defaultObjectsInitializer = [this] { loadDefaultQmlTypeDescriptions(); };
} }
ModelManager::~ModelManager() = default; ModelManager::~ModelManager() = default;

View File

@@ -64,7 +64,8 @@ void tst_Check::initTestCase()
// the resource path is wrong, have to load things manually // the resource path is wrong, have to load things manually
QFileInfo builtins(resourcePath() + "/qml-type-descriptions/builtins.qmltypes"); QFileInfo builtins(resourcePath() + "/qml-type-descriptions/builtins.qmltypes");
QStringList errors, warnings; QStringList errors, warnings;
CppQmlTypesLoader::defaultQtObjects = CppQmlTypesLoader::loadQmlTypes(QFileInfoList() << builtins, &errors, &warnings); CppQmlTypesLoader::defaultQtObjects()
= CppQmlTypesLoader::loadQmlTypes(QFileInfoList() << builtins, &errors, &warnings);
if (!ModelManagerInterface::instance()) if (!ModelManagerInterface::instance())
new ModelManagerInterface; new ModelManagerInterface;

View File

@@ -263,7 +263,8 @@ void tst_TestCore::initTestCase()
QFileInfo builtins(IDE_DATA_PATH "/qml-type-descriptions/builtins.qmltypes"); QFileInfo builtins(IDE_DATA_PATH "/qml-type-descriptions/builtins.qmltypes");
QStringList errors, warnings; QStringList errors, warnings;
QmlJS::CppQmlTypesLoader::defaultQtObjects = QmlJS::CppQmlTypesLoader::loadQmlTypes(QFileInfoList{builtins}, &errors, &warnings); QmlJS::CppQmlTypesLoader::defaultQtObjects()
= QmlJS::CppQmlTypesLoader::loadQmlTypes(QFileInfoList{builtins}, &errors, &warnings);
} }
void tst_TestCore::cleanupTestCase() void tst_TestCore::cleanupTestCase()