From 6fe1f5b96cbec86c0b40f014705f4c06925e827e Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Thu, 28 Jan 2010 16:29:45 +0100 Subject: [PATCH] Made the error recovering more robust. --- src/libs/qmljs/qmljsbind.cpp | 4 ++- src/plugins/qmljseditor/qmlcodecompletion.cpp | 29 ++++--------------- src/plugins/qmljseditor/qmljseditor.cpp | 14 +++++---- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp index e82e3b044be..3ee0fde7c6d 100644 --- a/src/libs/qmljs/qmljsbind.cpp +++ b/src/libs/qmljs/qmljsbind.cpp @@ -87,7 +87,9 @@ ObjectValue *Bind::scopeChainAt(Document::Ptr currentDocument, const Snapshot &s } LinkImports()(binds); - ObjectValue *scope = Link()(binds, currentBind, currentObject); + ObjectValue *scope = interp->globalObject(); + if (currentBind) + scope = Link()(binds, currentBind, currentObject); qDeleteAll(binds); return scope; diff --git a/src/plugins/qmljseditor/qmlcodecompletion.cpp b/src/plugins/qmljseditor/qmlcodecompletion.cpp index ef2a6c03dee..28bb8d1194e 100644 --- a/src/plugins/qmljseditor/qmlcodecompletion.cpp +++ b/src/plugins/qmljseditor/qmlcodecompletion.cpp @@ -607,36 +607,15 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) return -1; const QFileInfo currentFileInfo(fileName); - const QString currentFilePath = currentFileInfo.absolutePath(); bool isQmlFile = false; if (currentFileInfo.suffix() == QLatin1String("qml")) isQmlFile = true; - const QIcon componentIcon = iconForColor(Qt::yellow); const QIcon symbolIcon = iconForColor(Qt::darkCyan); Interpreter::Engine interp; - QHash<QString, Document::Ptr> userComponents; // #### - - foreach (Document::Ptr doc, snapshot) { - const QFileInfo fileInfo(doc->fileName()); - const QString absolutePath = fileInfo.absolutePath(); - - // ### generalize - if (fileInfo.suffix() != QLatin1String("qml")) - continue; - else if (absolutePath != currentFilePath && ! isImported(qmlDocument, absolutePath)) - continue; - - const QString typeName = fileInfo.baseName(); - if (typeName.isEmpty() || ! typeName.at(0).isUpper()) - continue; - - userComponents.insert(typeName, doc); - } - // Set up the current scope chain. Interpreter::ObjectValue *scope = interp.globalObject(); @@ -644,9 +623,13 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) AST::UiObjectMember *declaringMember = 0; const int cursorPosition = editor->position(); - foreach (const Range &range, semanticInfo.ranges) { - if (cursorPosition >= range.begin.position() && cursorPosition <= range.end.position()) { + for (int i = semanticInfo.ranges.size() - 1; i != -1; --i) { + const Range &range = semanticInfo.ranges.at(i); + if (range.begin.isNull() || range.end.isNull()) { + continue; + } else if (cursorPosition >= range.begin.position() && cursorPosition <= range.end.position()) { declaringMember = range.ast; + break; } } diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index d06f03fb810..593ca9eb895 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -397,27 +397,29 @@ protected: virtual bool visit(AST::UiObjectBinding *ast) { - _ranges.append(createRange(ast)); + if (ast->initializer) + _ranges.append(createRange(ast, ast->initializer)); return true; } virtual bool visit(AST::UiObjectDefinition *ast) { - _ranges.append(createRange(ast)); + if (ast->initializer) + _ranges.append(createRange(ast, ast->initializer)); return true; } - Range createRange(AST::UiObjectMember *ast) + Range createRange(AST::UiObjectMember *member, AST::UiObjectInitializer *ast) { Range range; - range.ast = ast; + range.ast = member; range.begin = QTextCursor(_textDocument); - range.begin.setPosition(ast->firstSourceLocation().begin()); + range.begin.setPosition(ast->lbraceToken.begin()); range.end = QTextCursor(_textDocument); - range.end.setPosition(ast->lastSourceLocation().end()); + range.end.setPosition(ast->rbraceToken.end()); return range; } }; -- GitLab