diff --git a/src/tools/clangbackend/source/codecompletionsextractor.cpp b/src/tools/clangbackend/source/codecompletionsextractor.cpp index be36cae0880..8633732238e 100644 --- a/src/tools/clangbackend/source/codecompletionsextractor.cpp +++ b/src/tools/clangbackend/source/codecompletionsextractor.cpp @@ -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. diff --git a/tests/unit/unittest/codecompleter-test.cpp b/tests/unit/unittest/codecompleter-test.cpp index dcb1c1a57c9..a0ed2b413f7 100644 --- a/tests/unit/unittest/codecompleter-test.cpp +++ b/tests/unit/unittest/codecompleter-test.cpp @@ -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) { diff --git a/tests/unit/unittest/data/completions_order.cpp b/tests/unit/unittest/data/completions_order.cpp index 6c363a6c504..433c171cecf 100644 --- a/tests/unit/unittest/data/completions_order.cpp +++ b/tests/unit/unittest/data/completions_order.cpp @@ -26,3 +26,16 @@ void testPriorities() { DifferentPriorities d; d. } + +class LexicographicalSorting +{ +public: + void memberFuncBB(); + void memberFuncC(); + void memberFuncAAA(); +}; + +void testLexicographicalSorting() { + LexicographicalSorting ls; + ls.memberFunc +}