forked from qt-creator/qt-creator
QmlDesigner: Fix used imports not working correctly
The existing logic (in qmljsinterpreter.cpp) for updating used imports doesn't work correctly. It takes into consideration items that are not part of the currently open document. Fixed by checking current model items in the document and updating used imports based on it. Fixes: QDS-3785 Change-Id: Ia50c3c7e7ca41b9bca0d69e7c2e253f29892933e Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -212,6 +212,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
|||||||
QString projectName = project ? project->displayName() : "";
|
QString projectName = project ? project->displayName() : "";
|
||||||
|
|
||||||
// create import sections
|
// create import sections
|
||||||
|
const QList<Import> usedImports = model->usedImports();
|
||||||
QHash<QString, ItemLibraryImport *> importHash;
|
QHash<QString, ItemLibraryImport *> importHash;
|
||||||
for (const Import &import : model->imports()) {
|
for (const Import &import : model->imports()) {
|
||||||
if (import.url() != projectName) {
|
if (import.url() != projectName) {
|
||||||
@@ -239,6 +240,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
|||||||
auto sectionType = isQuick3DAsset ? ItemLibraryImport::SectionType::Quick3DAssets
|
auto sectionType = isQuick3DAsset ? ItemLibraryImport::SectionType::Quick3DAssets
|
||||||
: ItemLibraryImport::SectionType::Default;
|
: ItemLibraryImport::SectionType::Default;
|
||||||
ItemLibraryImport *itemLibImport = new ItemLibraryImport(import, this, sectionType);
|
ItemLibraryImport *itemLibImport = new ItemLibraryImport(import, this, sectionType);
|
||||||
|
itemLibImport->setImportUsed(usedImports.contains(import));
|
||||||
importHash.insert(importUrl, itemLibImport);
|
importHash.insert(importUrl, itemLibImport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -934,15 +934,23 @@ void TextToModelMerger::setupUsedImports()
|
|||||||
|
|
||||||
const QList<QmlJS::Import> allImports = imports->all();
|
const QList<QmlJS::Import> allImports = imports->all();
|
||||||
|
|
||||||
|
QSet<QString> usedImportsSet;
|
||||||
QList<Import> usedImports;
|
QList<Import> usedImports;
|
||||||
|
|
||||||
foreach (const QmlJS::Import &import, allImports) {
|
// populate usedImportsSet from current model nodes
|
||||||
if (import.used && !import.info.name().isEmpty()) {
|
const QList<ModelNode> allModelNodes = m_rewriterView->allModelNodes();
|
||||||
if (import.info.type() == ImportType::Library) {
|
for (const ModelNode &modelNode : allModelNodes) {
|
||||||
|
QString type = QString::fromUtf8(modelNode.type());
|
||||||
|
if (type.contains('.'))
|
||||||
|
usedImportsSet.insert(type.left(type.lastIndexOf('.')));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const QmlJS::Import &import : allImports) {
|
||||||
|
if (!import.info.name().isEmpty() && usedImportsSet.contains(import.info.name())) {
|
||||||
|
if (import.info.type() == ImportType::Library)
|
||||||
usedImports.append(Import::createLibraryImport(import.info.name(), import.info.version().toString(), import.info.as()));
|
usedImports.append(Import::createLibraryImport(import.info.name(), import.info.version().toString(), import.info.as()));
|
||||||
} else if (import.info.type() == ImportType::Directory || import.info.type() == ImportType::File) {
|
else if (import.info.type() == ImportType::Directory || import.info.type() == ImportType::File)
|
||||||
usedImports.append(Import::createFileImport(import.info.name(), import.info.version().toString(), import.info.as()));
|
usedImports.append(Import::createFileImport(import.info.name(), import.info.version().toString(), import.info.as()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user