From 2aa7df6dff4725c42fe983f100289c700702a50c Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Thu, 26 Jun 2014 13:52:36 +0200 Subject: [PATCH] QmlJS: Move ensuredGetDocumentForPath to ModelManagerInterface The new function does properly update the latest snapshot. Change-Id: If3148701e2f98c39a0822d1395b43f4fa7ee1949 Reviewed-by: Fawzi Mohamed --- src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 13 +++++++++++++ src/libs/qmljs/qmljsmodelmanagerinterface.h | 3 +++ src/plugins/qmldesigner/qmldesignerplugin.cpp | 14 ++------------ 3 files changed, 18 insertions(+), 12 deletions(-) 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