Swift version
swiftlang-6.2.3.3.21
Platform
macOS 15
Editor
Visual Studio Code, main branch of SourceKit-LSP
Description
For a function like this:
func test(x: Int...) {
let y = x
}
SourceKit-LSP shows the inferred type for y to be Int.... Because the shown type is also the one that is inserted by double-clicking, SourceKit-LSP inserts Int... as the type for y which is not valid as variadic types are only allowed in function parameters.
I know that this issue probably has to be fixed in SourceKit, as SourceKit-LSP just displays the types that source.request.variable.type returns. However, as the source.request.variable.type request may also be used by other tools I'm not sure if we can just change the way variadic types are printed in the result. As a workaround, we could also just detect variadic types in the inlay hint code in SourceKit-LSP and replace them by the corresponding array type.
I'm open to providing a PR to fix this directly in SourceKit or for the workaround in SourceKit-LSP.
Steps to Reproduce
Inlay hint test case that reproduces this issue:
func testInferredVariadicParameter() async throws {
let (positions, hints) = try await performInlayHintRequest(
markedText: """
func test(x: Int...) {
let y1️⃣ = x
}
"""
)
assertHintsEqual(
hints,
[
makeInlayHint(
position: positions["1️⃣"],
kind: .type,
label: ": [Int]"
),
]
)
}
Logging
No response
Swift version
swiftlang-6.2.3.3.21
Platform
macOS 15
Editor
Visual Studio Code, main branch of SourceKit-LSP
Description
For a function like this:
SourceKit-LSP shows the inferred type for
yto beInt.... Because the shown type is also the one that is inserted by double-clicking, SourceKit-LSP insertsInt...as the type forywhich is not valid as variadic types are only allowed in function parameters.I know that this issue probably has to be fixed in SourceKit, as SourceKit-LSP just displays the types that
source.request.variable.typereturns. However, as thesource.request.variable.typerequest may also be used by other tools I'm not sure if we can just change the way variadic types are printed in the result. As a workaround, we could also just detect variadic types in the inlay hint code in SourceKit-LSP and replace them by the corresponding array type.I'm open to providing a PR to fix this directly in SourceKit or for the workaround in SourceKit-LSP.
Steps to Reproduce
Inlay hint test case that reproduces this issue:
Logging
No response