QmlDesigner: Reset old QMLJS code model when new types are added

Code view warnings/errors still come from the old QMLJS code model,
so we need to reset it after importing new types.

Fixes: QDS-15167
Change-Id: Ifd80f69bac29108702b0d98bfa3c6ac353a12424
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2025-04-11 12:53:30 +03:00
parent 8dbc5475c6
commit 21a6368db5
2 changed files with 15 additions and 5 deletions

View File

@@ -12,9 +12,7 @@
#include <rewritingexception.h> #include <rewritingexception.h>
#include <modelutils.h> #include <modelutils.h>
#ifndef QDS_USE_PROJECTSTORAGE
#include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsmodelmanagerinterface.h>
#endif
#include <utils/async.h> #include <utils/async.h>
#include <QJsonDocument> #include <QJsonDocument>
@@ -54,9 +52,9 @@ QString BundleImporter::importComponent(const QString &bundleDir,
if (!bundleImportPath.exists() && !bundleImportPath.createDir()) if (!bundleImportPath.exists() && !bundleImportPath.createDir())
return QStringLiteral("Failed to create bundle import folder: '%1'").arg(bundleImportPath.toUrlishString()); return QStringLiteral("Failed to create bundle import folder: '%1'").arg(bundleImportPath.toUrlishString());
bool doReset = false;
#ifndef QDS_USE_PROJECTSTORAGE #ifndef QDS_USE_PROJECTSTORAGE
bool doScan = false; bool doScan = false;
bool doReset = false;
#endif #endif
FilePath qmldirPath = bundleImportPath.pathAppended("qmldir"); FilePath qmldirPath = bundleImportPath.pathAppended("qmldir");
QString qmldirContent = QString::fromUtf8(qmldirPath.fileContents().value_or(QByteArray())); QString qmldirContent = QString::fromUtf8(qmldirPath.fileContents().value_or(QByteArray()));
@@ -81,9 +79,7 @@ QString BundleImporter::importComponent(const QString &bundleDir,
qmldirContent.append(qmlFile); qmldirContent.append(qmlFile);
qmldirContent.append('\n'); qmldirContent.append('\n');
qmldirPath.writeFileContents(qmldirContent.toUtf8()); qmldirPath.writeFileContents(qmldirContent.toUtf8());
#ifndef QDS_USE_PROJECTSTORAGE
doReset = true; doReset = true;
#endif
} }
QStringList allFiles; QStringList allFiles;
@@ -129,6 +125,7 @@ QString BundleImporter::importComponent(const QString &bundleDir,
Import import = Import::createLibraryImport(module, "1.0"); Import import = Import::createLibraryImport(module, "1.0");
#ifdef QDS_USE_PROJECTSTORAGE #ifdef QDS_USE_PROJECTSTORAGE
model->changeImports({import}, {}); model->changeImports({import}, {});
m_pendingFullReset = doReset;
#else #else
if (doScan) if (doScan)
data.pathToScan = bundleImportPath; data.pathToScan = bundleImportPath;
@@ -163,6 +160,7 @@ void BundleImporter::handleImportTimer()
auto handleFailure = [this] { auto handleFailure = [this] {
m_importTimer.stop(); m_importTimer.stop();
m_importTimerCount = 0; m_importTimerCount = 0;
m_pendingFullReset = false;
// Emit dummy finished signals for all pending types // Emit dummy finished signals for all pending types
const QList<TypeName> pendingTypes = m_pendingImports.keys(); const QList<TypeName> pendingTypes = m_pendingImports.keys();
@@ -198,6 +196,17 @@ void BundleImporter::handleImportTimer()
} }
} }
if (keys.size() > 0)
return; // Do the code model reset/cleanup on next timer tick
if (m_pendingFullReset) {
m_pendingFullReset = false;
// Force code model reset to notice changes to existing module
auto modelManager = QmlJS::ModelManagerInterface::instance();
if (modelManager)
modelManager->resetCodeModel();
}
if (m_pendingImports.isEmpty()) { if (m_pendingImports.isEmpty()) {
m_bundleId.clear(); m_bundleId.clear();
m_importTimer.stop(); m_importTimer.stop();

View File

@@ -56,6 +56,7 @@ private:
bool isImport = true; // false = unimport bool isImport = true; // false = unimport
TypeName type; TypeName type;
}; };
bool m_pendingFullReset = false; // Reset old QMLJS code model (it's used for code view warnings)
#else #else
struct ImportData struct ImportData
{ {