diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp index 0d575f50246..df8fc02bc01 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp @@ -79,6 +79,18 @@ void addSourceIds(SourceIds &sourceIds, const Storage::ProjectDatas &projectData sourceIds.push_back(projectData.sourceId); } +void addDependencies(Storage::Imports &dependencies, + SourceId sourceId, + const QList &qmldirDependencies, + ProjectStorageInterface &projectStorage) +{ + for (const QmlDirParser::Import &qmldirDependency : qmldirDependencies) { + ModuleId moduleId = projectStorage.moduleId(Utils::PathString{qmldirDependency.module} + + "-cppnative"); + dependencies.emplace_back(moduleId, Storage::Version{}, sourceId); + } +} + } // namespace void ProjectStorageUpdater::update(QStringList qmlDirs, QStringList qmlTypesPaths) @@ -157,6 +169,8 @@ void ProjectStorageUpdater::updateQmldirs(const QStringList &qmlDirs, if (!parser.typeInfos().isEmpty()) { ModuleId cppModuleId = m_projectStorage.moduleId(moduleName + "-cppnative"); parseTypeInfos(parser.typeInfos(), + parser.dependencies(), + parser.imports(), qmlDirSourceId, directoryId, cppModuleId, @@ -195,6 +209,8 @@ void ProjectStorageUpdater::updateQmldirs(const QStringList &qmlDirs, void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector &idPaths) {} void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos, + const QList &qmldirDependencies, + const QList &qmldirImports, SourceId qmldirSourceId, SourceContextId directoryId, ModuleId moduleId, @@ -209,6 +225,10 @@ void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos, {directory, "/", Utils::SmallString{typeInfo}}); SourceId sourceId = m_pathCache.sourceId(SourcePathView{qmltypesPath}); + addDependencies(package.moduleDependencies, sourceId, qmldirDependencies, m_projectStorage); + addDependencies(package.moduleDependencies, sourceId, qmldirImports, m_projectStorage); + package.updatedModuleDependencySourceIds.push_back(sourceId); + auto projectData = package.projectDatas.emplace_back(qmldirSourceId, sourceId, moduleId, diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h index b8222517db6..8da6567cf2e 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h @@ -94,6 +94,8 @@ private: SourceIds ¬UpdatedSourceIds); void parseTypeInfos(const QStringList &typeInfos, + const QList &qmldirDependencies, + const QList &qmldirImports, SourceId qmldirSourceId, SourceContextId directoryId, ModuleId moduleId, diff --git a/tests/unit/unittest/projectstorageupdater-test.cpp b/tests/unit/unittest/projectstorageupdater-test.cpp index 0e598403e9c..b5e407dc2c7 100644 --- a/tests/unit/unittest/projectstorageupdater-test.cpp +++ b/tests/unit/unittest/projectstorageupdater-test.cpp @@ -47,6 +47,7 @@ using QmlDesigner::Storage::TypeAccessSemantics; namespace Storage = QmlDesigner::Storage; using QmlDesigner::IdPaths; using QmlDesigner::Storage::FileType; +using QmlDesigner::Storage::Import; using QmlDesigner::Storage::ProjectData; using QmlDesigner::Storage::SynchronizationPackage; using QmlDesigner::Storage::Version; @@ -130,7 +131,9 @@ MATCHER(PackageIsEmpty, std::string(negation ? "isn't empty" : "is empty")) return package.imports.empty() && package.types.empty() && package.fileStatuses.empty() && package.updatedSourceIds.empty() && package.projectDatas.empty() - && package.updatedFileStatusSourceIds.empty() && package.updatedProjectSourceIds.empty(); + && package.updatedFileStatusSourceIds.empty() && package.updatedProjectSourceIds.empty() + && package.moduleDependencies.empty() && package.updatedModuleDependencySourceIds.empty() + && package.moduleExportedImports.empty() && package.updatedModuleIds.empty(); } class ProjectStorageUpdater : public testing::Test @@ -1044,4 +1047,46 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsWithRelativeFilePath) updater.update(qmlDirs, {}); } +TEST_F(ProjectStorageUpdater, SynchronizeQmldirDependencies) +{ + QString qmldir{R"(module Example + depends Qml + depends QML + typeinfo example.qmltypes + typeinfo types/example2.qmltypes + )"}; + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + + EXPECT_CALL( + projectStorageMock, + synchronize(AllOf( + Field(&SynchronizationPackage::moduleDependencies, + UnorderedElementsAre( + Import{qmlCppNativeModuleId, Storage::Version{}, qmltypesPathSourceId}, + Import{builtinCppNativeModuleId, Storage::Version{}, qmltypesPathSourceId}, + Import{qmlCppNativeModuleId, Storage::Version{}, qmltypes2PathSourceId}, + Import{builtinCppNativeModuleId, Storage::Version{}, qmltypes2PathSourceId})), + Field(&SynchronizationPackage::updatedModuleDependencySourceIds, + UnorderedElementsAre(qmltypesPathSourceId, qmltypes2PathSourceId))))); + + updater.update(qmlDirs, {}); +} + +TEST_F(ProjectStorageUpdater, SynchronizeQmldirWithNoDependencies) +{ + QString qmldir{R"(module Example + typeinfo example.qmltypes + typeinfo types/example2.qmltypes + )"}; + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + + EXPECT_CALL(projectStorageMock, + synchronize( + AllOf(Field(&SynchronizationPackage::moduleDependencies, IsEmpty()), + Field(&SynchronizationPackage::updatedModuleDependencySourceIds, + UnorderedElementsAre(qmltypesPathSourceId, qmltypes2PathSourceId))))); + + updater.update(qmlDirs, {}); +} + } // namespace