Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8a62caa6 authored by Kevin Funk's avatar Kevin Funk

Still propose "special" functions

Instead of hiding functions such as 'SomeClass::operator=(SomeClass&)',
put them into the (new) completion group called "Special"
parent d369b3d7
......@@ -274,7 +274,8 @@ int codeCompletionPriorityToMatchQuality(unsigned int completionPriority)
/**
* @return Whether the declaration represented by identifier @p identifier qualifies as completion result
*
* For example, we don't want to offer SomeClass::operator= as completion item to the user
* For example, we don't want to offer SomeClass::SomeClass as completion item to the user
* (otherwise we'd end up generating code such as 's.SomeClass();')
*/
bool isValidCompletionIdentifier(const QualifiedIdentifier& identifier)
{
......@@ -292,9 +293,6 @@ bool isValidCompletionIdentifier(const QualifiedIdentifier& identifier)
if (idString.startsWith("~") && scope.toString() == idString.midRef(1)) {
return false; // is destructor
}
if (idString.startsWith("operator")) {
return false; // is operator
}
return true;
}
......@@ -365,8 +363,13 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
return {};
}
/// Normal completion items, such as 'void Foo::foo()'
QList<CompletionTreeItemPointer> items;
/// Stuff like 'Foo& Foo::operator=(const Foo&)', etc. Not regularly used by our users.
QList<CompletionTreeItemPointer> specialItems;
/// Macros from the current context
QList<CompletionTreeItemPointer> macros;
/// Builtins reported by Clang
QList<CompletionTreeItemPointer> builtin;
QSet<Declaration*> handled;
......@@ -518,13 +521,16 @@ QList<CompletionTreeItemPointer> ClangCodeCompletionContext::completionItems(boo
if (result.CursorKind == CXCursor_MacroDefinition) {
// TODO: grouping of macros and built-in stuff
macros.append(item);
} else {
} else if (result.CursorKind == CXCursor_NotImplemented) {
builtin.append(item);
} else {
specialItems.append(item);
}
}
addOverwritableItems();
addImplementationHelperItems();
eventuallyAddGroup(i18n("Special"), 700, specialItems);
eventuallyAddGroup(i18n("Macros"), 900, macros);
eventuallyAddGroup(i18n("Builtin"), 800, builtin);
return items;
......
......@@ -110,11 +110,16 @@ void TestCodeCompletion::testClangCodeCompletion_data()
<< "class Foo { public: void foo() {} }; int main() { Foo f; \nf. "
<< CompletionItemsList{{{1, 2}, {
"foo()",
"operator=(Foo &&)",
"operator=(const Foo &)",
}}};
QTest::newRow("arrowmemberaccess")
<< "class Foo { public: void foo() {} }; int main() { Foo* f = new Foo; \nf-> }"
<< CompletionItemsList{{{1, 3}, {
"foo()",
"operator=(Foo &&)",
"operator=(const Foo &)",
}}};
QTest::newRow("enum-case")
<< "enum Foo { foo, bar }; int main() { Foo f; switch (f) {\ncase "
......@@ -126,23 +131,31 @@ void TestCodeCompletion::testClangCodeCompletion_data()
<< "class SomeStruct { private: void priv() {} };\n"
"int main() { SomeStruct s;\ns. "
<< CompletionItemsList{{{2, 2}, {
"operator=(SomeStruct &&)",
"operator=(const SomeStruct &)",
}}};
QTest::newRow("private-friend")
<< "class SomeStruct { private: void priv() {} friend int main(); };\n"
"int main() { SomeStruct s;\ns. "
<< CompletionItemsList{{{2, 2}, {
"operator=(SomeStruct &&)",
"operator=(const SomeStruct &)",
"priv()",
}}};
QTest::newRow("private-public")
<< "class SomeStruct { public: void pub() {} private: void priv() {} };\n"
"int main() { SomeStruct s;\ns. "
<< CompletionItemsList{{{2, 2}, {
"operator=(SomeStruct &&)",
"operator=(const SomeStruct &)",
"pub()",
}}};
QTest::newRow("protected-public")
<< "class SomeStruct { public: void pub() {} protected: void prot() {} };\n"
"int main() { SomeStruct s;\ns. "
<< CompletionItemsList{{{2, 2}, {
"operator=(SomeStruct &&)",
"operator=(const SomeStruct &)",
"pub()",
}}};
}
......
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