Skip to content

Commit b8603b8

Browse files
authored
Merge pull request #3649 from benlangmuir/context-match-rebalance
2 parents 488e335 + f962e74 commit b8603b8

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

test/SourceKit/CodeComplete/complete_fuzzy.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func test3() {
9090
}
9191

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

102102
#^CONTEXT_SORT_1,myVa^#
103103
// CONTEXT_SORT_1: Results for filterText: myVa [
104-
// CONTEXT_SORT_1-NEXT: myLocalVar
105104
// CONTEXT_SORT_1-NEXT: myVarTest4
105+
// CONTEXT_SORT_1-NEXT: myLocalVar
106106
// CONTEXT_SORT_1-NEXT: myVar
107107

108108
// CONTEXT_SORT_2: Results for filterText: myVa [
@@ -114,6 +114,11 @@ struct Test4 {
114114
// CONTEXT_SORT_3-NEXT: myVar
115115
// CONTEXT_SORT_3-NEXT: myVarTest4
116116
// CONTEXT_SORT_3-NEXT: myLocalVar
117+
118+
// CONTEXT_SORT_4: Results for filterText: myVa [
119+
// CONTEXT_SORT_4-NEXT: myLocalVar
120+
// CONTEXT_SORT_4-NEXT: myVarTest4
121+
// CONTEXT_SORT_4-NEXT: myVar
117122
}
118123
}
119124

@@ -149,3 +154,25 @@ func test6(x: S1) {
149154
// MIN_LENGTH_1-NEXT: ]
150155
// MIN_LENGTH_1-LABEL: Results for filterText: b [
151156
// MIN_LENGTH_1-NEXT: ]
157+
158+
// RUN: %complete-test %s -fuzz -tok=MAP | FileCheck %s -check-prefix=MAP
159+
protocol P {
160+
func map()
161+
}
162+
extension P {
163+
func map() {}
164+
}
165+
struct Arr : P {
166+
func withUnsafeMutablePointer() {}
167+
}
168+
func test7(x: Arr) {
169+
x.#^MAP,ma,map^#
170+
}
171+
// MAP: Results for filterText: ma [
172+
// MAP-NEXT: map()
173+
// MAP-NEXT: withUnsafeMutablePointer()
174+
// MAP-NEXT: ]
175+
// MAP-LABEL: Results for filterText: map [
176+
// MAP-NEXT: map()
177+
// MAP-NEXT: withUnsafeMutablePointer()
178+
// MAP-NEXT: ]

test/SourceKit/CodeComplete/complete_popular_api.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,15 @@ struct OuterNominal {
7979
// POPULAR_STMT_0: localColor
8080
// POPULAR_STMT_0: fromDerivedColor
8181
// POPULAR_STMT_0: fromSuperColor
82-
// POPULAR_STMT_0: fromOuterNominalColor
8382
// POPULAR_STMT_0: good()
84-
// POPULAR_STMT_0: globalColor
85-
// POPULAR_STMT_0: okay()
83+
// POPULAR_STMT_0: fromOuterNominalColor
8684
// POPULAR_STMT_0: DDModuleColor
8785
// POPULAR_STMT_0: CCModuleColor
88-
// bad() ends up here because it's an unpopular global but that's still
89-
// generally better than "other module" results.
90-
// POPULAR_STMT_0: bad()
9186
// POPULAR_STMT_0: EEModuleColor
87+
// POPULAR_STMT_0: globalColor
88+
// POPULAR_STMT_0: okay()
9289
// POPULAR_STMT_0: ModuleCollaborate
90+
// POPULAR_STMT_0: bad()
9391
// POPULAR_STMT_0: ]
9492
// POPULAR_STMT_0-LABEL: Results for filterText: col [
9593
// POPULAR_STMT_0: argColor

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ struct Options {
4141
unsigned minFuzzyLength = 2;
4242
unsigned showTopNonLiteralResults = 3;
4343

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

5350
struct SwiftCompletionInfo {

0 commit comments

Comments
 (0)