Skip to content

[5.3][CodeCompletion] Skip to '=' after completion in 'if'/'guard' pattern #32286

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
7 changes: 6 additions & 1 deletion lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,8 +1500,13 @@ Parser::parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,

ThePattern = parseOptionalPatternTypeAnnotation(ThePattern,
BindingKindStr != "case");
if (ThePattern.hasCodeCompletion())
if (ThePattern.hasCodeCompletion()) {
Status.setHasCodeCompletion();

// Skip to '=' so that the completion can see the expected type of the
// pattern which is determined by the initializer.
skipUntilDeclStmtRBrace(tok::equal, tok::l_brace);
}

if (ThePattern.isNull()) {
// Recover by creating AnyPattern.
Expand Down
19 changes: 18 additions & 1 deletion test/IDE/complete_stmt_controlling_expr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_LET_BIND_7 | %FileCheck %s -check-prefix=FOOSTRUCT_LOCALVAL
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_LET_BIND_8 | %FileCheck %s -check-prefix=FOOSTRUCT_LOCALVAL

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_CASE_PATTERN_1| %FileCheck %s -check-prefix=OPTIONAL_FOOSTRUCT
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_CASE_PATTERN_2| %FileCheck %s -check-prefix=OPTIONAL_FOOSTRUCT

struct FooStruct {
var instanceVar : Int
init(_: Int = 0) { }
Expand Down Expand Up @@ -612,7 +615,12 @@ func testGuardLetBinding7(x: FooStruct?) {
func testGuardLetBinding8(_ x: FooStruct?) {
guard let boundVal = x, let other = testGuardLetBinding8(#^GUARD_LET_BIND_8^#) else {}
}

func testGuardCase(x:FooStruct?) {
guard case .#^GUARD_CASE_PATTERN_1^# = x {}
}
func testGuardCase(x:FooStruct?) {
guard case .#^GUARD_CASE_PATTERN_2^#some() = x {}
}

// FOOSTRUCT_DOT: Begin completions
// FOOSTRUCT_DOT-DAG: Decl[InstanceVar]/CurrNominal: instanceVar[#Int#];
Expand All @@ -635,3 +643,12 @@ func testGuardLetBinding8(_ x: FooStruct?) {
// FOOSTRUCT_LOCALVAL: Begin completions
// FOOSTRUCT_LOCALVAL-DAG: Decl[LocalVar]/Local{{(/TypeRelation\[Convertible\])?}}: boundVal[#FooStruct#];
// FOOSTRUCT_LOCALVAL: End completions

// OPTIONAL_FOOSTRUCT: Begin completions, 5 items
// OPTIONAL_FOOSTRUCT-DAG: Keyword[nil]/None/Erase[1]: nil[#FooStruct?#]; name=nil
// OPTIONAL_FOOSTRUCT-DAG: Decl[EnumElement]/CurrNominal/IsSystem: none[#Optional<FooStruct>#]; name=none
// OPTIONAL_FOOSTRUCT-DAG: Decl[EnumElement]/CurrNominal/IsSystem: some({#FooStruct#})[#Optional<FooStruct>#]; name=some(FooStruct)
// FIXME: 'FooStruct' members should not be shown.
// OPTIONAL_FOOSTRUCT-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init()[#FooStruct#]; name=init()
// OPTIONAL_FOOSTRUCT-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init({#Int#})[#FooStruct#]; name=init(Int)
// OPTIONAL_FOOSTRUCT: End completions