From 8b31c4a0ba2f9c4dfc0bdde413e70250946028a0 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Mon, 16 May 2022 15:44:12 +0200 Subject: QmlDesigner: Support optional imports in qmldir optional import Foo Task-number: QDS-6945 Change-Id: Ib1136f4ffb3b7883bf50532dc7fd7cbd1fe04508 Reviewed-by: Thomas Hartmann --- .../projectstorage/projectstorageupdater.cpp | 3 -- tests/unit/unittest/projectstorageupdater-test.cpp | 42 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp index 1c130de81e..7fb1a140e0 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp @@ -145,9 +145,6 @@ void addModuleExportedImports(Storage::ModuleExportedImports &imports, ProjectStorageInterface &projectStorage) { for (const QmlDirParser::Import &qmldirImport : qmldirImports) { - if (qmldirImport.flags & QmlDirParser::Import::Flag::Optional) - continue; - ModuleId exportedModuleId = projectStorage.moduleId(Utils::PathString{qmldirImport.module}); imports.emplace_back(moduleId, exportedModuleId, diff --git a/tests/unit/unittest/projectstorageupdater-test.cpp b/tests/unit/unittest/projectstorageupdater-test.cpp index e9ab6ea4d1..0f5b27dad7 100644 --- a/tests/unit/unittest/projectstorageupdater-test.cpp +++ b/tests/unit/unittest/projectstorageupdater-test.cpp @@ -1258,4 +1258,46 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirImportsWithDoubleEntries) updater.update(qmlDirs, {}); } +TEST_F(ProjectStorageUpdater, SynchronizeQmldirOptionalImports) +{ + QString qmldir{R"(module Example + import Qml auto + import QML 2.1 + optional import Quick + )"}; + ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir)); + + EXPECT_CALL(projectStorageMock, + synchronize( + AllOf(Field(&SynchronizationPackage::moduleExportedImports, + UnorderedElementsAre(ModuleExportedImport{exampleModuleId, + qmlModuleId, + Storage::Version{}, + IsAutoVersion::Yes}, + ModuleExportedImport{exampleCppNativeModuleId, + qmlCppNativeModuleId, + Storage::Version{}, + IsAutoVersion::No}, + ModuleExportedImport{exampleModuleId, + builtinModuleId, + Storage::Version{2, 1}, + IsAutoVersion::No}, + ModuleExportedImport{exampleCppNativeModuleId, + builtinCppNativeModuleId, + Storage::Version{}, + IsAutoVersion::No}, + ModuleExportedImport{exampleModuleId, + quickModuleId, + Storage::Version{}, + IsAutoVersion::No}, + ModuleExportedImport{exampleCppNativeModuleId, + quickCppNativeModuleId, + Storage::Version{}, + IsAutoVersion::No})), + Field(&SynchronizationPackage::updatedModuleIds, + ElementsAre(exampleModuleId))))); + + updater.update(qmlDirs, {}); +} + } // namespace -- cgit v1.2.3