-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathCodeCompletionContext.cpp
36 lines (31 loc) · 1.4 KB
/
CodeCompletionContext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//===--- CodeCompletionContext.cpp ----------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/IDE/CodeCompletionContext.h"
using namespace swift;
using namespace swift::ide;
std::vector<CodeCompletionResult *>
CodeCompletionContext::sortCompletionResults(
ArrayRef<CodeCompletionResult *> Results) {
std::vector<CodeCompletionResult *> SortedResults(Results.begin(),
Results.end());
std::sort(SortedResults.begin(), SortedResults.end(),
[](const auto &LHS, const auto &RHS) {
int Result = StringRef(LHS->getFilterName())
.compare_insensitive(RHS->getFilterName());
// If the case insensitive comparison is equal, then secondary
// sort order should be case sensitive.
if (Result == 0)
Result = LHS->getFilterName().compare(RHS->getFilterName());
return Result < 0;
});
return SortedResults;
}