diff --git a/src/plugins/qmldesigner/CMakeLists.txt b/src/plugins/qmldesigner/CMakeLists.txt index 08689e6f417..4e62b72369d 100644 --- a/src/plugins/qmldesigner/CMakeLists.txt +++ b/src/plugins/qmldesigner/CMakeLists.txt @@ -465,6 +465,8 @@ extend_qtc_library(QmlDesignerCore projectstoragetypes.h projectstorageupdater.cpp projectstorageupdater.h projectstorage.cpp projectstorage.h + projectstorageerrornotifierinterface.h + projectstorageerrornotifier.cpp projectstorageerrornotifier.h sourcepath.h sourcepathcache.h sourcepathcacheinterface.h diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp index 3c6636f1f5f..8855c3251ca 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp @@ -1127,8 +1127,11 @@ public: } }; -ProjectStorage::ProjectStorage(Database &database, bool isInitialized) +ProjectStorage::ProjectStorage(Database &database, + ProjectStorageErrorNotifierInterface &errorNotifier, + bool isInitialized) : database{database} + , errorNotifier{errorNotifier} , exclusiveTransaction{database} , initializer{std::make_unique(database, isInitialized)} , moduleCache{ModuleStorageAdapter{*this}} diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index 8f69049f706..a5773448621 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -4,6 +4,7 @@ #pragma once #include "commontypecache.h" +#include "projectstorageerrornotifier.h" #include "projectstorageexceptions.h" #include "projectstorageinterface.h" #include "projectstoragetypes.h" @@ -39,7 +40,9 @@ class ProjectStorage final : public ProjectStorageInterface friend Storage::Info::CommonTypeCache; public: - ProjectStorage(Database &database, bool isInitialized); + ProjectStorage(Database &database, + ProjectStorageErrorNotifierInterface &errorNotifier, + bool isInitialized); ~ProjectStorage(); void synchronize(Storage::Synchronization::SynchronizationPackage package) override; @@ -967,6 +970,7 @@ private: public: Database &database; + ProjectStorageErrorNotifierInterface &errorNotifier; Sqlite::ExclusiveNonThrowingDestructorTransaction exclusiveTransaction; std::unique_ptr initializer; mutable ModuleCache moduleCache{ModuleStorageAdapter{*this}}; diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifier.cpp b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifier.cpp new file mode 100644 index 00000000000..a4705f5eecb --- /dev/null +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifier.cpp @@ -0,0 +1,17 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "projectstorageerrornotifier.h" + +#include "sourcepathcache.h" + +namespace QmlDesigner { + +void ProjectStorageErrorNotifier::typeNameCannotBeResolved(Utils::SmallStringView typeName, + SourceId sourceId) +{ + qDebug() << "Missing type name: " << typeName + << " in file: " << m_pathCache.sourcePath(sourceId).toStringView(); +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifier.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifier.h new file mode 100644 index 00000000000..2695e930193 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifier.h @@ -0,0 +1,25 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "projectstorageerrornotifierinterface.h" + +#include + +namespace QmlDesigner { + +class ProjectStorageErrorNotifier final : public ProjectStorageErrorNotifierInterface +{ +public: + ProjectStorageErrorNotifier(PathCacheType &pathCache) + : m_pathCache{pathCache} + {} + + void typeNameCannotBeResolved(Utils::SmallStringView typeName, SourceId souceId) override; + +private: + PathCacheType &m_pathCache; +}; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifierinterface.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifierinterface.h new file mode 100644 index 00000000000..8136c9d599c --- /dev/null +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageerrornotifierinterface.h @@ -0,0 +1,27 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "projectstorageids.h" + +#include + +namespace QmlDesigner { + +class ProjectStorageErrorNotifierInterface +{ +public: + ProjectStorageErrorNotifierInterface() = default; + ProjectStorageErrorNotifierInterface(ProjectStorageErrorNotifierInterface &&) = default; + ProjectStorageErrorNotifierInterface &operator=(ProjectStorageErrorNotifierInterface &&) = default; + ProjectStorageErrorNotifierInterface(const ProjectStorageErrorNotifierInterface &) = delete; + ProjectStorageErrorNotifierInterface &operator=(const ProjectStorageErrorNotifierInterface &) = delete; + + virtual void typeNameCannotBeResolved(Utils::SmallStringView typeName, SourceId souceId) = 0; + +protected: + ~ProjectStorageErrorNotifierInterface() = default; +}; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp b/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp index 6af4d77974a..730a557d120 100644 --- a/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp +++ b/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp @@ -12,15 +12,16 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include +#include #include #include @@ -181,7 +182,8 @@ public: pathCache.sourceId(SourcePath{project->projectDirectory().toString() + "/."}).internalId())} {} Sqlite::Database database; - ProjectStorage storage{database, database.isInitialized()}; + ProjectStorageErrorNotifier errorNotifier{pathCache}; + ProjectStorage storage{database, errorNotifier, database.isInitialized()}; PathCacheType pathCache{storage}; FileSystem fileSystem{pathCache}; FileStatusCache fileStatusCache{fileSystem}; diff --git a/tests/unit/tests/mocks/CMakeLists.txt b/tests/unit/tests/mocks/CMakeLists.txt index d2090432626..0fdfa639c09 100644 --- a/tests/unit/tests/mocks/CMakeLists.txt +++ b/tests/unit/tests/mocks/CMakeLists.txt @@ -22,6 +22,7 @@ add_qtc_library(TestMocks OBJECT mocktimestampprovider.h modelresourcemanagementmock.h propertycomponentgeneratormock.h + projectstorageerrornotifiermock.h projectstoragemock.cpp projectstoragemock.h projectstorageobservermock.h diff --git a/tests/unit/tests/mocks/projectstorageerrornotifiermock.h b/tests/unit/tests/mocks/projectstorageerrornotifiermock.h new file mode 100644 index 00000000000..28443300cc1 --- /dev/null +++ b/tests/unit/tests/mocks/projectstorageerrornotifiermock.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "../utils/googletest.h" + +#include + +class ProjectStorageErrorNotifierMock : public QmlDesigner::ProjectStorageErrorNotifierInterface +{ + MOCK_METHOD(void, + typeNameCannotBeResolved, + (Utils::SmallStringView typeName, QmlDesigner::SourceId souceId), + (override)); +}; diff --git a/tests/unit/tests/testdesignercore/CMakeLists.txt b/tests/unit/tests/testdesignercore/CMakeLists.txt index ebe7f7df120..c446af81a35 100644 --- a/tests/unit/tests/testdesignercore/CMakeLists.txt +++ b/tests/unit/tests/testdesignercore/CMakeLists.txt @@ -125,6 +125,8 @@ add_qtc_library(TestDesignerCore OBJECT projectstorage/projectstorageinterface.h projectstorage/projectstorageobserver.h projectstorage/projectstorage.cpp projectstorage/projectstorage.h + projectstorage/projectstorageerrornotifierinterface.h + projectstorage/projectstorageerrornotifier.cpp projectstorage/projectstorageerrornotifier.h projectstorage/projectstoragepathwatcher.h projectstorage/projectstoragepathwatcherinterface.h projectstorage/projectstoragepathwatchernotifierinterface.h diff --git a/tests/unit/tests/unittests/projectstorage/projectstorage-test.cpp b/tests/unit/tests/unittests/projectstorage/projectstorage-test.cpp index 230a6cbb21d..c59971fec1c 100644 --- a/tests/unit/tests/unittests/projectstorage/projectstorage-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/projectstorage-test.cpp @@ -5,7 +5,8 @@ #include #include -#include +#include +#include #include #include @@ -274,21 +275,18 @@ MATCHER_P2(IsInfoType, class ProjectStorage : public testing::Test { protected: - static void SetUpTestSuite() + struct StaticData { - static_database = std::make_unique(":memory:", Sqlite::JournalMode::Memory); + Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; + NiceMock errorNotifierMock; + QmlDesigner::ProjectStorage storage{database, errorNotifierMock, database.isInitialized()}; + }; - static_projectStorage = std::make_unique( - *static_database, static_database->isInitialized()); - } + static void SetUpTestSuite() { staticData = std::make_unique(); } - static void TearDownTestSuite() - { - static_projectStorage.reset(); - static_database.reset(); - } + static void TearDownTestSuite() { staticData.reset(); } - ~ProjectStorage() { static_projectStorage->resetForTestsOnly(); } + ~ProjectStorage() { storage.resetForTestsOnly(); } template static auto toValues(Range &&range) @@ -1141,12 +1139,11 @@ protected: } protected: - inline static std::unique_ptr static_database; - Sqlite::Database &database = *static_database; - inline static std::unique_ptr static_projectStorage; - QmlDesigner::ProjectStorage &storage = *static_projectStorage; - QmlDesigner::SourcePathCache sourcePathCache{ - storage}; + inline static std::unique_ptr staticData; + Sqlite::Database &database = staticData->database; + QmlDesigner::ProjectStorage &storage = staticData->storage; + ProjectStorageErrorNotifierMock &errorNotifierMock = staticData->errorNotifierMock; + QmlDesigner::SourcePathCache sourcePathCache{storage}; QmlDesigner::SourcePathView path1{"/path1/to"}; QmlDesigner::SourcePathView path2{"/path2/to"}; QmlDesigner::SourcePathView path3{"/path3/to"}; @@ -5118,7 +5115,7 @@ TEST_F(ProjectStorage, populate_module_cache) { auto id = storage.moduleId("Qml", ModuleKind::QmlLibrary); - QmlDesigner::ProjectStorage newStorage{database, database.isInitialized()}; + QmlDesigner::ProjectStorage newStorage{database, errorNotifierMock, database.isInitialized()}; ASSERT_THAT(newStorage.module(id), IsModule("Qml", ModuleKind::QmlLibrary)); } diff --git a/tests/unit/tests/unittests/projectstorage/projectstoragepathwatcher-test.cpp b/tests/unit/tests/unittests/projectstorage/projectstoragepathwatcher-test.cpp index 26d5af8af8a..771107ece79 100644 --- a/tests/unit/tests/unittests/projectstorage/projectstoragepathwatcher-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/projectstoragepathwatcher-test.cpp @@ -3,10 +3,11 @@ #include "../utils/googletest.h" -#include "../mocks/filesystemmock.h" -#include "../mocks/mockqfilesystemwatcher.h" -#include "../mocks/mocktimer.h" -#include "../mocks/projectstoragepathwatchernotifiermock.h" +#include +#include +#include +#include +#include #include #include @@ -39,21 +40,18 @@ using QmlDesigner::WatcherEntry; class ProjectStoragePathWatcher : public testing::Test { protected: - static void SetUpTestSuite() + struct StaticData { - static_database = std::make_unique(":memory:", Sqlite::JournalMode::Memory); + Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; + ProjectStorageErrorNotifierMock errorNotifierMock; + QmlDesigner::ProjectStorage storage{database, errorNotifierMock, database.isInitialized()}; + }; - static_projectStorage = std::make_unique( - *static_database, static_database->isInitialized()); - } + static void SetUpTestSuite() { staticData = std::make_unique(); } - static void TearDownTestSuite() - { - static_projectStorage.reset(); - static_database.reset(); - } + static void TearDownTestSuite() { staticData.reset(); } - ~ProjectStoragePathWatcher() { static_projectStorage->resetForTestsOnly(); } + ~ProjectStoragePathWatcher() { storage.resetForTestsOnly(); } ProjectStoragePathWatcher() { @@ -79,10 +77,9 @@ protected: protected: NiceMock notifier; NiceMock mockFileSystem; - inline static std::unique_ptr static_database; - Sqlite::Database &database = *static_database; - inline static std::unique_ptr static_projectStorage; - QmlDesigner::ProjectStorage &storage = *static_projectStorage; + inline static std::unique_ptr staticData; + Sqlite::Database &database = staticData->database; + QmlDesigner::ProjectStorage &storage = staticData->storage; SourcePathCache pathCache{storage}; Watcher watcher{pathCache, mockFileSystem, ¬ifier}; NiceMock &mockQFileSytemWatcher = watcher.fileSystemWatcher(); diff --git a/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp b/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp index 7ad09044c6b..e38f05349be 100644 --- a/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp @@ -3,11 +3,12 @@ #include "../utils/googletest.h" -#include "../mocks/filesystemmock.h" -#include "../mocks/projectstoragemock.h" -#include "../mocks/projectstoragepathwatchermock.h" -#include "../mocks/qmldocumentparsermock.h" -#include "../mocks/qmltypesparsermock.h" +#include +#include +#include +#include +#include +#include #include @@ -142,19 +143,16 @@ auto IsPropertyEditorQmlPath(const ModuleIdMatcher &moduleIdMatcher, class ProjectStorageUpdater : public testing::Test { public: - static void SetUpTestSuite() + struct StaticData { - static_database = std::make_unique(":memory:", Sqlite::JournalMode::Memory); + Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; + NiceMock errorNotifierMock; + QmlDesigner::ProjectStorage storage{database, errorNotifierMock, database.isInitialized()}; + }; - static_projectStorage = std::make_unique( - *static_database, static_database->isInitialized()); - } + static void SetUpTestSuite() { staticData = std::make_unique(); } - static void TearDownTestSuite() - { - static_projectStorage.reset(); - static_database.reset(); - } + static void TearDownTestSuite() { staticData.reset(); } ProjectStorageUpdater() { @@ -228,7 +226,7 @@ public: }); } - ~ProjectStorageUpdater() { static_projectStorage->resetForTestsOnly(); } + ~ProjectStorageUpdater() { storage.resetForTestsOnly(); } void setFilesDontChanged(const QmlDesigner::SourceIds &sourceIds) { @@ -327,10 +325,9 @@ protected: NiceMock qmlTypesParserMock; NiceMock qmlDocumentParserMock; QmlDesigner::FileStatusCache fileStatusCache{fileSystemMock}; - inline static std::unique_ptr static_database; - Sqlite::Database &database = *static_database; - inline static std::unique_ptr static_projectStorage; - QmlDesigner::ProjectStorage &storage = *static_projectStorage; + inline static std::unique_ptr staticData; + Sqlite::Database &database = staticData->database; + QmlDesigner::ProjectStorage &storage = staticData->storage; QmlDesigner::SourcePathCache sourcePathCache{ storage}; NiceMock patchWatcherMock; diff --git a/tests/unit/tests/unittests/projectstorage/qmldocumentparser-test.cpp b/tests/unit/tests/unittests/projectstorage/qmldocumentparser-test.cpp index bbe42bab1df..e135bb27bd3 100644 --- a/tests/unit/tests/unittests/projectstorage/qmldocumentparser-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/qmldocumentparser-test.cpp @@ -3,6 +3,8 @@ #include "../utils/googletest.h" +#include + #include #include @@ -144,7 +146,8 @@ class QmlDocumentParser : public ::testing::Test public: protected: Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - QmlDesigner::ProjectStorage storage{database, database.isInitialized()}; + ProjectStorageErrorNotifierMock errorNotifierMock; + QmlDesigner::ProjectStorage storage{database, errorNotifierMock, database.isInitialized()}; QmlDesigner::SourcePathCache sourcePathCache{ storage}; QmlDesigner::QmlDocumentParser parser{storage, sourcePathCache}; diff --git a/tests/unit/tests/unittests/projectstorage/qmltypesparser-test.cpp b/tests/unit/tests/unittests/projectstorage/qmltypesparser-test.cpp index aeb68cc2d6c..e75f7bf3a90 100644 --- a/tests/unit/tests/unittests/projectstorage/qmltypesparser-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/qmltypesparser-test.cpp @@ -3,6 +3,8 @@ #include "../utils/googletest.h" +#include + #include #include @@ -169,7 +171,8 @@ class QmlTypesParser : public ::testing::Test public: protected: Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - QmlDesigner::ProjectStorage storage{database, database.isInitialized()}; + ProjectStorageErrorNotifierMock errorNotifierMock; + QmlDesigner::ProjectStorage storage{database, errorNotifierMock, database.isInitialized()}; QmlDesigner::SourcePathCache sourcePathCache{ storage}; QmlDesigner::QmlTypesParser parser{storage}; diff --git a/tests/unit/tests/unittests/projectstorage/typeannotationreader-test.cpp b/tests/unit/tests/unittests/projectstorage/typeannotationreader-test.cpp index 1a64a4980ec..d55c368f6ee 100644 --- a/tests/unit/tests/unittests/projectstorage/typeannotationreader-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/typeannotationreader-test.cpp @@ -4,6 +4,7 @@ #include "../utils/googletest.h" #include +#include #include #include @@ -26,19 +27,19 @@ protected: traits.hasFormEditorItem = FlagIs::True; traits.visibleInLibrary = FlagIs::True; } - static void SetUpTestSuite() - { - static_database = std::make_unique(":memory:", Sqlite::JournalMode::Memory); - static_projectStorage = std::make_unique( - *static_database, static_database->isInitialized()); - } + ~TypeAnnotationReader() { storage.resetForTestsOnly(); } - static void TearDownTestSuite() + struct StaticData { - static_projectStorage.reset(); - static_database.reset(); - } + Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; + ProjectStorageErrorNotifierMock errorNotifierMock; + QmlDesigner::ProjectStorage storage{database, errorNotifierMock, database.isInitialized()}; + }; + + static void SetUpTestSuite() { staticData = std::make_unique(); } + + static void TearDownTestSuite() { staticData.reset(); } auto moduleId(Utils::SmallStringView name) const { @@ -46,10 +47,9 @@ protected: } protected: - inline static std::unique_ptr static_database; - Sqlite::Database &database = *static_database; - inline static std::unique_ptr static_projectStorage; - QmlDesigner::ProjectStorage &storage = *static_projectStorage; + inline static std::unique_ptr staticData; + Sqlite::Database &database = staticData->database; + QmlDesigner::ProjectStorage &storage = staticData->storage; QmlDesigner::Storage::TypeAnnotationReader reader{storage}; QmlDesigner::SourceId sourceId = QmlDesigner::SourceId::create(33); QmlDesigner::SourceId directorySourceId = QmlDesigner::SourceId::create(77);