QmlDesigner: Improve support for project storage aliases

Change-Id: I074aa01e2fc68dea01bece63d13e2688eadbea67
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2024-10-01 17:17:31 +02:00
parent 469194a082
commit e64f3c2703
9 changed files with 26 additions and 23 deletions

View File

@@ -375,6 +375,11 @@ extend_qtc_library(QmlDesignerCore
DEFINES QML_DOM_MSVC2019_COMPAT DEFINES QML_DOM_MSVC2019_COMPAT
) )
extend_qtc_library(QmlDesignerCore
CONDITION WITH_TESTS
PUBLIC_DEFINES QDS_MODEL_USE_PROJECTSTORAGEINTERFACE
)
extend_qtc_library(QmlDesignerCore extend_qtc_library(QmlDesignerCore
SOURCES_PREFIX projectstorage SOURCES_PREFIX projectstorage
PUBLIC_INCLUDES projectstorage PUBLIC_INCLUDES projectstorage

View File

@@ -39,6 +39,8 @@ constexpr bool useProjectStorage()
return false; return false;
#endif #endif
} }
class SourcePathStorage;
using PathCache = SourcePathCache<SourcePathStorage, NonLockingMutex>;
#ifdef QDS_MODEL_USE_PROJECTSTORAGEINTERFACE #ifdef QDS_MODEL_USE_PROJECTSTORAGEINTERFACE
using ProjectStorageType = ProjectStorageInterface; using ProjectStorageType = ProjectStorageInterface;
@@ -46,7 +48,6 @@ class SourcePathCacheInterface;
using PathCacheType = SourcePathCacheInterface; using PathCacheType = SourcePathCacheInterface;
#else #else
using ProjectStorageType = ProjectStorage; using ProjectStorageType = ProjectStorage;
class SourcePathStorage;
using PathCacheType = SourcePathCache<SourcePathStorage, NonLockingMutex>; using PathCacheType = SourcePathCache<SourcePathStorage, NonLockingMutex>;
#endif #endif

View File

@@ -7,6 +7,8 @@
#include "filesysteminterface.h" #include "filesysteminterface.h"
#include "sourcepathstorage/nonlockingmutex.h" #include "sourcepathstorage/nonlockingmutex.h"
#include <modelfwd.h>
namespace QmlDesigner { namespace QmlDesigner {
class SourcePathStorage; class SourcePathStorage;
@@ -16,10 +18,9 @@ class SourcePathCache;
class QMLDESIGNERCORE_EXPORT FileSystem : public FileSystemInterface class QMLDESIGNERCORE_EXPORT FileSystem : public FileSystemInterface
{ {
using PathCache = SourcePathCache<SourcePathStorage, NonLockingMutex>;
public: public:
FileSystem(PathCache &sourcePathCache) FileSystem(PathCacheType &sourcePathCache)
: m_sourcePathCache(sourcePathCache) : m_sourcePathCache(sourcePathCache)
{} {}
@@ -33,7 +34,7 @@ public:
void remove(const SourceIds &sourceIds) override; void remove(const SourceIds &sourceIds) override;
private: private:
PathCache &m_sourcePathCache; PathCacheType &m_sourcePathCache;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -17,7 +17,7 @@ namespace QmlDesigner {
class ProjectStorageInterface class ProjectStorageInterface
{ {
friend Storage::Info::CommonTypeCache<ProjectStorageInterface>; friend Storage::Info::CommonTypeCache<ProjectStorageType>;
public: public:
ProjectStorageInterface(const ProjectStorageInterface &) = delete; ProjectStorageInterface(const ProjectStorageInterface &) = delete;

View File

@@ -41,12 +41,10 @@ class QMLDESIGNERCORE_EXPORT ProjectStorageUpdater final
: public ProjectStoragePathWatcherNotifierInterface : public ProjectStoragePathWatcherNotifierInterface
{ {
public: public:
using PathCache = SourcePathCache<SourcePathStorage, NonLockingMutex>;
ProjectStorageUpdater(FileSystemInterface &fileSystem, ProjectStorageUpdater(FileSystemInterface &fileSystem,
ProjectStorageType &projectStorage, ProjectStorageType &projectStorage,
FileStatusCache &fileStatusCache, FileStatusCache &fileStatusCache,
PathCache &pathCache, PathCacheType &pathCache,
QmlDocumentParserInterface &qmlDocumentParser, QmlDocumentParserInterface &qmlDocumentParser,
QmlTypesParserInterface &qmlTypesParser, QmlTypesParserInterface &qmlTypesParser,
class ProjectStoragePathWatcherInterface &pathWatcher, class ProjectStoragePathWatcherInterface &pathWatcher,
@@ -243,7 +241,7 @@ private:
FileSystemInterface &m_fileSystem; FileSystemInterface &m_fileSystem;
ProjectStorageType &m_projectStorage; ProjectStorageType &m_projectStorage;
FileStatusCache &m_fileStatusCache; FileStatusCache &m_fileStatusCache;
PathCache &m_pathCache; PathCacheType &m_pathCache;
QmlDocumentParserInterface &m_qmlDocumentParser; QmlDocumentParserInterface &m_qmlDocumentParser;
QmlTypesParserInterface &m_qmlTypesParser; QmlTypesParserInterface &m_qmlTypesParser;
ProjectStoragePathWatcherInterface &m_pathWatcher; ProjectStoragePathWatcherInterface &m_pathWatcher;

View File

@@ -66,7 +66,7 @@ Utils::PathString createNormalizedPath(Utils::SmallStringView directoryPath,
Storage::Import createImport(const QmlDom::Import &qmlImport, Storage::Import createImport(const QmlDom::Import &qmlImport,
SourceId sourceId, SourceId sourceId,
Utils::SmallStringView directoryPath, Utils::SmallStringView directoryPath,
QmlDocumentParser::ProjectStorage &storage) ProjectStorageType &storage)
{ {
using Storage::ModuleKind; using Storage::ModuleKind;
using QmlUriKind = QQmlJS::Dom::QmlUri::Kind; using QmlUriKind = QQmlJS::Dom::QmlUri::Kind;
@@ -99,7 +99,7 @@ Storage::Import createImport(const QmlDom::Import &qmlImport,
QualifiedImports createQualifiedImports(const QList<QmlDom::Import> &qmlImports, QualifiedImports createQualifiedImports(const QList<QmlDom::Import> &qmlImports,
SourceId sourceId, SourceId sourceId,
Utils::SmallStringView directoryPath, Utils::SmallStringView directoryPath,
QmlDocumentParser::ProjectStorage &storage) ProjectStorageType &storage)
{ {
NanotraceHR::Tracer tracer{"create qualified imports"_t, NanotraceHR::Tracer tracer{"create qualified imports"_t,
category(), category(),
@@ -123,7 +123,7 @@ void addImports(Storage::Imports &imports,
const QList<QmlDom::Import> &qmlImports, const QList<QmlDom::Import> &qmlImports,
SourceId sourceId, SourceId sourceId,
Utils::SmallStringView directoryPath, Utils::SmallStringView directoryPath,
QmlDocumentParser::ProjectStorage &storage) ProjectStorageType &storage)
{ {
int importCount = 0; int importCount = 0;
for (const QmlDom::Import &qmlImport : qmlImports) { for (const QmlDom::Import &qmlImport : qmlImports) {

View File

@@ -7,8 +7,8 @@
#include "qmldocumentparserinterface.h" #include "qmldocumentparserinterface.h"
#include "sourcepathstorage/nonlockingmutex.h" #include "sourcepathstorage/nonlockingmutex.h"
#include <modelfwd.h>
#include <qmldesignercorelib_exports.h> #include <qmldesignercorelib_exports.h>
namespace QmlDesigner { namespace QmlDesigner {
template<typename Storage, typename Mutex> template<typename Storage, typename Mutex>
@@ -18,11 +18,9 @@ class SourcePathStorage;
class QMLDESIGNERCORE_EXPORT QmlDocumentParser final : public QmlDocumentParserInterface class QMLDESIGNERCORE_EXPORT QmlDocumentParser final : public QmlDocumentParserInterface
{ {
public: public:
using ProjectStorage = QmlDesigner::ProjectStorage;
using PathCache = QmlDesigner::SourcePathCache<SourcePathStorage, NonLockingMutex>;
#ifdef QDS_BUILD_QMLPARSER #ifdef QDS_BUILD_QMLPARSER
QmlDocumentParser(ProjectStorage &storage, PathCache &pathCache) QmlDocumentParser(ProjectStorageType &storage, PathCacheType &pathCache)
: m_storage{storage} : m_storage{storage}
, m_pathCache{pathCache} , m_pathCache{pathCache}
{} {}
@@ -39,8 +37,8 @@ public:
private: private:
// m_pathCache and m_storage are only used when compiled for QDS // m_pathCache and m_storage are only used when compiled for QDS
#ifdef QDS_BUILD_QMLPARSER #ifdef QDS_BUILD_QMLPARSER
ProjectStorage &m_storage; ProjectStorageType &m_storage;
PathCache &m_pathCache; PathCacheType &m_pathCache;
#endif #endif
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -202,7 +202,7 @@ public:
FileStatusCache fileStatusCache{fileSystem}; FileStatusCache fileStatusCache{fileSystem};
QmlDocumentParser qmlDocumentParser; QmlDocumentParser qmlDocumentParser;
QmlTypesParser qmlTypesParser{storage}; QmlTypesParser qmlTypesParser{storage};
ProjectStoragePathWatcher<QFileSystemWatcher, QTimer, ProjectStorageUpdater::PathCache> pathWatcher; ProjectStoragePathWatcher<QFileSystemWatcher, QTimer, PathCacheType> pathWatcher;
ProjectPartId projectPartId; ProjectPartId projectPartId;
ProjectStorageUpdater updater; ProjectStorageUpdater updater;
}; };
@@ -265,7 +265,7 @@ public:
Sqlite::LockingMode::Normal}; Sqlite::LockingMode::Normal};
QmlDesigner::SourcePathStorage sourcePathStorage{sourcePathDatabase, QmlDesigner::SourcePathStorage sourcePathStorage{sourcePathDatabase,
sourcePathDatabase.isInitialized()}; sourcePathDatabase.isInitialized()};
PathCacheType pathCache{sourcePathStorage}; PathCache pathCache{sourcePathStorage};
}; };
QmlDesignerProjectManager::QmlDesignerProjectManager(ExternalDependenciesInterface &externalDependencies) QmlDesignerProjectManager::QmlDesignerProjectManager(ExternalDependenciesInterface &externalDependencies)
@@ -322,12 +322,12 @@ AsynchronousImageCache &QmlDesignerProjectManager::asynchronousImageCache()
} }
namespace { namespace {
[[maybe_unused]] ProjectStorage *dummyProjectStorage() [[maybe_unused]] ProjectStorageType *dummyProjectStorage()
{ {
return nullptr; return nullptr;
} }
[[maybe_unused]] ProjectStorageUpdater::PathCache *dummyPathCache() [[maybe_unused]] PathCacheType *dummyPathCache()
{ {
return nullptr; return nullptr;
} }

View File

@@ -1041,7 +1041,7 @@ TEST_F(Model_MetaInfo, get_meta_info_by_module)
ASSERT_THAT(metaInfo, model.qmlQtObjectMetaInfo()); ASSERT_THAT(metaInfo, model.qmlQtObjectMetaInfo());
} }
TEST_F(Model_MetaInfo, get_invalid_meta_info_by_module_for_wrong_name) TEST_F(Model_MetaInfo, get_invalid_meta_info_by_module_and_name_for_wrong_name)
{ {
auto module = model.module("QML", ModuleKind::QmlLibrary); auto module = model.module("QML", ModuleKind::QmlLibrary);