forked from qt-creator/qt-creator
Introduced SemanticInfo::isValid().
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -121,6 +121,7 @@ class SemanticInfo
|
||||
public:
|
||||
SemanticInfo() {}
|
||||
|
||||
bool isValid() const;
|
||||
int revision() const;
|
||||
|
||||
// Returns the declaring member
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -101,6 +101,7 @@ protected:
|
||||
bool emitDocChangedOnDisk);
|
||||
|
||||
void loadQmlTypeDescriptions();
|
||||
void loadQmlTypeDescriptions(const QString &path);
|
||||
|
||||
void updateImportPaths();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user