diff --git a/plugins/clang/codecompletion/context.cpp b/plugins/clang/codecompletion/context.cpp --- a/plugins/clang/codecompletion/context.cpp +++ b/plugins/clang/codecompletion/context.cpp @@ -366,7 +366,7 @@ return QVariant(CodeCompletionModel::CustomHighlighting); } - if (index.column() == CodeCompletionModel::Arguments && !m_declaration) { + if (index.column() == CodeCompletionModel::Arguments) { return m_arguments; } @@ -936,7 +936,11 @@ /// Builtins reported by Clang QList builtin; + // two sets of handled declarations to prevent duplicates and make sure we show + // all available overloads QSet handled; + // this is only used for the CXCursor_OverloadCandidate completion items + QSet overloadsHandled; LookAheadItemMatcher lookAheadMatcher(TopDUContextPointer(ctx->topContext())); @@ -1097,7 +1101,7 @@ continue; } - auto found = findDeclaration(qid, ctx, m_position, handled); + auto found = findDeclaration(qid, ctx, m_position, isOverloadCandidate ? overloadsHandled : handled); CompletionTreeItemPointer item; if (found) { @@ -1120,7 +1124,13 @@ } } - auto declarationItem = new DeclarationItem(found, typed, resultType, replacement); + DeclarationItem* declarationItem = nullptr; + if (isOverloadCandidate) { + declarationItem = new ArgumentHintItem(found, resultType, typed, arguments, argumentRange); + declarationItem->setArgumentHintDepth(1); + } else { + declarationItem = new DeclarationItem(found, typed, resultType, replacement); + } const unsigned int completionPriority = adjustPriorityForDeclaration(found, clang_getCompletionPriority(result.CompletionString)); const bool bestMatch = completionPriority <= CCP_SuperCompletion; @@ -1141,9 +1151,6 @@ if ( isInternal ) { declarationItem->markAsUnimportant(); } - if (isOverloadCandidate) { - declarationItem->setArgumentHintDepth(1); - } item = declarationItem; } else { diff --git a/plugins/clang/tests/test_codecompletion.cpp b/plugins/clang/tests/test_codecompletion.cpp --- a/plugins/clang/tests/test_codecompletion.cpp +++ b/plugins/clang/tests/test_codecompletion.cpp @@ -1201,7 +1201,7 @@ QVERIFY(f.data()); const QString itemDisplay = tester.itemData(f).toString() + tester.itemData(f, KTextEditor:: CodeCompletionModel::Arguments).toString(); - QCOMPARE(itemDisplay, QStringLiteral("f(int i, int j, double k)")); + QCOMPARE(itemDisplay, QStringLiteral("f(int i, int j = 0, double k = 1)")); } void TestCodeCompletion::testCompleteFunction()