QmlDesigner: Keep possible imports updated

QmlJS resolves available libraries at its own pace on the background,
which means all possible imports are not necessarily known at the time
the model is attached.
Listen to QmlJS::ModelManagerInterface::libraryInfoUpdated to trigger
reload of document when available libraries change to keep
possible imports list up to date.

Change-Id: Id605a6ee1fe2c43735bb30c9446d2a31ef52fe99
Fixes: QDS-1592
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2020-05-19 11:54:46 +03:00
parent be339abb16
commit a9619b53f3
2 changed files with 20 additions and 2 deletions

View File

@@ -189,6 +189,7 @@ protected: // functions
private: //variables private: //variables
ModelNode nodeAtTextCursorPositionHelper(const ModelNode &root, int cursorPosition) const; ModelNode nodeAtTextCursorPositionHelper(const ModelNode &root, int cursorPosition) const;
void setupCanonicalHashes() const; void setupCanonicalHashes() const;
void handleLibraryInfoUpdate();
TextModifier *m_textModifier = nullptr; TextModifier *m_textModifier = nullptr;
int transactionLevel = 0; int transactionLevel = 0;
@@ -209,6 +210,7 @@ private: //variables
std::function<void(bool)> m_setWidgetStatusCallback; std::function<void(bool)> m_setWidgetStatusCallback;
bool m_hasIncompleteTypeInformation = false; bool m_hasIncompleteTypeInformation = false;
bool m_restoringAuxData = false; bool m_restoringAuxData = false;
bool m_modelAttachPending = false;
mutable QHash<int, ModelNode> m_canonicalIntModelNode; mutable QHash<int, ModelNode> m_canonicalIntModelNode;
mutable QHash<ModelNode, int> m_canonicalModelNodeInt; mutable QHash<ModelNode, int> m_canonicalModelNodeInt;

View File

@@ -70,7 +70,12 @@ RewriterView::RewriterView(DifferenceHandling differenceHandling, QObject *paren
m_textToModelMerger(new Internal::TextToModelMerger(this)) m_textToModelMerger(new Internal::TextToModelMerger(this))
{ {
m_amendTimer.setSingleShot(true); m_amendTimer.setSingleShot(true);
m_amendTimer.setInterval(400);
connect(&m_amendTimer, &QTimer::timeout, this, &RewriterView::amendQmlText); connect(&m_amendTimer, &QTimer::timeout, this, &RewriterView::amendQmlText);
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
connect(modelManager, &QmlJS::ModelManagerInterface::libraryInfoUpdated,
this, &RewriterView::handleLibraryInfoUpdate, Qt::QueuedConnection);
} }
RewriterView::~RewriterView() = default; RewriterView::~RewriterView() = default;
@@ -87,6 +92,8 @@ Internal::TextToModelMerger *RewriterView::textToModelMerger() const
void RewriterView::modelAttached(Model *model) void RewriterView::modelAttached(Model *model)
{ {
m_modelAttachPending = false;
if (model && model->textModifier()) if (model && model->textModifier())
setTextModifier(model->textModifier()); setTextModifier(model->textModifier());
@@ -100,10 +107,12 @@ void RewriterView::modelAttached(Model *model)
if (!(m_errors.isEmpty() && m_warnings.isEmpty())) if (!(m_errors.isEmpty() && m_warnings.isEmpty()))
notifyErrorsAndWarnings(m_errors); notifyErrorsAndWarnings(m_errors);
if (hasIncompleteTypeInformation()) if (hasIncompleteTypeInformation()) {
m_modelAttachPending = true;
QTimer::singleShot(1000, this, [this, model](){ QTimer::singleShot(1000, this, [this, model](){
modelAttached(model); modelAttached(model);
}); });
}
} }
void RewriterView::modelAboutToBeDetached(Model * /*model*/) void RewriterView::modelAboutToBeDetached(Model * /*model*/)
@@ -796,6 +805,13 @@ void RewriterView::setupCanonicalHashes() const
} }
} }
void RewriterView::handleLibraryInfoUpdate()
{
// Trigger dummy amend to reload document when library info changes
if (isAttached() && !m_modelAttachPending)
m_amendTimer.start();
}
ModelNode RewriterView::nodeAtTextCursorPosition(int cursorPosition) const ModelNode RewriterView::nodeAtTextCursorPosition(int cursorPosition) const
{ {
return nodeAtTextCursorPositionHelper(rootModelNode(), cursorPosition); return nodeAtTextCursorPositionHelper(rootModelNode(), cursorPosition);
@@ -995,7 +1011,7 @@ void RewriterView::qmlTextChanged()
auto &viewManager = QmlDesignerPlugin::instance()->viewManager(); auto &viewManager = QmlDesignerPlugin::instance()->viewManager();
if (viewManager.usesRewriterView(this)) { if (viewManager.usesRewriterView(this)) {
QmlDesignerPlugin::instance()->viewManager().disableWidgets(); QmlDesignerPlugin::instance()->viewManager().disableWidgets();
m_amendTimer.start(400); m_amendTimer.start();
} }
#else #else
/*Keep test synchronous*/ /*Keep test synchronous*/