diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index 34ca7fa672c..98015f81715 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -1379,6 +1379,19 @@ void ModelManagerInterface::joinAllThreads() future.waitForFinished(); } +Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &filePath) +{ + QmlJS::Document::Ptr document = newestSnapshot().document(filePath); + if (!document) { + document = QmlJS::Document::create(filePath, QmlJS::Language::Qml); + QMutexLocker lock(&m_mutex); + + m_newestSnapshot.insert(document); + } + + return document; +} + void ModelManagerInterface::resetCodeModel() { QStringList documents; diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index 425f7bc2eb1..6e53c21746f 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -199,6 +199,9 @@ public: // Blocks until all parsing threads are done. Used for testing. void joinAllThreads(); + + QmlJS::Document::Ptr ensuredGetDocumentForPath(const QString &filePath); + public slots: virtual void resetCodeModel(); void removeProjectInfo(ProjectExplorer::Project *project); diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index 447746f26a0..a251f9c6f21 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -347,22 +347,12 @@ void QmlDesignerPlugin::resetModelSelection() currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList()); } -static QmlJS::Document::Ptr documentForFilePath(const QString &filePath) -{ - QmlJS::Document::Ptr document = QmlJS::ModelManagerInterface::instance()->snapshot().document(filePath); - if (!document) { - document = QmlJS::Document::create(filePath, QmlJS::Language::Qml); - QmlJS::ModelManagerInterface::instance()->snapshot().insert(document); - } - - return document; -} - static bool checkIfEditorIsQtQuick(Core::IEditor *editor) { if (editor) if (editor && editor->document()->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { - QmlJS::Document::Ptr document = documentForFilePath(editor->document()->filePath()); + QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance(); + QmlJS::Document::Ptr document = modelManager->ensuredGetDocumentForPath(editor->document()->filePath()); if (!document.isNull()) return document->language() == QmlJS::Language::QmlQtQuick1 || document->language() == QmlJS::Language::QmlQtQuick2