mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Following on from updating regular member completion, this hooks up unresolved member completion (i.e. .<complete here>) to the typeCheckForCodeCompletion API to generate completions from all solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any). This lets us produce unresolved member completions even when the contextual type is ambiguous or involves errors. Whenever typeCheckExpression is called on an expression containing a code completion expression and a CompletionCallback has been set, each solution formed is passed to the callback so the type of the completion expression can be extracted and used to lookup up the members to return.
58 lines
3.3 KiB
Swift
58 lines
3.3 KiB
Swift
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOAD_INT -swift-version=5 | %FileCheck %s -check-prefix=OVERLOAD_INT
|
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOAD_INTLITERAL -swift-version=5 | %FileCheck %s -check-prefix=OVERLOAD_INTLITERAL
|
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOAD_FLT -swift-version=5 | %FileCheck %s -check-prefix=OVERLOAD_FLT
|
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOAD_FLTLITERAL -swift-version=5 | %FileCheck %s -check-prefix=OVERLOAD_FLT
|
|
|
|
struct Messenger {
|
|
init() {}
|
|
func send(_ msg: Message) {}
|
|
}
|
|
|
|
struct Message : ExpressibleByStringInterpolation, ExpressibleByStringLiteral {
|
|
init(stringInterpolation: MsgInterpolation) {}
|
|
init(stringLiteral: String) {}
|
|
}
|
|
|
|
struct MsgInterpolation: StringInterpolationProtocol {
|
|
init() {}
|
|
init(literalCapacity: Int, interpolationCount: Int) {}
|
|
mutating func appendLiteral(_ literal: String) {}
|
|
|
|
enum IntFormat {
|
|
case decimal, hex
|
|
}
|
|
struct FloatFormat {
|
|
private init() {}
|
|
static func precision(_: Int) -> FloatFormat { fatalError() }
|
|
static var hex: FloatFormat { fatalError() }
|
|
}
|
|
mutating func appendInterpolation(_ value: @autoclosure () -> Int, format: IntFormat = .decimal) {}
|
|
mutating func appendInterpolation(_ value: @autoclosure () -> Float, format: FloatFormat = .hex) {}
|
|
}
|
|
|
|
var messenger = Messenger()
|
|
func testMessenger(intVal: Int, fltVal: Float) {
|
|
messenger.send(" \(intVal, format: .#^OVERLOAD_INT^#) ")
|
|
// OVERLOAD_INT: Begin completions, 3 items
|
|
// OVERLOAD_INT-DAG: Decl[EnumElement]/ExprSpecific/TypeRelation[Identical]: decimal[#MsgInterpolation.IntFormat#];
|
|
// OVERLOAD_INT-DAG: Decl[EnumElement]/ExprSpecific/TypeRelation[Identical]: hex[#MsgInterpolation.IntFormat#];
|
|
// OVERLOAD_INT-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): MsgInterpolation.IntFormat#})[#(into: inout Hasher) -> Void#];
|
|
// OVERLOAD_INT: End completions
|
|
|
|
messenger.send(" \(5, format: .#^OVERLOAD_INTLITERAL^#, extraneousArg: 10) ")
|
|
// OVERLOAD_INTLITERAL: Begin completions, 5 items
|
|
// OVERLOAD_INTLITERAL-DAG: Decl[EnumElement]/ExprSpecific/TypeRelation[Identical]: decimal[#MsgInterpolation.IntFormat#];
|
|
// OVERLOAD_INTLITERAL-DAG: Decl[EnumElement]/ExprSpecific/TypeRelation[Identical]: hex[#MsgInterpolation.IntFormat#];
|
|
// OVERLOAD_INTLITERAL-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): MsgInterpolation.IntFormat#})[#(into: inout Hasher) -> Void#];
|
|
// OVERLOAD_INTLITERAL-DAG: Decl[StaticMethod]/ExprSpecific/TypeRelation[Identical]: precision({#Int#})[#MsgInterpolation.FloatFormat#];
|
|
// OVERLOAD_INTLITERAL-DAG: Decl[StaticVar]/ExprSpecific/TypeRelation[Identical]: hex[#MsgInterpolation.FloatFormat#];
|
|
// OVERLOAD_INTLITERAL: End completions
|
|
|
|
messenger.send(" \(fltVal, format: .#^OVERLOAD_FLT^#) ")
|
|
messenger.send(" \(5.0, format: .#^OVERLOAD_FLTLITERAL^#) ")
|
|
// OVERLOAD_FLT: Begin completions, 2 items
|
|
// OVERLOAD_FLT-DAG: Decl[StaticMethod]/ExprSpecific/TypeRelation[Identical]: precision({#Int#})[#MsgInterpolation.FloatFormat#];
|
|
// OVERLOAD_FLT-DAG: Decl[StaticVar]/ExprSpecific/TypeRelation[Identical]: hex[#MsgInterpolation.FloatFormat#];
|
|
// OVERLOAD_FLT: End completions
|
|
}
|