Commit 8b9dd766 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

More intelligent function argument widget

Now it shows immediately when there is only a single signature of a
given method/constructor.
parent b928f7b5
......@@ -518,7 +518,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
if (exprTy->isReferenceType())
exprTy = exprTy->asReferenceType()->elementType();
if (m_completionOperator == T_LPAREN && completeFunction(exprTy, resolvedTypes, context)) {
if (m_completionOperator == T_LPAREN && completeConstructorOrFunction(exprTy, resolvedTypes)) {
return m_startPosition;
} else if ((m_completionOperator == T_DOT || m_completionOperator == T_ARROW) &&
completeMember(resolvedTypes, context)) {
......@@ -551,7 +551,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
foreach (const TypeOfExpression::Result &result, results) {
if (result.first->isClassType()) {
FullySpecifiedType exprTy = result.first;
if (completeConstructors(exprTy->asClassType()))
if (completeConstructorOrFunction(exprTy, QList<TypeOfExpression::Result>()))
return m_startPosition;
break;
}
......@@ -563,18 +563,29 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
return -1;
}
bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy,
const QList<TypeOfExpression::Result> &resolvedTypes,
const LookupContext &)
bool CppCodeCompletion::completeConstructorOrFunction(FullySpecifiedType exprTy,
const QList<TypeOfExpression::Result> &resolvedTypes)
{
ConvertToCompletionItem toCompletionItem(this);
Overview o;
o.setShowReturnTypes(true);
o.setShowArgumentNames(true);
if (Class *klass = exprTy->asClassType()) {
completeConstructors(klass);
for (unsigned i = 0; i < klass->memberCount(); ++i) {
Symbol *member = klass->memberAt(i);
if (! member->type()->isFunctionType())
continue;
else if (! member->identity())
continue;
else if (! member->identity()->isEqualTo(klass->identity()))
continue;
if (TextEditor::CompletionItem item = toCompletionItem(member)) {
item.m_text = o(member->type(), member->name());
m_completions.append(item);
}
}
} else {
ConvertToCompletionItem toCompletionItem(this);
Overview o;
o.setShowReturnTypes(true);
o.setShowArgumentNames(true);
QSet<QString> signatures;
foreach (TypeOfExpression::Result p, resolvedTypes) {
FullySpecifiedType ty = p.first;
......@@ -594,6 +605,10 @@ bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy,
}
}
// If there is only one item, show the function argument widget immediately
if (m_completions.size() == 1)
complete(m_completions.takeFirst());
return ! m_completions.isEmpty();
}
......@@ -887,30 +902,6 @@ void CppCodeCompletion::completeClass(const QList<Symbol *> &candidates,
}
}
bool CppCodeCompletion::completeConstructors(Class *klass)
{
ConvertToCompletionItem toCompletionItem(this);
Overview o;
o.setShowReturnTypes(true);
o.setShowArgumentNames(true);
for (unsigned i = 0; i < klass->memberCount(); ++i) {
Symbol *member = klass->memberAt(i);
if (! member->type()->isFunctionType())
continue;
else if (! member->identity())
continue;
else if (! member->identity()->isEqualTo(klass->identity()))
continue;
if (TextEditor::CompletionItem item = toCompletionItem(member)) {
item.m_text = o(member->type(), member->name());
m_completions.append(item);
}
}
return ! m_completions.isEmpty();
}
bool CppCodeCompletion::completeQtMethod(CPlusPlus::FullySpecifiedType,
const QList<TypeOfExpression::Result> &results,
const LookupContext &context,
......
......@@ -86,9 +86,8 @@ private:
void addMacros(const CPlusPlus::LookupContext &context);
void addCompletionItem(CPlusPlus::Symbol *symbol);
bool completeFunction(CPlusPlus::FullySpecifiedType exprTy,
const QList<CPlusPlus::TypeOfExpression::Result> &,
const CPlusPlus::LookupContext &context);
bool completeConstructorOrFunction(CPlusPlus::FullySpecifiedType exprTy,
const QList<CPlusPlus::TypeOfExpression::Result> &);
bool completeMember(const QList<CPlusPlus::TypeOfExpression::Result> &,
const CPlusPlus::LookupContext &context);
......
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