Commit 203b02d4 authored by Milian Wolff's avatar Milian Wolff
Browse files

clang: Improve argument hint code completion

Previously, the overload candidates never got an DUChain Declaration
associated, meaning we could not inspect the API documentation in-line
from the code completion. The reason was that most of the time the
hinted declaration is also a valid "normal" completion item, and thus
was found a second time. The findDeclaration call then returned null
for the second call, since we added the declaration to the exclusion
set after the first call. Instead, use a separate set for overload
candidates to fix this. Note that the expanded argument hint item
is still not showing any documentation in-line... Apparently there's
more to fix to get this done properly.

While at it, also use the ArgumentHintItem for the situations where
we (now) find a Declaration, to get proper current-argument

Then fix the unit test to expect the default arguments. Though
potentially this is clang-version dependent? Anyhow, this makes the
test pass for me on my machine with libclang from LLVM 5.0.0.

Reviewers: #kdevelop

Subscribers: kdevelop-devel

Differential Revision:
parent 2ad24171
......@@ -366,7 +366,7 @@ public:
return QVariant(CodeCompletionModel::CustomHighlighting);
if (index.column() == CodeCompletionModel::Arguments && !m_declaration) {
if (index.column() == CodeCompletionModel::Arguments) {
return m_arguments;
......@@ -936,7 +936,11 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
/// Builtins reported by Clang
QList<CompletionTreeItemPointer> builtin;
// two sets of handled declarations to prevent duplicates and make sure we show
// all available overloads
QSet<Declaration*> handled;
// this is only used for the CXCursor_OverloadCandidate completion items
QSet<Declaration*> overloadsHandled;
LookAheadItemMatcher lookAheadMatcher(TopDUContextPointer(ctx->topContext()));
......@@ -1097,7 +1101,7 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
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 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
auto declarationItem = new DeclarationItem(found, typed, resultType, replacement);
DeclarationItem* declarationItem = nullptr;
if (isOverloadCandidate) {
declarationItem = new ArgumentHintItem(found, resultType, typed, arguments, argumentRange);
} 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 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
if ( isInternal ) {
if (isOverloadCandidate) {
item = declarationItem;
} else {
......@@ -1201,7 +1201,7 @@ void TestCodeCompletion::testArgumentHintCompletionDefaultParameters()
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()
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