Files
swift-mirror/test/IDE/complete_rdar80489548.swift
Rintaro Ishizaki 1e018989c8 [CodeCompletion] Suggest 'in' after expression in closure
func test(value: [Int]) {
    value.map { value <HERE> }
  }

In this case 'value' in the closure is ambiguous between an expression
referring the outer function parameter, or a parameter declaration in
the closure. Previously, code completion only considered the former and
suggest the members of '[Int]', but not 'in' keyword. As a result, when
the user actually want to type 'in' here, they needed to hit 'esc' to
cancel the code completion.

In this change, suggest 'in' keyword even without a newline, as long as
the current decl context is a closure and it doesn't have 'in' in it.

Also previously 'in' was suggested even outside the closure and even it
already had the explict 'in'. This PR limit suggesting 'in' inside
closures without explicit 'in'.

rdar://80489548
2022-05-10 11:49:12 -07:00

27 lines
757 B
Swift

// RUN: %empty-directory(%t.ccp)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
// KW_IN: Keyword[in]/None: in{{; name=.+$}}
// KW_NO_IN-NOT: Keyword[in]
func test(value: [Int]) {
value.map { #^NOIN_IMMEDIATE?check=KW_IN^# }
value.map { value#^NOIN_AFTER_EXPR_NOSPCACE?check=KW_NO_IN^# }
value.map { value #^NOIN_AFTER_EXPR?check=KW_IN^# }
value.map { value
#^NOIN_NEWLINE?check=KW_IN^#
}
value.map { value in #^IN_AFTER_IN?check=KW_NO_IN^# }
value.map { value in
#^IN_NEWLINE?check=KW_NO_IN^#
}
#^FUNCBODY_STMT?check=KW_NO_IN^#
value #^FUNCBODY_POSTFIX?check=KW_NO_IN^#
}
#^GLOBAL_STMT?check=KW_NO_IN^#
value #^GLOBAL_POSTFIX?check=KW_NO_IN^#