QmlDesigner: Use ModuleId for Type instead of Module

We already know the module id because it's the source id of the module.

Change-Id: Ice241d38c12c7ca79a525464c53b7d552095a0fc
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2021-09-23 14:35:06 +02:00
parent 03687c1d02
commit 9e29b602d4
7 changed files with 1190 additions and 900 deletions

View File

@@ -1274,7 +1274,7 @@ private:
TypeId declareType(Storage::Type &type) TypeId declareType(Storage::Type &type)
{ {
if (type.module.name.isEmpty() && type.typeName.isEmpty()) { if (!type.moduleId && type.typeName.isEmpty()) {
auto [moduleId, typeId] = selectModuleAndTypeIdBySourceIdStatement auto [moduleId, typeId] = selectModuleAndTypeIdBySourceIdStatement
.template value<ModuleAndTypeId>(&type.sourceId); .template value<ModuleAndTypeId>(&type.sourceId);
type.typeId = typeId; type.typeId = typeId;
@@ -1282,8 +1282,6 @@ private:
return type.typeId; return type.typeId;
} }
type.moduleId = fetchModuleIdUnguarded(type.module);
if (!type.moduleId) if (!type.moduleId)
throw ModuleDoesNotExists{}; throw ModuleDoesNotExists{};
@@ -1935,10 +1933,10 @@ public:
"SELECT name, ifnull(majorVersion, -1), ifnull(minorVersion, -1) FROM exportedTypeNames " "SELECT name, ifnull(majorVersion, -1), ifnull(minorVersion, -1) FROM exportedTypeNames "
"WHERE typeId=? AND kind=1", "WHERE typeId=? AND kind=1",
database}; database};
mutable ReadStatement<7> selectTypesStatement{ mutable ReadStatement<6> selectTypesStatement{
"SELECT m.name, m.moduleId, t.name, typeId, (SELECT name FROM types WHERE " "SELECT moduleId, name, typeId, (SELECT name FROM types WHERE "
"typeId=t.prototypeId), accessSemantics, ifnull(sourceId, -1) FROM types AS " "typeId=t.prototypeId), accessSemantics, ifnull(sourceId, -1) FROM types AS "
"t JOIN modules AS m USING (moduleId)", "t",
database}; database};
ReadStatement<1> selectNotUpdatedTypesInSourcesStatement{ ReadStatement<1> selectNotUpdatedTypesInSourcesStatement{
"SELECT typeId FROM types WHERE (sourceId IN carray(?1) AND typeId NOT IN carray(?2))", "SELECT typeId FROM types WHERE (sourceId IN carray(?1) AND typeId NOT IN carray(?2))",

View File

@@ -632,7 +632,7 @@ class Type
{ {
public: public:
explicit Type() = default; explicit Type() = default;
explicit Type(Module module, explicit Type(ModuleId moduleId,
Utils::SmallStringView typeName, Utils::SmallStringView typeName,
ImportedTypeName prototype, ImportedTypeName prototype,
TypeAccessSemantics accessSemantics, TypeAccessSemantics accessSemantics,
@@ -650,26 +650,26 @@ public:
, functionDeclarations{std::move(functionDeclarations)} , functionDeclarations{std::move(functionDeclarations)}
, signalDeclarations{std::move(signalDeclarations)} , signalDeclarations{std::move(signalDeclarations)}
, enumerationDeclarations{std::move(enumerationDeclarations)} , enumerationDeclarations{std::move(enumerationDeclarations)}
, module{std::move(module)} , moduleId{moduleId}
, accessSemantics{accessSemantics} , accessSemantics{accessSemantics}
, sourceId{sourceId} , sourceId{sourceId}
, changeLevel{changeLevel} , changeLevel{changeLevel}
{} {}
explicit Type(Utils::SmallStringView moduleName, explicit Type(ModuleId moduleId,
Utils::SmallStringView typeName, Utils::SmallStringView typeName,
Utils::SmallStringView prototype, Utils::SmallStringView prototype,
int accessSemantics, int accessSemantics,
int sourceId) int sourceId)
: typeName{typeName} : typeName{typeName}
, prototype{NativeType{prototype}} , prototype{NativeType{prototype}}
, module{moduleName} , moduleId{moduleId}
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)} , accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
, sourceId{sourceId} , sourceId{sourceId}
{} {}
explicit Type(Utils::SmallStringView moduleName, explicit Type(int moduleId,
Utils::SmallStringView typeName, Utils::SmallStringView typeName,
long long typeId, long long typeId,
Utils::SmallStringView prototype, Utils::SmallStringView prototype,
@@ -677,22 +677,7 @@ public:
int sourceId) int sourceId)
: typeName{typeName} : typeName{typeName}
, prototype{NativeType{prototype}} , prototype{NativeType{prototype}}
, module{moduleName} , moduleId{moduleId}
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
, sourceId{sourceId}
, typeId{typeId}
{}
explicit Type(Utils::SmallStringView moduleName,
int moduleId,
Utils::SmallStringView typeName,
long long typeId,
Utils::SmallStringView prototype,
int accessSemantics,
int sourceId)
: typeName{typeName}
, prototype{NativeType{prototype}}
, module{moduleName, moduleId}
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)} , accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
, sourceId{sourceId} , sourceId{sourceId}
, typeId{typeId} , typeId{typeId}
@@ -705,7 +690,7 @@ public:
&& first.propertyDeclarations == second.propertyDeclarations && first.propertyDeclarations == second.propertyDeclarations
&& first.functionDeclarations == second.functionDeclarations && first.functionDeclarations == second.functionDeclarations
&& first.signalDeclarations == second.signalDeclarations && first.signalDeclarations == second.signalDeclarations
&& first.module == second.module && first.sourceId == second.sourceId && first.moduleId == second.moduleId && first.sourceId == second.sourceId
&& first.sourceId == second.sourceId; && first.sourceId == second.sourceId;
} }
@@ -717,7 +702,6 @@ public:
FunctionDeclarations functionDeclarations; FunctionDeclarations functionDeclarations;
SignalDeclarations signalDeclarations; SignalDeclarations signalDeclarations;
EnumerationDeclarations enumerationDeclarations; EnumerationDeclarations enumerationDeclarations;
Module module;
TypeAccessSemantics accessSemantics = TypeAccessSemantics::Invalid; TypeAccessSemantics accessSemantics = TypeAccessSemantics::Invalid;
SourceId sourceId; SourceId sourceId;
TypeId typeId; TypeId typeId;

View File

@@ -71,13 +71,12 @@ void ProjectUpdater::update()
sourceIds.push_back(qmlDirSourceId); sourceIds.push_back(qmlDirSourceId);
Utils::SmallString moduleName{parser.typeNamespace()};
SourceContextId directoryId = m_pathCache.sourceContextId(qmlDirSourceId); SourceContextId directoryId = m_pathCache.sourceContextId(qmlDirSourceId);
parseTypeInfos(parser.typeInfos(), directoryId, imports, types, sourceIds, fileStatuses); parseTypeInfos(parser.typeInfos(), directoryId, imports, types, sourceIds, fileStatuses);
parseQmlComponents(createComponentReferences(parser.components()), parseQmlComponents(createComponentReferences(parser.components()),
directoryId, directoryId,
moduleName, ModuleId{&qmlDirSourceId},
imports, imports,
types, types,
sourceIds, sourceIds,
@@ -151,7 +150,7 @@ void ProjectUpdater::parseTypeInfo(SourceId sourceId,
void ProjectUpdater::parseQmlComponents(ComponentReferences components, void ProjectUpdater::parseQmlComponents(ComponentReferences components,
SourceContextId directoryId, SourceContextId directoryId,
Utils::SmallStringView moduleName, ModuleId moduleId,
Storage::Imports &imports, Storage::Imports &imports,
Storage::Types &types, Storage::Types &types,
SourceIds &sourceIds, SourceIds &sourceIds,
@@ -184,7 +183,7 @@ void ProjectUpdater::parseQmlComponents(ComponentReferences components,
auto type = m_qmlDocumentParser.parse(content, imports); auto type = m_qmlDocumentParser.parse(content, imports);
type.typeName = fileName; type.typeName = fileName;
type.module.name = moduleName; type.moduleId = moduleId;
type.accessSemantics = Storage::TypeAccessSemantics::Reference; type.accessSemantics = Storage::TypeAccessSemantics::Reference;
type.sourceId = sourceId; type.sourceId = sourceId;
type.exportedTypes.push_back( type.exportedTypes.push_back(

View File

@@ -105,7 +105,7 @@ private:
FileStatuses &fileStatuses); FileStatuses &fileStatuses);
void parseQmlComponents(ComponentReferences components, void parseQmlComponents(ComponentReferences components,
SourceContextId directoryId, SourceContextId directoryId,
Utils::SmallStringView moduleName, ModuleId moduleId,
Storage::Imports &imports, Storage::Imports &imports,
Storage::Types &types, Storage::Types &types,
SourceIds &sourceIds, SourceIds &sourceIds,

View File

@@ -1101,7 +1101,7 @@ std::ostream &operator<<(std::ostream &out, const QualifiedImportedType &importe
std::ostream &operator<<(std::ostream &out, const Type &type) std::ostream &operator<<(std::ostream &out, const Type &type)
{ {
using Utils::operator<<; using Utils::operator<<;
return out << "(module: " << type.module << ", typename: \"" << type.typeName return out << "(moduleId: " << type.moduleId << ", typename: \"" << type.typeName
<< "\", prototype: " << type.prototype << ", " << type.accessSemantics << "\", prototype: " << type.prototype << ", " << type.accessSemantics
<< ", source: " << type.sourceId << ", exports: " << type.exportedTypes << ", source: " << type.sourceId << ", exports: " << type.exportedTypes
<< ", properties: " << type.propertyDeclarations << ", properties: " << type.propertyDeclarations

File diff suppressed because it is too large Load Diff

View File

@@ -49,17 +49,17 @@ using QmlDesigner::IdPaths;
using QmlDesigner::Storage::Version; using QmlDesigner::Storage::Version;
MATCHER_P5(IsStorageType, MATCHER_P5(IsStorageType,
module, moduleId,
typeName, typeName,
prototype, prototype,
accessSemantics, accessSemantics,
sourceId, sourceId,
std::string(negation ? "isn't " : "is ") std::string(negation ? "isn't " : "is ")
+ PrintToString(Storage::Type{module, typeName, prototype, accessSemantics, sourceId})) + PrintToString(Storage::Type{moduleId, typeName, prototype, accessSemantics, sourceId}))
{ {
const Storage::Type &type = arg; const Storage::Type &type = arg;
return type.module == module && type.typeName == typeName return type.moduleId == moduleId && type.typeName == typeName
&& type.accessSemantics == accessSemantics && type.sourceId == sourceId && type.accessSemantics == accessSemantics && type.sourceId == sourceId
&& Storage::ImportedTypeName{prototype} == type.prototype; && Storage::ImportedTypeName{prototype} == type.prototype;
} }
@@ -199,18 +199,20 @@ protected:
qmlDocumentParserMock, qmlDocumentParserMock,
qmlTypesParserMock}; qmlTypesParserMock};
SourceId objectTypeSourceId{sourcePathCache.sourceId("/path/Object")}; SourceId objectTypeSourceId{sourcePathCache.sourceId("/path/Object")};
Storage::Type objectType{Storage::Module{"Qml"},
SourceId qmltypesPathSourceId = sourcePathCache.sourceId("/path/example.qmltypes");
SourceId qmltypes2PathSourceId = sourcePathCache.sourceId("/path/example2.qmltypes");
SourceId qmlDirPathSourceId = sourcePathCache.sourceId("/path/qmldir");
QmlDesigner::ModuleId exampleModuleId{&qmlDirPathSourceId};
SourceId qmlDocumentSourceId1 = sourcePathCache.sourceId("/path/First.qml");
SourceId qmlDocumentSourceId2 = sourcePathCache.sourceId("/path/First.2.qml");
SourceId qmlDocumentSourceId3 = sourcePathCache.sourceId("/path/Second.qml");
Storage::Type objectType{exampleModuleId,
"QObject", "QObject",
Storage::NativeType{}, Storage::NativeType{},
Storage::TypeAccessSemantics::Reference, Storage::TypeAccessSemantics::Reference,
objectTypeSourceId, objectTypeSourceId,
{Storage::ExportedType{"Object"}, Storage::ExportedType{"Obj"}}}; {Storage::ExportedType{"Object"}, Storage::ExportedType{"Obj"}}};
SourceId qmltypesPathSourceId = sourcePathCache.sourceId("/path/example.qmltypes");
SourceId qmltypes2PathSourceId = sourcePathCache.sourceId("/path/example2.qmltypes");
SourceId qmlDirPathSourceId = sourcePathCache.sourceId("/path/qmldir");
SourceId qmlDocumentSourceId1 = sourcePathCache.sourceId("/path/First.qml");
SourceId qmlDocumentSourceId2 = sourcePathCache.sourceId("/path/First.2.qml");
SourceId qmlDocumentSourceId3 = sourcePathCache.sourceId("/path/Second.qml");
QString qmlDocument1{"First{}"}; QString qmlDocument1{"First{}"};
QString qmlDocument2{"Second{}"}; QString qmlDocument2{"Second{}"};
QString qmlDocument3{"Third{}"}; QString qmlDocument3{"Third{}"};
@@ -417,21 +419,21 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocuments)
synchronize(ElementsAre(IsModule("Example", qmlDirPathSourceId)), synchronize(ElementsAre(IsModule("Example", qmlDirPathSourceId)),
UnorderedElementsAre(import1, import2, import3), UnorderedElementsAre(import1, import2, import3),
UnorderedElementsAre( UnorderedElementsAre(
AllOf(IsStorageType(Storage::Module{"Example"}, AllOf(IsStorageType(exampleModuleId,
"First.qml", "First.qml",
Storage::ImportedType{"Object"}, Storage::ImportedType{"Object"},
TypeAccessSemantics::Reference, TypeAccessSemantics::Reference,
qmlDocumentSourceId1), qmlDocumentSourceId1),
Field(&Storage::Type::exportedTypes, Field(&Storage::Type::exportedTypes,
ElementsAre(IsExportedType("FirstType", 1, 0)))), ElementsAre(IsExportedType("FirstType", 1, 0)))),
AllOf(IsStorageType(Storage::Module{"Example"}, AllOf(IsStorageType(exampleModuleId,
"First.2.qml", "First.2.qml",
Storage::ImportedType{"Object2"}, Storage::ImportedType{"Object2"},
TypeAccessSemantics::Reference, TypeAccessSemantics::Reference,
qmlDocumentSourceId2), qmlDocumentSourceId2),
Field(&Storage::Type::exportedTypes, Field(&Storage::Type::exportedTypes,
ElementsAre(IsExportedType("FirstType", 2, 2)))), ElementsAre(IsExportedType("FirstType", 2, 2)))),
AllOf(IsStorageType(Storage::Module{"Example"}, AllOf(IsStorageType(exampleModuleId,
"Second.qml", "Second.qml",
Storage::ImportedType{"Object3"}, Storage::ImportedType{"Object3"},
TypeAccessSemantics::Reference, TypeAccessSemantics::Reference,
@@ -462,14 +464,14 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsDontUpdateIfUpToDate)
projectStorageMock, projectStorageMock,
synchronize(ElementsAre(IsModule("Example", qmlDirPathSourceId)), synchronize(ElementsAre(IsModule("Example", qmlDirPathSourceId)),
UnorderedElementsAre(import1, import2), UnorderedElementsAre(import1, import2),
UnorderedElementsAre(AllOf(IsStorageType(Storage::Module{"Example"}, UnorderedElementsAre(AllOf(IsStorageType(exampleModuleId,
"First.qml", "First.qml",
Storage::ImportedType{"Object"}, Storage::ImportedType{"Object"},
TypeAccessSemantics::Reference, TypeAccessSemantics::Reference,
qmlDocumentSourceId1), qmlDocumentSourceId1),
Field(&Storage::Type::exportedTypes, Field(&Storage::Type::exportedTypes,
ElementsAre(IsExportedType("FirstType", 1, 0)))), ElementsAre(IsExportedType("FirstType", 1, 0)))),
AllOf(IsStorageType(Storage::Module{"Example"}, AllOf(IsStorageType(exampleModuleId,
"First.2.qml", "First.2.qml",
Storage::ImportedType{"Object2"}, Storage::ImportedType{"Object2"},
TypeAccessSemantics::Reference, TypeAccessSemantics::Reference,
@@ -509,4 +511,15 @@ TEST_F(ProjectStorageUpdater, SynchronizeModules)
updater.update(); updater.update();
} }
TEST_F(ProjectStorageUpdater, UpdateQmldirDocuments)
{
QString qmldir{"module Example\nFirstType 1.1 First.qml\nFirstType 2.2 "
"First.2.qml\nSecondType 2.1 OldSecond.qml\nSecondType 2.2 Second.qml\n"};
ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir));
ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmlDocumentSourceId3)))
.WillByDefault(Return(FileStatus{qmlDocumentSourceId3, 22, 14}));
updater.pathsWithIdsChanged({});
}
} // namespace } // namespace