forked from qt-creator/qt-creator
More intelligent function argument widget
Now it shows immediately when there is only a single signature of a
given method/constructor.
(cherry picked from commit 8b9dd766c8
)
Conflicts:
src/plugins/cpptools/cppcodecompletion.cpp
This commit is contained in:
@@ -518,7 +518,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
if (exprTy->isReferenceType())
|
if (exprTy->isReferenceType())
|
||||||
exprTy = exprTy->asReferenceType()->elementType();
|
exprTy = exprTy->asReferenceType()->elementType();
|
||||||
|
|
||||||
if (m_completionOperator == T_LPAREN && completeFunction(exprTy, resolvedTypes, context)) {
|
if (m_completionOperator == T_LPAREN && completeConstructorOrFunction(exprTy, resolvedTypes)) {
|
||||||
return m_startPosition;
|
return m_startPosition;
|
||||||
} else if ((m_completionOperator == T_DOT || m_completionOperator == T_ARROW) &&
|
} else if ((m_completionOperator == T_DOT || m_completionOperator == T_ARROW) &&
|
||||||
completeMember(resolvedTypes, context)) {
|
completeMember(resolvedTypes, context)) {
|
||||||
@@ -551,7 +551,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
foreach (const TypeOfExpression::Result &result, results) {
|
foreach (const TypeOfExpression::Result &result, results) {
|
||||||
if (result.first->isClass()) {
|
if (result.first->isClass()) {
|
||||||
FullySpecifiedType exprTy = result.first;
|
FullySpecifiedType exprTy = result.first;
|
||||||
if (completeConstructors(exprTy->asClass()))
|
if (completeConstructorOrFunction(exprTy, QList<TypeOfExpression::Result>()))
|
||||||
return m_startPosition;
|
return m_startPosition;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -563,18 +563,29 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy,
|
bool CppCodeCompletion::completeConstructorOrFunction(FullySpecifiedType exprTy,
|
||||||
const QList<TypeOfExpression::Result> &resolvedTypes,
|
const QList<TypeOfExpression::Result> &resolvedTypes)
|
||||||
const LookupContext &)
|
|
||||||
{
|
{
|
||||||
if (Class *klass = exprTy->asClass()) {
|
|
||||||
completeConstructors(klass);
|
|
||||||
} else {
|
|
||||||
ConvertToCompletionItem toCompletionItem(this);
|
ConvertToCompletionItem toCompletionItem(this);
|
||||||
Overview o;
|
Overview o;
|
||||||
o.setShowReturnTypes(true);
|
o.setShowReturnTypes(true);
|
||||||
o.setShowArgumentNames(true);
|
o.setShowArgumentNames(true);
|
||||||
|
|
||||||
|
if (Class *klass = exprTy->asClass()) {
|
||||||
|
for (unsigned i = 0; i < klass->memberCount(); ++i) {
|
||||||
|
Symbol *member = klass->memberAt(i);
|
||||||
|
if (! member->type()->isFunction())
|
||||||
|
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 {
|
||||||
QSet<QString> signatures;
|
QSet<QString> signatures;
|
||||||
foreach (TypeOfExpression::Result p, resolvedTypes) {
|
foreach (TypeOfExpression::Result p, resolvedTypes) {
|
||||||
FullySpecifiedType ty = p.first;
|
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();
|
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()->isFunction())
|
|
||||||
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,
|
bool CppCodeCompletion::completeQtMethod(CPlusPlus::FullySpecifiedType,
|
||||||
const QList<TypeOfExpression::Result> &results,
|
const QList<TypeOfExpression::Result> &results,
|
||||||
const LookupContext &context,
|
const LookupContext &context,
|
||||||
|
@@ -86,9 +86,8 @@ private:
|
|||||||
void addMacros(const CPlusPlus::LookupContext &context);
|
void addMacros(const CPlusPlus::LookupContext &context);
|
||||||
void addCompletionItem(CPlusPlus::Symbol *symbol);
|
void addCompletionItem(CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
bool completeFunction(CPlusPlus::FullySpecifiedType exprTy,
|
bool completeConstructorOrFunction(CPlusPlus::FullySpecifiedType exprTy,
|
||||||
const QList<CPlusPlus::TypeOfExpression::Result> &,
|
const QList<CPlusPlus::TypeOfExpression::Result> &);
|
||||||
const CPlusPlus::LookupContext &context);
|
|
||||||
|
|
||||||
bool completeMember(const QList<CPlusPlus::TypeOfExpression::Result> &,
|
bool completeMember(const QList<CPlusPlus::TypeOfExpression::Result> &,
|
||||||
const CPlusPlus::LookupContext &context);
|
const CPlusPlus::LookupContext &context);
|
||||||
|
Reference in New Issue
Block a user