[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
This commit is contained in:
Ben Langmuir
2016-05-02 10:57:17 -07:00
parent fd641cdbca
commit f1ba846c78
2 changed files with 31 additions and 1 deletions

View File

@@ -183,3 +183,24 @@ func test6() {
// VOID_1_RAW-NEXT: key.context: source.codecompletion.context.thismodule,
// VOID_1_RAW-NEXT: key.num_bytes_to_erase: 0,
// VOID_1_RAW-NEXT: key.not_recommended: 1,
// RUN: %complete-test -tok=CASE_0 %s | FileCheck %s -check-prefix=CASE_0
func test7() {
struct CaseSensitiveCheck {
var member: Int = 0
}
let caseSensitiveCheck = CaseSensitiveCheck()
#^CASE_0,caseSensitiveCheck,CaseSensitiveCheck^#
}
// CASE_0: Results for filterText: caseSensitiveCheck [
// CASE_0: caseSensitiveCheck
// CASE_0: CaseSensitiveCheck
// CASE_0: caseSensitiveCheck.
// CASE_0: ]
// CASE_0: Results for filterText: CaseSensitiveCheck [
// CASE_0: caseSensitiveCheck
// CASE_0: CaseSensitiveCheck
// CASE_0: CaseSensitiveCheck(
// CASE_0: ]

View File

@@ -586,8 +586,17 @@ void CodeCompletionOrganizer::Impl::addCompletionsWithFilter(
bool isExactMatch = match && completion->getName().equals_lower(filterText);
if (isExactMatch) {
if (!exactMatch)
if (!exactMatch) { // first match
exactMatch = completion;
} else if (completion->getName() != exactMatch->getName()) {
if (completion->getName() == filterText && // first case-sensitive match
exactMatch->getName() != filterText)
exactMatch = completion;
else if (pattern.scoreCandidate(completion->getName()) > // better match
pattern.scoreCandidate(exactMatch->getName()))
exactMatch = completion;
}
match = (options.addInnerResults || options.addInnerOperators)
? options.includeExactMatch
: true;