Commit 4fdeeb30 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Fix enum completion with 'as' imports.

Change-Id: Ifc229c23c14a6395c9d3e5f7ec76b9b04678787d
Reviewed-on: http://codereview.qt-project.org/5134

Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent 3e090166
......@@ -2118,6 +2118,33 @@ ImportInfo Imports::info(const QString &name, const Context *context) const
return ImportInfo();
}
QString Imports::nameForImportedObject(const ObjectValue *value, const Context *context) const
{
QListIterator<Import> it(_imports);
it.toBack();
while (it.hasPrevious()) {
const Import &i = it.previous();
const ObjectValue *import = i.object;
const ImportInfo &info = i.info;
if (info.type() == ImportInfo::FileImport) {
if (import == value)
return import->className();
} else {
const Value *v = import->lookupMember(value->className(), context);
if (v == value) {
QString result = value->className();
if (!info.id().isEmpty()) {
result.prepend(QLatin1Char('.'));
result.prepend(info.id());
}
return result;
}
}
}
return QString();
}
QList<Import> Imports::all() const
{
return _imports;
......
......@@ -896,6 +896,7 @@ public:
void append(const Import &import);
ImportInfo info(const QString &name, const Context *context) const;
QString nameForImportedObject(const ObjectValue *value, const Context *context) const;
QList<Import> all() const;
const TypeScope *typeScope() const;
......
......@@ -643,9 +643,16 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface
getPropertyValue(qmlScopeType, contextFinder.bindingPropertyName(), context);
if (const QmlEnumValue *enumValue =
dynamic_cast<const QmlEnumValue *>(value)) {
foreach (const QString &key, enumValue->keys())
const QString &name = context->imports(document.data())->nameForImportedObject(enumValue->owner(), context.data());
foreach (const QString &key, enumValue->keys()) {
QString completion;
if (name.isEmpty())
completion = QString("\"%1\"").arg(key);
else
completion = QString("%1.%2").arg(name, key);
addCompletion(&m_completions, key, m_interface->symbolIcon(),
EnumValueOrder, QString("%1.%2").arg(enumValue->owner()->className(), key));
EnumValueOrder, completion);
}
}
}
......
Markdown is supported
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