forked from qt-creator/qt-creator
clangbackend: Fix lexicographical sorting of completions
Utf8String has a weird operator<, so we did not get the expected results from our string comparisons. Task-number: QTCREATORBUG-6242 Change-Id: I0e94dc42d6e04ab833efcce41463b7024455b6d8 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -146,8 +146,14 @@ static void sortCodeCompletions(CodeCompletions &codeCompletions)
|
||||
if (first.requiredFixIts.empty() != second.requiredFixIts.empty())
|
||||
return first.requiredFixIts.empty() > second.requiredFixIts.empty();
|
||||
|
||||
return std::tie(first.priority, first.text, first.completionKind)
|
||||
< std::tie(second.priority, second.text, second.completionKind);
|
||||
if (first.priority != second.priority)
|
||||
return first.priority < second.priority;
|
||||
|
||||
const int textCmp = first.text.toString().compare(second.text);
|
||||
if (textCmp != 0)
|
||||
return textCmp < 0;
|
||||
|
||||
return first.completionKind < second.completionKind;
|
||||
};
|
||||
|
||||
// Keep the order for the items with the same priority and name.
|
||||
|
||||
@@ -647,6 +647,26 @@ TEST_F(CodeCompleterSlowTest, FunctionOverloadsWithoutDotOrArrowOrder)
|
||||
ASSERT_THAT(abs(firstIndex - secondIndex), 1);
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleterSlowTest, LexicographicalSorting)
|
||||
{
|
||||
auto myCompleter = setupCompleter(completionsOrder);
|
||||
const ClangBackEnd::CodeCompletions completions = myCompleter.complete(40, 18);
|
||||
|
||||
const int funcAIndex = Utils::indexOf(completions, [](const CodeCompletion &codeCompletion) {
|
||||
return codeCompletion.text == "memberFuncAAA";
|
||||
});
|
||||
const int funcBIndex = Utils::indexOf(completions, [](const CodeCompletion &codeCompletion) {
|
||||
return codeCompletion.text == "memberFuncBB";
|
||||
});
|
||||
const int funcCIndex = Utils::indexOf(completions, [](const CodeCompletion &codeCompletion) {
|
||||
return codeCompletion.text == "memberFuncC";
|
||||
});
|
||||
|
||||
ASSERT_NE(funcAIndex, -1);
|
||||
ASSERT_EQ(funcBIndex, funcAIndex + 1);
|
||||
ASSERT_EQ(funcCIndex, funcAIndex + 2);
|
||||
}
|
||||
|
||||
ClangBackEnd::CodeCompleter CodeCompleter::setupCompleter(
|
||||
const ClangBackEnd::FileContainer &fileContainer)
|
||||
{
|
||||
|
||||
@@ -26,3 +26,16 @@ void testPriorities() {
|
||||
DifferentPriorities d;
|
||||
d.
|
||||
}
|
||||
|
||||
class LexicographicalSorting
|
||||
{
|
||||
public:
|
||||
void memberFuncBB();
|
||||
void memberFuncC();
|
||||
void memberFuncAAA();
|
||||
};
|
||||
|
||||
void testLexicographicalSorting() {
|
||||
LexicographicalSorting ls;
|
||||
ls.memberFunc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user