swiftlang/sourcekit-lsp

Types are not disambiguated

Opened this issue · 2 comments

Swift version

swiftlang-6.0.0.6.8

Platform

macOS 14.6.1

Editor

VSCode

Does the issue reproduce with Swift 6?

Yes

Description

In the example below, the type of a is main.Int and the type of b is Swift.Int. LSP seems to ignore that the using the unqualified Int is ambiguous in this context.

class Int {}
let a = Int()
let b = 1 + 1

Steps to Reproduce

In VSCode, type hints provided by SK-LSP show the same type for both variables. When double clicking the type hint, the inserted type is ambiguous. A similar issue appears when invoking the extract expression refactoring. When we try to extract 1 + 1, the generated code looks like let extractedExpr: Int = 1 + 1.

Logging

No response

It looks like the underlying SK requests never return qualified types. I added the fully_qualified option some time ago so we could process qualified types from SK. However, this makes all types qualified which might not be very user friendly when showing type hints.

There is the FullyQualifiedTypesIfAmbiguous option in PrintOptions.h, but after some quick testing the behaviour seems a bit unexpected. In the example I posted it only disambiguates the user introduced type, and not Swift.Int

Synced to Apple’s issue tracker as rdar://134708970