diff --git a/src/plugins/qmljseditor/qmljscodecompletion.cpp b/src/plugins/qmljseditor/qmljscodecompletion.cpp index 37d8e8e5953..dce84351c74 100644 --- a/src/plugins/qmljseditor/qmljscodecompletion.cpp +++ b/src/plugins/qmljseditor/qmljscodecompletion.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -786,8 +787,20 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor) CompletionContextFinder contextFinder(startPositionCursor); const Interpreter::ObjectValue *qmlScopeType = 0; - if (contextFinder.isInQmlContext()) - qmlScopeType = context->lookupType(document.data(), contextFinder.qmlObjectTypeName()); + if (contextFinder.isInQmlContext()) { + // ### this should use semanticInfo.declaringMember instead, but that may also return functions + for (int i = path.size() - 1; i >= 0; --i) { + AST::Node *node = path[i]; + if (AST::cast(node) || AST::cast(node)) { + qmlScopeType = document->bind()->findQmlObject(node); + if (qmlScopeType) + break; + } + } + // fallback to getting the base type object + if (!qmlScopeType) + qmlScopeType = context->lookupType(document.data(), contextFinder.qmlObjectTypeName()); + } if (contextFinder.isInStringLiteral()) { // get the text of the literal up to the cursor position