Skip to content

Commit 4e33d50

Browse files
committed
[CodeCompletion] Bump the priority on keywords in the
experimental code-completion path. Move them right before "other module" results. This is a bit of a hack. Ideally, we would have a much better idea which keywords are actually legal/likely in a given context and could prioritize them even more. Since today we basically splat in all the keywords, keep them below the current module results so they don't overwhelm us. rdar://problem/25119529
1 parent c59dba7 commit 4e33d50

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

test/SourceKit/CodeComplete/complete_hide_low_priority.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func test(y: Int) {
2626
// NOHIDE: y
2727
// NOHIDE: z
2828
// NOHIDE: x
29+
// NOHIDE: import
2930
// NOHIDE: ModuleColor
3031
// NOHIDE: Int
31-
// NOHIDE: import
3232

3333
func testType() {
3434
let x: #^TOP_LEVEL_TYPE_0^#

test/SourceKit/CodeComplete/complete_sort_order.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func test() {
4040
// CONTEXT: key.name: "foo(b:)"
4141
// CONTEXT-NOT: key.name:
4242
// CONTEXT: key.name: "test()"
43-
// CONTEXT: key.name: "AbsoluteValuable"
4443
// CONTEXT: key.name: "#column"
44+
// CONTEXT: key.name: "AbsoluteValuable"
4545

4646
// RUN: %complete-test -tok=STMT_0 %s | FileCheck %s -check-prefix=STMT
4747
func test1() {
@@ -55,6 +55,29 @@ func test1() {
5555
// STMT: func
5656
// STMT: foo(a: Int)
5757

58+
// RUN: %complete-test -tok=STMT_1 %s | FileCheck %s -check-prefix=STMT_1
59+
func test5() {
60+
var retLocal: Int
61+
#^STMT_1,r,ret,retur,return^#
62+
}
63+
// STMT_1-LABEL: Results for filterText: r [
64+
// STMT_1-NEXT: retLocal
65+
// STMT_1-NEXT: repeat
66+
// STMT_1-NEXT: return
67+
// STMT_1-NEXT: required
68+
// STMT_1: ]
69+
// STMT_1-LABEL: Results for filterText: ret [
70+
// STMT_1-NEXT: retLocal
71+
// STMT_1-NEXT: return
72+
// STMT_1-NEXT: repeat
73+
// STMT_1: ]
74+
// STMT_1-LABEL: Results for filterText: retur [
75+
// STMT_1-NEXT: return
76+
// STMT_1: ]
77+
// STMT_1-LABEL: Results for filterText: return [
78+
// STMT_1-NEXT: return
79+
// STMT_1: ]
80+
5881
// RUN: %complete-test -top=0 -tok=EXPR_0 %s | FileCheck %s -check-prefix=EXPR
5982
func test2() {
6083
(#^EXPR_0^#)

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,17 @@ static double getSemanticContextScore(bool useImportDepth,
602602
if (useImportDepth && completion->getModuleImportDepth())
603603
depth = *completion->getModuleImportDepth();
604604
// We treat depth == 0 the same as CurrentModule.
605+
// Note: there is a gap in between that we use for keywords.
605606
order = (depth == 0) ? 5.0 : 6.0; // Base value.
606607
order += double(depth) / (Completion::maxModuleImportDepth + 1);
607608
assert((depth == 0 && order == 5.0) ||
608609
(depth && 6.0 <= order && order <= 7.0));
609610
break;
610611
}
611-
case SemanticContextKind::None: order = 8.0; break;
612+
case SemanticContextKind::None: {
613+
order = completion->getKind() == Completion::Keyword ? 5.5 : 8.0;
614+
break;
615+
}
612616
}
613617
assert(0.0 <= order && order <= 8.0);
614618
return (8.0 - order) / 8.0;

0 commit comments

Comments
 (0)