Skip to content

[code-completion] Filter out non-postfix results from inner operators #11695

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
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
27 changes: 27 additions & 0 deletions test/SourceKit/CodeComplete/complete_inner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ class FooBar {
let prop: FooBar { return FooBar() }
subscript(x: Foo) -> Foo {}
}

enum E1 {
case one
case two
}

// Note: this test uses line:column inputs as a workaround for a complete-test limitation.
func test010(x: E1, y: FooBar) {
switch x {
case .:
break
case two:
y.
}
}

// RUN: %sourcekitd-test -req=complete.open -pos=26:11 -req-opts=filtertext=one %s -- %s | %FileCheck %s -check-prefix=INNER_POSTFIX_0
// INNER_POSTFIX_0-NOT: key.description: "one{{.+}}"
// INNER_POSTFIX_0: key.description: "one",{{$}}
// INNER_POSTFIX_0-NOT: key.description: "one{{.+}}"

// RUN: %sourcekitd-test -req=complete.open -pos=29:9 -req-opts=filtertext=prop %s -- %s | %FileCheck %s -check-prefix=INNER_POSTFIX_1
// INNER_POSTFIX_1-NOT: key.description: "prop{{.+}}"
// INNER_POSTFIX_1: key.description: "prop",{{$}}
// INNER_POSTFIX_1-NOT: key.description: "prop{{.+}}"


func test001() {
#^TOP_LEVEL_0,fo,foo,foob,foobar^#
}
Expand Down
3 changes: 3 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,9 @@ static void transformAndForwardResults(
SwiftCodeCompletionConsumer swiftConsumer([&](
MutableArrayRef<CodeCompletionResult *> results,
SwiftCompletionInfo &info) {
auto *context = info.completionContext;
if (!context || context->CodeCompletionKind != CompletionKind::PostfixExpr)
return;
auto topResults = filterInnerResults(results, options.addInnerResults,
options.addInnerOperators, hasDot,
hasQDot, hasInit, rules);
Expand Down