diff --git a/src/plugins/clangcodemodel/clangassistproposalmodel.cpp b/src/plugins/clangcodemodel/clangassistproposalmodel.cpp index 7fb13327f77..148ebb0ad48 100644 --- a/src/plugins/clangcodemodel/clangassistproposalmodel.cpp +++ b/src/plugins/clangcodemodel/clangassistproposalmodel.cpp @@ -63,7 +63,8 @@ void ClangAssistProposalModel::sort(const QString &/*prefix*/) || (first->order() == second->order() && first->text() < second->text()))); }; - std::sort(m_currentItems.begin(), m_currentItems.end(), currentItemsCompare); + // Keep the order for the items with the same priority and name. + std::stable_sort(m_currentItems.begin(), m_currentItems.end(), currentItemsCompare); } } // namespace Internal diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp index dba3e380f3c..1dd1a98671b 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp @@ -133,12 +133,14 @@ static QList toAssistProposalItems( auto samePreviousConstructor = std::find_if(items.begin(), items.end(), - [&name](const AssistProposalItemInterface *item) { - return item->text() == name; + [&](const AssistProposalItemInterface *item) { + return item->text() == name + && static_cast(item)->firstCodeCompletion() + .completionKind == codeCompletion.completionKind; }); if (samePreviousConstructor == items.end()) { addAssistProposalItem(items, codeCompletion, name); - } else { + } else if (codeCompletion.completionKind == CodeCompletion::ConstructorCompletionKind){ addFunctionOverloadAssistProposalItem(items, *samePreviousConstructor, interface, codeCompletion, name); } diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp index 7aada9a48cd..b878875ae61 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp @@ -361,6 +361,20 @@ bool hasItem(TextEditor::ProposalModelPtr model, const QByteArray &text) return indexOfItemWithText(model, text) != -1; } +int itemsWithText(TextEditor::ProposalModelPtr model, const QByteArray &text) +{ + if (!model) + return 0; + + int amount = 0; + for (int i = 0, size = model->size(); i < size; ++i) { + if (model->text(i) == QString::fromUtf8(text)) + ++amount; + } + + return amount; +} + bool hasItem(TextEditor::ProposalModelPtr model, const QByteArray &text, const QByteArray &detail) { const int index = indexOfItemWithText(model, text); @@ -571,6 +585,13 @@ void ClangCodeCompletionTest::testCompleteConstructor() QVERIFY(hasItem(t.proposal, "Foo(int, double)")); } +void ClangCodeCompletionTest::testCompleteClassAndConstructor() +{ + ProjectLessCompletionTest t("classAndConstructorCompletion.cpp"); + + QCOMPARE(itemsWithText(t.proposal, "Foo"), 2); +} + // Explicitly Inserting The Dot // ---------------------------- // Inserting the dot for is important since it will send the editor @@ -582,7 +603,7 @@ void ClangCodeCompletionTest::testCompleteWithDotToArrowCorrection() ProjectLessCompletionTest t("dotToArrowCorrection.cpp", QStringLiteral(".")); // See above "Explicitly Inserting The Dot" - QVERIFY(hasItem(t.proposal, "member")); + QVERIFY(hasItem(t.proposal, "member (requires to correct [4:8-4:9] to \"->\")")); } void ClangCodeCompletionTest::testDontCompleteWithDotToArrowCorrectionForFloats() diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.h b/src/plugins/clangcodemodel/test/clangcodecompletion_test.h index b2659d064d5..b2013550cc3 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.h +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.h @@ -46,6 +46,7 @@ private slots: void testCompleteMembers(); void testCompleteFunctions(); void testCompleteConstructor(); + void testCompleteClassAndConstructor(); void testCompleteWithDotToArrowCorrection(); void testDontCompleteWithDotToArrowCorrectionForFloats(); diff --git a/src/plugins/clangcodemodel/test/data/clangtestdata.qrc b/src/plugins/clangcodemodel/test/data/clangtestdata.qrc index ad5ccb47681..a44f6b77411 100644 --- a/src/plugins/clangcodemodel/test/data/clangtestdata.qrc +++ b/src/plugins/clangcodemodel/test/data/clangtestdata.qrc @@ -23,5 +23,6 @@ preprocessorKeywordsCompletion.cpp dotToArrowCorrection.cpp noDotToArrowCorrectionForFloats.cpp + classAndConstructorCompletion.cpp diff --git a/src/plugins/clangcodemodel/test/data/classAndConstructorCompletion.cpp b/src/plugins/clangcodemodel/test/data/classAndConstructorCompletion.cpp new file mode 100644 index 00000000000..977fa5d509e --- /dev/null +++ b/src/plugins/clangcodemodel/test/data/classAndConstructorCompletion.cpp @@ -0,0 +1,8 @@ +struct Foo { + Foo(int) {} + Foo(int, double) {} +}; + +void f() { + Fo /* COMPLETE HERE */ +}