forked from qt-creator/qt-creator
QmlDesigner: Support directory style qmldir files
If no module entry is found, it is using the directory name. Change-Id: I7aca4216e66aec55e3cb0b9b0304ef72b78edf32 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
726b45ac94
commit
8dfe50a0a8
@@ -401,6 +401,14 @@ bool isNotExisting(ProjectStorageUpdater::FileState state)
|
||||
return !isExisting(state);
|
||||
}
|
||||
|
||||
Utils::PathString directoryName(std::string_view directoryPath)
|
||||
{
|
||||
using namespace std::views;
|
||||
auto isNotSlash = std::bind_front(std::ranges::not_equal_to{}, '/');
|
||||
auto directoryName = directoryPath | reverse | take_while(isNotSlash) | reverse;
|
||||
return {directoryName.begin(), directoryName.end()};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView directoryPath,
|
||||
@@ -428,6 +436,8 @@ void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView direct
|
||||
|
||||
using Storage::ModuleKind;
|
||||
Utils::PathString moduleName{parser.typeNamespace()};
|
||||
if (moduleName.empty())
|
||||
moduleName = directoryName(directoryPath);
|
||||
ModuleId moduleId = m_projectStorage.moduleId(moduleName, ModuleKind::QmlLibrary);
|
||||
ModuleId cppModuleId = m_projectStorage.moduleId(moduleName, ModuleKind::CppLibrary);
|
||||
ModuleId pathModuleId = m_projectStorage.moduleId(directoryPath, ModuleKind::PathLibrary);
|
||||
|
@@ -1066,6 +1066,31 @@ TEST_F(ProjectStorageUpdater, synchronize_qml_documents)
|
||||
updater.update({.qtDirectories = directories});
|
||||
}
|
||||
|
||||
TEST_F(ProjectStorageUpdater, synchronize_qml_documents_with_missing_module_name)
|
||||
{
|
||||
QString qmldir{R"(FirstType 1.0 First.qml
|
||||
FirstType 2.2 First2.qml
|
||||
SecondType 2.2 Second.qml)"};
|
||||
setContent(u"/path/qmldir", qmldir);
|
||||
ModuleId directoryNameModuleId{storage.moduleId("path", ModuleKind::QmlLibrary)};
|
||||
|
||||
EXPECT_CALL(projectStorageMock,
|
||||
synchronize(AllOf(Field(
|
||||
&SynchronizationPackage::types,
|
||||
Contains(AllOf(IsStorageType("First.qml",
|
||||
ImportedType{"Object"},
|
||||
TypeTraitsKind::Reference,
|
||||
qmlDocumentSourceId1,
|
||||
ChangeLevel::Full),
|
||||
Field("Type::exportedTypes",
|
||||
&Type::exportedTypes,
|
||||
UnorderedElementsAre(
|
||||
IsExportedType(directoryNameModuleId, "FirstType", 1, 0),
|
||||
IsExportedType(pathModuleId, "First", -1, -1)))))))));
|
||||
|
||||
updater.update({.qtDirectories = directories});
|
||||
}
|
||||
|
||||
TEST_F(ProjectStorageUpdater, synchronize_qml_documents_in_project)
|
||||
{
|
||||
QString qmldir{R"(module Example
|
||||
|
Reference in New Issue
Block a user