Skip to content

[CodeCompletion] Rebalance match score and semantic context #3649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions test/SourceKit/CodeComplete/complete_fuzzy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func test3() {
}

// RUN: %complete-test %s -fuzz -tok=CONTEXT_SORT_1 | FileCheck %s -check-prefix=CONTEXT_SORT_1
// RUN: %complete-test %s -fuzz -fuzzy-weight=10 -tok=CONTEXT_SORT_1 | FileCheck %s -check-prefix=CONTEXT_SORT_1
// RUN: %complete-test %s -fuzz -fuzzy-weight=1 -tok=CONTEXT_SORT_1 | FileCheck %s -check-prefix=CONTEXT_SORT_4
// RUN: %complete-test %s -fuzz -fuzzy-weight=100 -tok=CONTEXT_SORT_1 | FileCheck %s -check-prefix=CONTEXT_SORT_2
// RUN: %complete-test %s -fuzz -fuzzy-weight=10000 -no-inner-results -tok=CONTEXT_SORT_1 | FileCheck %s -check-prefix=CONTEXT_SORT_3
let myVar = 1
Expand All @@ -101,8 +101,8 @@ struct Test4 {

#^CONTEXT_SORT_1,myVa^#
// CONTEXT_SORT_1: Results for filterText: myVa [
// CONTEXT_SORT_1-NEXT: myLocalVar
// CONTEXT_SORT_1-NEXT: myVarTest4
// CONTEXT_SORT_1-NEXT: myLocalVar
// CONTEXT_SORT_1-NEXT: myVar

// CONTEXT_SORT_2: Results for filterText: myVa [
Expand All @@ -114,6 +114,11 @@ struct Test4 {
// CONTEXT_SORT_3-NEXT: myVar
// CONTEXT_SORT_3-NEXT: myVarTest4
// CONTEXT_SORT_3-NEXT: myLocalVar

// CONTEXT_SORT_4: Results for filterText: myVa [
// CONTEXT_SORT_4-NEXT: myLocalVar
// CONTEXT_SORT_4-NEXT: myVarTest4
// CONTEXT_SORT_4-NEXT: myVar
}
}

Expand Down Expand Up @@ -149,3 +154,25 @@ func test6(x: S1) {
// MIN_LENGTH_1-NEXT: ]
// MIN_LENGTH_1-LABEL: Results for filterText: b [
// MIN_LENGTH_1-NEXT: ]

// RUN: %complete-test %s -fuzz -tok=MAP | FileCheck %s -check-prefix=MAP
protocol P {
func map()
}
extension P {
func map() {}
}
struct Arr : P {
func withUnsafeMutablePointer() {}
}
func test7(x: Arr) {
x.#^MAP,ma,map^#
}
// MAP: Results for filterText: ma [
// MAP-NEXT: map()
// MAP-NEXT: withUnsafeMutablePointer()
// MAP-NEXT: ]
// MAP-LABEL: Results for filterText: map [
// MAP-NEXT: map()
// MAP-NEXT: withUnsafeMutablePointer()
// MAP-NEXT: ]
10 changes: 4 additions & 6 deletions test/SourceKit/CodeComplete/complete_popular_api.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ struct OuterNominal {
// POPULAR_STMT_0: localColor
// POPULAR_STMT_0: fromDerivedColor
// POPULAR_STMT_0: fromSuperColor
// POPULAR_STMT_0: fromOuterNominalColor
// POPULAR_STMT_0: good()
// POPULAR_STMT_0: globalColor
// POPULAR_STMT_0: okay()
// POPULAR_STMT_0: fromOuterNominalColor
// POPULAR_STMT_0: DDModuleColor
// POPULAR_STMT_0: CCModuleColor
// bad() ends up here because it's an unpopular global but that's still
// generally better than "other module" results.
// POPULAR_STMT_0: bad()
// POPULAR_STMT_0: EEModuleColor
// POPULAR_STMT_0: globalColor
// POPULAR_STMT_0: okay()
// POPULAR_STMT_0: ModuleCollaborate
// POPULAR_STMT_0: bad()
// POPULAR_STMT_0: ]
// POPULAR_STMT_0-LABEL: Results for filterText: col [
// POPULAR_STMT_0: argColor
Expand Down
11 changes: 4 additions & 7 deletions tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ struct Options {
unsigned minFuzzyLength = 2;
unsigned showTopNonLiteralResults = 3;

// Options for combining priorities. The defaults are chosen so that a fuzzy
// match just breaks ties within a semantic context. If semanticContextWeight
// isn't modified, a fuzzyMatchWeight of N means that a perfect match is worth
// the same as the worst possible match N/10 "contexts" ahead of it.
unsigned semanticContextWeight = 10 * Completion::numSemanticContexts;
unsigned fuzzyMatchWeight = 9;
unsigned popularityBonus = 5;
// Options for combining priorities.
unsigned semanticContextWeight = 15;
unsigned fuzzyMatchWeight = 10;
unsigned popularityBonus = 2;
};

struct SwiftCompletionInfo {
Expand Down