mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Prioritize type matching overload for unresovled member
For exmaple:
func foo(_: Int, _: IntOption)
func foo(_: Float, _: FloatOption)
foo(intVal, .<HERE>)
Previously code completion suggests static member from 'IntOption' and
'FloatOption' without any prioritization. Prioritize members from
'IntOption' because the user probably wants to input them.
In such cases, 'CodeCompletionExpr' at the cursor position is
pre-typechecked to 'IntOption'. So mark results with matching type with
'ExprSpecific'.
rdar://problem/62121221
This commit is contained in:
48
test/IDE/complete_string_interpolation.swift
Normal file
48
test/IDE/complete_string_interpolation.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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_FLT -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, 4 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[StaticMethod]/CurrNominal/TypeRelation[Identical]: precision({#Int#})[#MsgInterpolation.FloatFormat#];
|
||||
// OVERLOAD_INT-DAG: Decl[StaticVar]/CurrNominal/TypeRelation[Identical]: hex[#MsgInterpolation.FloatFormat#];
|
||||
// OVERLOAD_INT: End completions
|
||||
|
||||
messenger.send(" \(fltVal, format: .#^OVERLOAD_FLT^#) ")
|
||||
// OVERLOAD_FLT: Begin completions, 4 items
|
||||
// OVERLOAD_FLT-DAG: Decl[EnumElement]/CurrNominal/TypeRelation[Identical]: decimal[#MsgInterpolation.IntFormat#];
|
||||
// OVERLOAD_FLT-DAG: Decl[EnumElement]/CurrNominal/TypeRelation[Identical]: hex[#MsgInterpolation.IntFormat#];
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user