summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
authorAlexey Semenko <igogo.dev@gmail.com>2013-08-28 01:02:26 +0400
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-09-03 14:44:41 +0200
commitda4c4b80f3b9047ee4d87c7c7c7a7e073ab23ead (patch)
treea665efd7ed84ec7b1ccba4c17026f1cd4afb65ea /src/plugins/cpptools/cppcompletion_test.cpp
parentadee8336bbc1365149dbcd33b0e05a2096c4dfa8 (diff)
downloadqt-creator-da4c4b80f3b9047ee4d87c7c7c7a7e073ab23ead.tar.gz
Completions: move continuations upper in proposals list.
Since fuzzy completions are allowed, the lexicographically first proposal is not necessarily most relevant. The patch modifies sorting of proposals so that the exact match and continuations go first, and fuzzy completions follow. Moreover, being a continuation seem to be a more important characteristic of a proposal, than being it a function argument or keyword etc. That's why the check for continuation is placed before the check for order. Task-number: QTCREATORBUG-8737 Task-number: QTCREATORBUG-9236 Change-Id: I89aae9d2ce6bfa59af7c2f75e6f3af00212008ca Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Alexey Zhondin <lexxmark.dev@gmail.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cppcompletion_test.cpp')
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index 4248d9d431..23556b58b9 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -121,6 +121,8 @@ public:
const QString prefix = Convenience::textAt(QTextCursor(editorWidget->document()), pos, length);
if (!prefix.isEmpty())
listmodel->filter(prefix);
+ if (listmodel->isSortable(prefix))
+ listmodel->sort(prefix);
for (int i = 0; i < listmodel->size(); ++i)
completions << listmodel->text(i);
@@ -2069,6 +2071,56 @@ void CppToolsPlugin::test_completion_recursive_using_typedef_declarations()
QCOMPARE(completions.size(), 0);
}
+void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_8737()
+{
+ const QByteArray source =
+ "void f()\n"
+ "{\n"
+ " int a_b_c, a_c, a_c_a;\n"
+ " @;\n"
+ " // padding so we get the scope right\n"
+ "}\n"
+ ;
+ CompletionTestCase test(source, "a_c");
+
+ QStringList completions = test.getCompletions();
+
+ QVERIFY(completions.size() >= 2);
+ QCOMPARE(completions.at(0), QLatin1String("a_c"));
+ QCOMPARE(completions.at(1), QLatin1String("a_c_a"));
+ QVERIFY(completions.contains(QLatin1String("a_b_c")));
+}
+
+void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_9236()
+{
+ const QByteArray source =
+ "class r_etclass\n"
+ "{\n"
+ "public:\n"
+ " int raEmTmber;\n"
+ " void r_e_t(int re_t)\n"
+ " {\n"
+ " int r_et;\n"
+ " int rETUCASE;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ "};\n"
+ ;
+ CompletionTestCase test(source, "ret");
+
+ QStringList completions = test.getCompletions();
+
+ QVERIFY(completions.size() >= 2);
+ QCOMPARE(completions.at(0), QLatin1String("return"));
+ QCOMPARE(completions.at(1), QLatin1String("rETUCASE"));
+ QVERIFY(completions.contains(QLatin1String("r_etclass")));
+ QVERIFY(completions.contains(QLatin1String("raEmTmber")));
+ QVERIFY(completions.contains(QLatin1String("r_e_t")));
+ QVERIFY(completions.contains(QLatin1String("re_t")));
+ QVERIFY(completions.contains(QLatin1String("r_et")));
+}
+
void CppToolsPlugin::test_completion_class_declaration_inside_function_or_block_QTCREATORBUG3620()
{
test_completion();