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 1383602c authored by Sergey Kalinichev's avatar Sergey Kalinichev

Invert return value of the codeCompletionPriorityToMatchQuality

It should return 10 in case of the best match not vice-versa

Now the best mathes completion group shows elements in the right
order: with the best priority at the top.
parent 93245d4b
......@@ -304,14 +304,14 @@ QString& elideStringRight(QString& str, int length)
}
/**
* @return Value suited for @ref CodeCompletionModel::MatchQuality in the range [0.0, 10.0]
* @return Value suited for @ref CodeCompletionModel::MatchQuality in the range [0.0, 10.0] (the higher the better)
*
* See http://clang.llvm.org/doxygen/CodeCompleteConsumer_8h_source.html for list of priorities
* They (currently) have a range from [-3, 80] (the lower, the better)
*/
int codeCompletionPriorityToMatchQuality(unsigned int completionPriority)
{
return qBound(0u, completionPriority, 80u) / 8;
return 10u - qBound(0u, completionPriority, 80u) / 8;
}
/**
......
......@@ -59,7 +59,7 @@ struct CompletionItems {
{};
KTextEditor::Cursor position;
QStringList completions;
QStringList declarationItems; // completion items that have associated declarations
QStringList declarationItems; ///< completion items that have associated declarations. Declarations with higher match quality at the top. @sa KTextEditor::CodeCompletionModel::MatchQuality
};
Q_DECLARE_TYPEINFO(CompletionItems, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(CompletionItems);
......@@ -104,11 +104,15 @@ void executeCompletionTest(const QString& code, const CompletionItems& expectedC
lock.lock();
auto tester = ClangCodeCompletionItemTester(QExplicitlySharedDataPointer<ClangCodeCompletionContext>(context));
int previousMatchQuality = 10;
for(const auto& declarationName : expectedCompletionItems.declarationItems){
const auto declarationItem = tester.findItem(declarationName);
QVERIFY(declarationItem);
QVERIFY(declarationItem->declaration());
auto matchQuality = tester.itemData(declarationItem, KTextEditor::CodeCompletionModel::Name, KTextEditor::CodeCompletionModel::MatchQuality).toInt();
QVERIFY(matchQuality <= previousMatchQuality);
previousMatchQuality = matchQuality;
}
tester.names.sort();
......@@ -249,6 +253,13 @@ void TestCodeCompletion::testClangCodeCompletion_data()
{"m_variable", "operator=(A &&)", "operator=(B &&)", "operator=(const A &)", "operator=(const B &)"},
{"m_variable"}
};
QTest::newRow("itemsPriority")
<< "class A; class B; void f(A); int main(){ A c; B b;f(\n} "
<< CompletionItems{{1, 0},
// TODO: what's the "()"?
{"()", "A", "B", "b", "c", "f(A)", "main()"},
{"c", "A", "b", "B"}
};
}
void TestCodeCompletion::testVirtualOverride()
......
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