Commit 6fe1f5b9 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Made the error recovering more robust.

parent da81d59e
......@@ -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;
......
......@@ -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;
}
}
......
......@@ -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;
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment