Commit d764f013 authored by Denis Steckelmacher's avatar Denis Steckelmacher

Hide C++ wrappers in QML contexts

C++ wrappers (QDeclarativeItem, etc) cannot be instantiated in a QML component,
they can only be used in Javascript snippets.
parent 39167957
......@@ -82,19 +82,22 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::completionItems(bool& ab
// The cursor is in a QML object and there is nothing before it. Display
// a list of properties and signals that can be used in a script binding.
// Note that the properties/signals of parent QML objects are not displayed here
items << completionsInContext(m_duContext, true, CompletionItem::Colon);
items << completionsInContext(m_duContext,
CompletionOnlyLocal | CompletionHideWrappers,
CompletionItem::Colon);
items << globalCompletions(CompletionHideWrappers);
} else {
items << completionsInContext(m_duContext, false, CompletionItem::NoDecoration);
items << completionsInContext(m_duContext,
0,
CompletionItem::NoDecoration);
}
items << globalCompletions();
}
return items;
}
QList<CompletionTreeItemPointer> CodeCompletionContext::completionsInContext(const DUContextPointer& context,
bool onlyLocal,
CompletionInContextFlags flags,
CompletionItem::Decoration decoration)
{
QList<CompletionTreeItemPointer> items;
......@@ -104,16 +107,22 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::completionsInContext(con
const QList<DeclarationDepthPair>& declarations = context->allDeclarations(
CursorInRevision::invalid(),
context->topContext(),
!onlyLocal
!flags.testFlag(CompletionOnlyLocal)
);
foreach (const DeclarationDepthPair& decl, declarations) {
DeclarationPointer declaration(decl.first);
if (decl.first->kind() == Declaration::NamespaceAlias) {
if (declaration->kind() == Declaration::NamespaceAlias) {
continue;
} else if (decl.first->qualifiedIdentifier().isEmpty()) {
} else if (declaration->qualifiedIdentifier().isEmpty()) {
continue;
} else if (flags.testFlag(CompletionHideWrappers)) {
ClassDeclaration* classDecl = dynamic_cast<ClassDeclaration*>(declaration.data());
if (classDecl && classDecl->classType() == ClassDeclarationData::Interface) {
continue;
}
}
items << CompletionTreeItemPointer(new CompletionItem(declaration, decl.second, decoration));
......@@ -123,7 +132,7 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::completionsInContext(con
return items;
}
QList<CompletionTreeItemPointer> CodeCompletionContext::globalCompletions()
QList<CompletionTreeItemPointer> CodeCompletionContext::globalCompletions(CompletionInContextFlags flags)
{
QList<CompletionTreeItemPointer> items;
......@@ -146,7 +155,7 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::globalCompletions()
foreach (Declaration* import, realImports) {
items << completionsInContext(
DUContextPointer(import->internalContext()),
false,
flags,
CompletionItem::NoDecoration
);
}
......@@ -219,7 +228,9 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::fieldCompletions(const Q
DUContext* context = getInternalContext(visitor.lastDeclaration());
if (context) {
return completionsInContext(DUContextPointer(context), true, decoration);
return completionsInContext(DUContextPointer(context),
CompletionOnlyLocal,
decoration);
} else {
return QList<CompletionTreeItemPointer>();
}
......
......@@ -38,17 +38,25 @@ public:
const KDevelop::CursorInRevision& position, int depth = 0);
virtual QList<KDevelop::CompletionTreeItemPointer> completionItems(bool& abort, bool fullCompletion = true);
enum CompletionInContextFlag {
CompletionOnlyLocal = 1, /*!< @brief Don't list the items available in parent contexts */
CompletionHideWrappers = 2, /*!< @brief Filter out QML component wrappers (Q... C++ classes) */
};
Q_DECLARE_FLAGS(CompletionInContextFlags, CompletionInContextFlag)
private:
QList<KDevelop::CompletionTreeItemPointer> completionsInContext(const KDevelop::DUContextPointer& context,
bool onlyLocal,
CompletionInContextFlags flags,
CompletionItem::Decoration decoration);
QList<KDevelop::CompletionTreeItemPointer> globalCompletions();
QList<KDevelop::CompletionTreeItemPointer> globalCompletions(CompletionInContextFlags flags = 0);
QList<KDevelop::CompletionTreeItemPointer> fieldCompletions(const QString &expression,
CompletionItem::Decoration decoration);
bool containsOnlySpaces(const QString &str);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(CodeCompletionContext::CompletionInContextFlags)
}
#endif // QMLJS_CONTEXT_H
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