Skip to content

Commit

Permalink
[CodeCompletion] Don't fuzzy-match on single characters
Browse files Browse the repository at this point in the history
Use prefix matching on the first character, switch to fuzzy after 2 or
more. With only a single character, we often get silly fuzzy results.
  • Loading branch information
benlangmuir committed Nov 7, 2015
1 parent 0a82a6f commit 1144437
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions test/SourceKit/CodeComplete/complete_fuzzy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,17 @@ func test5(x: Test5) {
// DONT_FILTER_TYPES_1-NEXT: ]
// DONT_FILTER_TYPES_1-LABEL: Results for filterText: flo [
// DONT_FILTER_TYPES_1-NEXT: ]

// RUN: %complete-test %s -fuzz -tok=MIN_LENGTH_1 | FileCheck %s -check-prefix=MIN_LENGTH_1
func test6(x: S1) {
x.#^MIN_LENGTH_1,f,o,b^#
}
// MIN_LENGTH_1-LABEL: Results for filterText: f [
// MIN_LENGTH_1-NEXT: fooBarBaz()
// MIN_LENGTH_1-NEXT: footastic()
// MIN_LENGTH_1-NEXT: fooBarTastic()
// MIN_LENGTH_1-NEXT: ]
// MIN_LENGTH_1-LABEL: Results for filterText: o [
// MIN_LENGTH_1-NEXT: ]
// MIN_LENGTH_1-LABEL: Results for filterText: b [
// MIN_LENGTH_1-NEXT: ]
2 changes: 1 addition & 1 deletion tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ void CodeCompletionOrganizer::Impl::addCompletionsWithFilter(
pattern.normalize = true;
for (Completion *completion : completions) {
bool match = false;
if (options.fuzzyMatching) {
if (options.fuzzyMatching && filterText.size() >= options.minFuzzyLength) {
match = pattern.matchesCandidate(completion->getName());
} else {
match = completion->getName().startswith_lower(filterText);
Expand Down
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct Options {
bool hideLowPriority = true;
bool hideByNameStyle = true;
bool fuzzyMatching = true;
unsigned minFuzzyLength = 2;

// Options for combining priorities. The defaults are chosen so that a fuzzy
// match just breaks ties within a semantic context. If semanticContextWeight
Expand Down

0 comments on commit 1144437

Please sign in to comment.