diff --git a/src/plugins/qmljseditor/qmljscodecompletion.cpp b/src/plugins/qmljseditor/qmljscodecompletion.cpp index 2454502c2e975f3a56c91fc3732c8b2961cf616a..f27ca6bfb0216718b6db8c13fb8d8d3b9d8d99a2 100644 --- a/src/plugins/qmljseditor/qmljscodecompletion.cpp +++ b/src/plugins/qmljseditor/qmljscodecompletion.cpp @@ -678,12 +678,11 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor) m_completions.clear(); const SemanticInfo semanticInfo = edit->semanticInfo(); - const QmlJS::Snapshot snapshot = semanticInfo.snapshot; - const Document::Ptr document = semanticInfo.document; - if (!document) + if (! semanticInfo.isValid()) return -1; + const Document::Ptr document = semanticInfo.document; const QFileInfo currentFileInfo(fileName); bool isQmlFile = false; diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index d1f9832e926b2180db7006a692884dc83381a65c..333a0f1fcddd5d453b085f4615ee6761c4fb2e2b 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -556,6 +556,11 @@ QList<AST::Node *> SemanticInfo::astPath(int cursorPosition) const LookupContext::Ptr SemanticInfo::lookupContext(const QList<QmlJS::AST::Node *> &path) const { + Q_ASSERT(! m_context.isNull()); + + if (m_context.isNull()) + return LookupContext::create(document, snapshot, path); + return LookupContext::create(document, snapshot, *m_context, path); } @@ -610,6 +615,14 @@ AST::Node *SemanticInfo::nodeUnderCursor(int pos) const return 0; } +bool SemanticInfo::isValid() const +{ + if (document && m_context) + return true; + + return false; +} + int SemanticInfo::revision() const { if (document) @@ -1360,6 +1373,9 @@ void QmlJSTextEditor::createToolBar(QmlJSEditorEditable *editable) TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &cursor, bool /*resolveTarget*/) { const SemanticInfo semanticInfo = m_semanticInfo; + if (! semanticInfo.isValid()) + return Link(); + const unsigned cursorPosition = cursor.position(); AST::Node *node = semanticInfo.nodeUnderCursor(cursorPosition); diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 7e83fd8c7c48a048a830f9417ace7c69cc07c536..b95cd0d7efddc6586713831e754c2d25d077ee32 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -121,6 +121,7 @@ class SemanticInfo public: SemanticInfo() {} + bool isValid() const; int revision() const; // Returns the declaring member diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp index 100d8fb34fa4899b4cfb5c953470f09bee7756ad..5e7f24ddf0cf1a4343f5017b4a3e7e2bbea0ac7f 100644 --- a/src/plugins/qmljseditor/qmljshoverhandler.cpp +++ b/src/plugins/qmljseditor/qmljshoverhandler.cpp @@ -110,7 +110,7 @@ void HoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos) if (!matchDiagnosticMessage(qmlEditor, pos)) { const SemanticInfo &semanticInfo = qmlEditor->semanticInfo(); - if (semanticInfo.revision() != qmlEditor->editorRevision()) + if (! semanticInfo.isValid() || semanticInfo.revision() != qmlEditor->editorRevision()) return; QList<AST::Node *> astPath = semanticInfo.astPath(pos); diff --git a/src/plugins/qmljseditor/qmljsmodelmanager.cpp b/src/plugins/qmljseditor/qmljsmodelmanager.cpp index 6bbe8a0b7f2d95563ce5ffc044b939cf9d62d4d5..b6b3ffeb9d9b3c85b740fdb1017d79905297a4e2 100644 --- a/src/plugins/qmljseditor/qmljsmodelmanager.cpp +++ b/src/plugins/qmljseditor/qmljsmodelmanager.cpp @@ -80,7 +80,12 @@ ModelManager::ModelManager(QObject *parent): void ModelManager::loadQmlTypeDescriptions() { - const QString resourcePath = Core::ICore::instance()->resourcePath(); + loadQmlTypeDescriptions(Core::ICore::instance()->resourcePath()); + loadQmlTypeDescriptions(Core::ICore::instance()->userResourcePath()); +} + +void ModelManager::loadQmlTypeDescriptions(const QString &resourcePath) +{ const QDir typeFileDir(resourcePath + QLatin1String("/qml-type-descriptions")); const QStringList xmlExtensions = QStringList() << QLatin1String("*.xml"); const QFileInfoList xmlFiles = typeFileDir.entryInfoList(xmlExtensions, diff --git a/src/plugins/qmljseditor/qmljsmodelmanager.h b/src/plugins/qmljseditor/qmljsmodelmanager.h index 7b5ca21242a8cb1c15f2c47f45540a41add2b13d..b6350f7604ed730d0acc724534b9b9d7ad3aea15 100644 --- a/src/plugins/qmljseditor/qmljsmodelmanager.h +++ b/src/plugins/qmljseditor/qmljsmodelmanager.h @@ -101,6 +101,7 @@ protected: bool emitDocChangedOnDisk); void loadQmlTypeDescriptions(); + void loadQmlTypeDescriptions(const QString &path); void updateImportPaths(); diff --git a/src/plugins/qmljseditor/qmljsquickfix.cpp b/src/plugins/qmljseditor/qmljsquickfix.cpp index 476bf4f488a806d6d0d6bf5dbafad86fc390c65e..3b5ce360f98b7de8fd9a0cb343977c04ab746c5b 100644 --- a/src/plugins/qmljseditor/qmljsquickfix.cpp +++ b/src/plugins/qmljseditor/qmljsquickfix.cpp @@ -136,7 +136,7 @@ TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEdit if (QmlJSTextEditor *qmljsEditor = qobject_cast<QmlJSTextEditor *>(editor)) { const SemanticInfo info = qmljsEditor->semanticInfo(); - if (qmljsEditor->isOutdated()) { + if (! info.isValid() || qmljsEditor->isOutdated()) { // outdated qWarning() << "TODO: outdated semantic info, force a reparse."; return 0; diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp index f6662b9f7509dc6cb525b6be76b72465bee240d6..a04fe75e20140f4d3a6524a2657dde21833f29e9 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.cpp +++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp @@ -330,6 +330,8 @@ Document::Ptr QmlOutlineModel::document() const void QmlOutlineModel::update(const SemanticInfo &semanticInfo) { m_semanticInfo = semanticInfo; + if (! m_semanticInfo.isValid()) + return; m_treePos.clear(); m_treePos.append(0);