Do never offer signature autocompletion for constructor calls.

They should always use the function parameter tooltip.

This fixes a bug where you were offered completion for
C foo( -> C foo(int x)
if C had a constructor taking int x.

Reviewed-by: Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
This commit is contained in:
Christian Kamm
2009-11-09 10:10:31 +01:00
parent 5e0e975873
commit a253a69980
2 changed files with 19 additions and 15 deletions

View File

@@ -871,7 +871,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
if (! resolvedTypes.isEmpty()) { if (! resolvedTypes.isEmpty()) {
if (m_completionOperator == T_LPAREN && if (m_completionOperator == T_LPAREN &&
completeConstructorOrFunction(resolvedTypes, context, endOfExpression)) { completeConstructorOrFunction(resolvedTypes, context, endOfExpression, false)) {
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) &&
@@ -910,7 +910,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
// If it's a class, add completions for the constructors // If it's a class, add completions for the constructors
foreach (const TypeOfExpression::Result &result, results) { foreach (const TypeOfExpression::Result &result, results) {
if (result.first->isClassType()) { if (result.first->isClassType()) {
if (completeConstructorOrFunction(results, context, endOfExpression)) if (completeConstructorOrFunction(results, context, endOfExpression, true))
return m_startPosition; return m_startPosition;
break; break;
} }
@@ -924,7 +924,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpression::Result> &results, bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpression::Result> &results,
const LookupContext &context, const LookupContext &context,
int endOfExpression) int endOfExpression, bool toolTipOnly)
{ {
QList<Function *> functions; QList<Function *> functions;
@@ -1013,15 +1013,17 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
} }
} }
if (! functions.isEmpty()) { // There are two different kinds of completion we want to provide:
// There are two options:
// 1. If this is a function call, we want to pop up a tooltip that shows the user // 1. If this is a function call, we want to pop up a tooltip that shows the user
// the possible overloads with their argument types and names. // the possible overloads with their argument types and names.
// 2. If this is a function definition, we want to offer autocompletion of // 2. If this is a function definition, we want to offer autocompletion of
// the function signature. // the function signature.
// Here we evaluate a first criterion: function definitions will only // check if function signature autocompletion is appropriate
// happen in class or namespace scope. if (! functions.isEmpty() && ! toolTipOnly) {
// function definitions will only happen in class or namespace scope,
// so get the current location's enclosing scope.
// get current line and column // get current line and column
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget()); TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget());
@@ -1043,16 +1045,16 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
unsigned endLine, endColumn; unsigned endLine, endColumn;
context.thisDocument()->translationUnit()->getPosition(sc->owner()->endOffset(), &endLine, &endColumn); context.thisDocument()->translationUnit()->getPosition(sc->owner()->endOffset(), &endLine, &endColumn);
if (startLine <= line && line <= endLine) if (startLine <= line && line <= endLine) {
if ((startLine != line || startColumn <= column) if ((startLine != line || startColumn <= column)
&& (endLine != line || column <= endColumn)) && (endLine != line || column <= endColumn))
break; break;
}
sc = sc->enclosingScope(); sc = sc->enclosingScope();
} }
if (sc && (sc->isClassScope() || sc->isNamespaceScope())) if (sc && (sc->isClassScope() || sc->isNamespaceScope())) {
{
// It may still be a function call. If the whole line parses as a function // It may still be a function call. If the whole line parses as a function
// declaration, we should be certain that it isn't. // declaration, we should be certain that it isn't.
bool autocompleteSignature = false; bool autocompleteSignature = false;
@@ -1091,7 +1093,9 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
return true; return true;
} }
} }
}
if (! functions.empty()) {
// set up function call tooltip // set up function call tooltip
// Recreate if necessary // Recreate if necessary

View File

@@ -115,7 +115,7 @@ private:
bool completeConstructorOrFunction(const QList<CPlusPlus::TypeOfExpression::Result> &, bool completeConstructorOrFunction(const QList<CPlusPlus::TypeOfExpression::Result> &,
const CPlusPlus::LookupContext &, const CPlusPlus::LookupContext &,
int endOfExpression); int endOfExpression, bool toolTipOnly);
bool completeMember(const QList<CPlusPlus::TypeOfExpression::Result> &, bool completeMember(const QList<CPlusPlus::TypeOfExpression::Result> &,
const CPlusPlus::LookupContext &context); const CPlusPlus::LookupContext &context);