forked from qt-creator/qt-creator
Clang: Do not replace class completion with constructor completion
Both completion kinds have the same name. Do not merge them together when looking for constructor overloads. Task-number: QTCREATORBUG-21010 Change-Id: I4c851033d63ad4e242b6179491f1fba00af466f6 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -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
|
||||
|
@@ -133,12 +133,14 @@ static QList<AssistProposalItemInterface *> 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<const ClangAssistProposalItem *>(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);
|
||||
}
|
||||
|
@@ -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()
|
||||
|
@@ -46,6 +46,7 @@ private slots:
|
||||
void testCompleteMembers();
|
||||
void testCompleteFunctions();
|
||||
void testCompleteConstructor();
|
||||
void testCompleteClassAndConstructor();
|
||||
|
||||
void testCompleteWithDotToArrowCorrection();
|
||||
void testDontCompleteWithDotToArrowCorrectionForFloats();
|
||||
|
@@ -23,5 +23,6 @@
|
||||
<file>preprocessorKeywordsCompletion.cpp</file>
|
||||
<file>dotToArrowCorrection.cpp</file>
|
||||
<file>noDotToArrowCorrectionForFloats.cpp</file>
|
||||
<file>classAndConstructorCompletion.cpp</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -0,0 +1,8 @@
|
||||
struct Foo {
|
||||
Foo(int) {}
|
||||
Foo(int, double) {}
|
||||
};
|
||||
|
||||
void f() {
|
||||
Fo /* COMPLETE HERE */
|
||||
}
|
Reference in New Issue
Block a user