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);
|
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
|
} // namespace
|
||||||
|
|
||||||
void ProjectStorageUpdater::update(QStringList qmlDirs, QStringList qmlTypesPaths)
|
void ProjectStorageUpdater::update(QStringList qmlDirs, QStringList qmlTypesPaths)
|
||||||
@@ -157,6 +169,8 @@ void ProjectStorageUpdater::updateQmldirs(const QStringList &qmlDirs,
|
|||||||
if (!parser.typeInfos().isEmpty()) {
|
if (!parser.typeInfos().isEmpty()) {
|
||||||
ModuleId cppModuleId = m_projectStorage.moduleId(moduleName + "-cppnative");
|
ModuleId cppModuleId = m_projectStorage.moduleId(moduleName + "-cppnative");
|
||||||
parseTypeInfos(parser.typeInfos(),
|
parseTypeInfos(parser.typeInfos(),
|
||||||
|
parser.dependencies(),
|
||||||
|
parser.imports(),
|
||||||
qmlDirSourceId,
|
qmlDirSourceId,
|
||||||
directoryId,
|
directoryId,
|
||||||
cppModuleId,
|
cppModuleId,
|
||||||
@@ -195,6 +209,8 @@ void ProjectStorageUpdater::updateQmldirs(const QStringList &qmlDirs,
|
|||||||
void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &idPaths) {}
|
void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &idPaths) {}
|
||||||
|
|
||||||
void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos,
|
void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos,
|
||||||
|
const QList<QmlDirParser::Import> &qmldirDependencies,
|
||||||
|
const QList<QmlDirParser::Import> &qmldirImports,
|
||||||
SourceId qmldirSourceId,
|
SourceId qmldirSourceId,
|
||||||
SourceContextId directoryId,
|
SourceContextId directoryId,
|
||||||
ModuleId moduleId,
|
ModuleId moduleId,
|
||||||
@@ -209,6 +225,10 @@ void ProjectStorageUpdater::parseTypeInfos(const QStringList &typeInfos,
|
|||||||
{directory, "/", Utils::SmallString{typeInfo}});
|
{directory, "/", Utils::SmallString{typeInfo}});
|
||||||
SourceId sourceId = m_pathCache.sourceId(SourcePathView{qmltypesPath});
|
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,
|
auto projectData = package.projectDatas.emplace_back(qmldirSourceId,
|
||||||
sourceId,
|
sourceId,
|
||||||
moduleId,
|
moduleId,
|
||||||
|
@@ -94,6 +94,8 @@ private:
|
|||||||
SourceIds ¬UpdatedSourceIds);
|
SourceIds ¬UpdatedSourceIds);
|
||||||
|
|
||||||
void parseTypeInfos(const QStringList &typeInfos,
|
void parseTypeInfos(const QStringList &typeInfos,
|
||||||
|
const QList<QmlDirParser::Import> &qmldirDependencies,
|
||||||
|
const QList<QmlDirParser::Import> &qmldirImports,
|
||||||
SourceId qmldirSourceId,
|
SourceId qmldirSourceId,
|
||||||
SourceContextId directoryId,
|
SourceContextId directoryId,
|
||||||
ModuleId moduleId,
|
ModuleId moduleId,
|
||||||
|
@@ -47,6 +47,7 @@ using QmlDesigner::Storage::TypeAccessSemantics;
|
|||||||
namespace Storage = QmlDesigner::Storage;
|
namespace Storage = QmlDesigner::Storage;
|
||||||
using QmlDesigner::IdPaths;
|
using QmlDesigner::IdPaths;
|
||||||
using QmlDesigner::Storage::FileType;
|
using QmlDesigner::Storage::FileType;
|
||||||
|
using QmlDesigner::Storage::Import;
|
||||||
using QmlDesigner::Storage::ProjectData;
|
using QmlDesigner::Storage::ProjectData;
|
||||||
using QmlDesigner::Storage::SynchronizationPackage;
|
using QmlDesigner::Storage::SynchronizationPackage;
|
||||||
using QmlDesigner::Storage::Version;
|
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()
|
return package.imports.empty() && package.types.empty() && package.fileStatuses.empty()
|
||||||
&& package.updatedSourceIds.empty() && package.projectDatas.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
|
class ProjectStorageUpdater : public testing::Test
|
||||||
@@ -1044,4 +1047,46 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsWithRelativeFilePath)
|
|||||||
updater.update(qmlDirs, {});
|
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
|
} // namespace
|
||||||
|
Reference in New Issue
Block a user