Skip to content

Commit f1ba846

Browse files
committed
[CodeCompletion] Swap the exact-match if one is a better case-sensitive match
Instead of just taking the first one, consider whether there is a better result because of case-sensitivity. rdar://problem/25994202
1 parent fd641cd commit f1ba846

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

test/SourceKit/CodeComplete/complete_sort_order.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,24 @@ func test6() {
183183
// VOID_1_RAW-NEXT: key.context: source.codecompletion.context.thismodule,
184184
// VOID_1_RAW-NEXT: key.num_bytes_to_erase: 0,
185185
// VOID_1_RAW-NEXT: key.not_recommended: 1,
186+
187+
188+
189+
// RUN: %complete-test -tok=CASE_0 %s | FileCheck %s -check-prefix=CASE_0
190+
func test7() {
191+
struct CaseSensitiveCheck {
192+
var member: Int = 0
193+
}
194+
let caseSensitiveCheck = CaseSensitiveCheck()
195+
#^CASE_0,caseSensitiveCheck,CaseSensitiveCheck^#
196+
}
197+
// CASE_0: Results for filterText: caseSensitiveCheck [
198+
// CASE_0: caseSensitiveCheck
199+
// CASE_0: CaseSensitiveCheck
200+
// CASE_0: caseSensitiveCheck.
201+
// CASE_0: ]
202+
// CASE_0: Results for filterText: CaseSensitiveCheck [
203+
// CASE_0: caseSensitiveCheck
204+
// CASE_0: CaseSensitiveCheck
205+
// CASE_0: CaseSensitiveCheck(
206+
// CASE_0: ]

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,17 @@ void CodeCompletionOrganizer::Impl::addCompletionsWithFilter(
586586
bool isExactMatch = match && completion->getName().equals_lower(filterText);
587587

588588
if (isExactMatch) {
589-
if (!exactMatch)
589+
if (!exactMatch) { // first match
590590
exactMatch = completion;
591+
} else if (completion->getName() != exactMatch->getName()) {
592+
if (completion->getName() == filterText && // first case-sensitive match
593+
exactMatch->getName() != filterText)
594+
exactMatch = completion;
595+
else if (pattern.scoreCandidate(completion->getName()) > // better match
596+
pattern.scoreCandidate(exactMatch->getName()))
597+
exactMatch = completion;
598+
}
599+
591600
match = (options.addInnerResults || options.addInnerOperators)
592601
? options.includeExactMatch
593602
: true;

0 commit comments

Comments
 (0)