forked from qt-creator/qt-creator
QmlDesigner: Support qmldir dependencies
Task-number: QDS-6090 Change-Id: Iaca42e4ec314720629148911c8a0f93854572adc Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -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<QmlDirParser::Import> &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> &idPaths) {}
|
||||
|
||||
void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos,
|
||||
const QList<QmlDirParser::Import> &qmldirDependencies,
|
||||
const QList<QmlDirParser::Import> &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,
|
||||
|
@@ -94,6 +94,8 @@ private:
|
||||
SourceIds ¬UpdatedSourceIds);
|
||||
|
||||
void parseTypeInfos(const QStringList &typeInfos,
|
||||
const QList<QmlDirParser::Import> &qmldirDependencies,
|
||||
const QList<QmlDirParser::Import> &qmldirImports,
|
||||
SourceId qmldirSourceId,
|
||||
SourceContextId directoryId,
|
||||
ModuleId moduleId,
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user