Skip to content

Commit 9ce791a

Browse files
authored
Merge pull request #11695 from benlangmuir/cc-filter-non-postfix-4.0
[code-completion] Filter out non-postfix results from inner operators
2 parents 1cfada4 + 2450a74 commit 9ce791a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/SourceKit/CodeComplete/complete_inner.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ class FooBar {
1414
let prop: FooBar { return FooBar() }
1515
subscript(x: Foo) -> Foo {}
1616
}
17+
18+
enum E1 {
19+
case one
20+
case two
21+
}
22+
23+
// Note: this test uses line:column inputs as a workaround for a complete-test limitation.
24+
func test010(x: E1, y: FooBar) {
25+
switch x {
26+
case .:
27+
break
28+
case two:
29+
y.
30+
}
31+
}
32+
33+
// RUN: %sourcekitd-test -req=complete.open -pos=26:11 -req-opts=filtertext=one %s -- %s | %FileCheck %s -check-prefix=INNER_POSTFIX_0
34+
// INNER_POSTFIX_0-NOT: key.description: "one{{.+}}"
35+
// INNER_POSTFIX_0: key.description: "one",{{$}}
36+
// INNER_POSTFIX_0-NOT: key.description: "one{{.+}}"
37+
38+
// RUN: %sourcekitd-test -req=complete.open -pos=29:9 -req-opts=filtertext=prop %s -- %s | %FileCheck %s -check-prefix=INNER_POSTFIX_1
39+
// INNER_POSTFIX_1-NOT: key.description: "prop{{.+}}"
40+
// INNER_POSTFIX_1: key.description: "prop",{{$}}
41+
// INNER_POSTFIX_1-NOT: key.description: "prop{{.+}}"
42+
43+
1744
func test001() {
1845
#^TOP_LEVEL_0,fo,foo,foob,foobar^#
1946
}

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,9 @@ static void transformAndForwardResults(
10841084
SwiftCodeCompletionConsumer swiftConsumer([&](
10851085
MutableArrayRef<CodeCompletionResult *> results,
10861086
SwiftCompletionInfo &info) {
1087+
auto *context = info.completionContext;
1088+
if (!context || context->CodeCompletionKind != CompletionKind::PostfixExpr)
1089+
return;
10871090
auto topResults = filterInnerResults(results, options.addInnerResults,
10881091
options.addInnerOperators, hasDot,
10891092
hasQDot, hasInit, rules);

0 commit comments

Comments
 (0)