Skip to content

Commit 1878be2

Browse files
committed
[CodeCompletion] Don't complete .members after a space
This lets us filter down to binary operators, etc. rdar://problem/25994246
1 parent 69967ca commit 1878be2

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
26542654
if (HaveLParen)
26552655
return;
26562656

2657+
if (HaveLeadingSpace && !HaveDot)
2658+
return;
2659+
26572660
if (auto *VD = dyn_cast<VarDecl>(D)) {
26582661
addVarDeclRef(VD, Reason);
26592662
return;

test/IDE/complete_value_expr.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_TYPEALIAS_1 | FileCheck %s -check-prefix=GENERIC_TYPEALIAS_1
171171
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_TYPEALIAS_2 | FileCheck %s -check-prefix=GENERIC_TYPEALIAS_2
172172

173+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AFTER_SPACE_1 | FileCheck %s -check-prefix=AFTER_SPACE_1
174+
173175
// Test code completion of expressions that produce a value.
174176

175177
struct FooStruct {
@@ -1882,3 +1884,8 @@ func testGenericTypealias2() {
18821884
Enclose.#^GENERIC_TYPEALIAS_2^#
18831885
}
18841886
// GENERIC_TYPEALIAS_2: Decl[TypeAlias]/CurrNominal: MyPair[#(T, T)#];
1887+
1888+
func testAfterSpace(x: Int?) {
1889+
x #^AFTER_SPACE_1^#
1890+
// AFTER_SPACE_1-NOT: CurrNominal
1891+
}

test/SourceKit/CodeComplete/complete_operators.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// RUN: %complete-test -tok=OPT_OPERATORS %s | FileCheck %s -check-prefix=OPT
66
// RUN: %complete-test -tok=KNOWN_OPERATORS_1 %s | FileCheck %s -check-prefix=KNOWN
77
// RUN: %complete-test -tok=KNOWN_OPERATORS_2 %s | FileCheck %s -check-prefix=KNOWN
8+
// RUN: %complete-test -tok=NO_DOT %s | FileCheck %s -check-prefix=NO_DOT
89

910
struct MyInt {
1011
var bigPowers: Int { return 1 }
@@ -167,3 +168,11 @@ func test6(x: DoesEverything) {
167168
// KNOWN: ===
168169
// KNOWN: !==
169170
// KNOWN: ~=
171+
172+
func test7() {
173+
var x: DoesEverything
174+
x #^NO_DOT^#
175+
}
176+
// NO_DOT-NOT: .
177+
// NO_DOT: =
178+
// NO_DOT: ==

0 commit comments

Comments
 (0)