swiftlang / swiftlang/sourcekit-lsp

[SR-13653] SourceKit-LSP: show full type signature in autocompletion

Open
#511 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
3.9k
Forks
390
Avg merge
9d 5h
Merged PRs (30d)
3

Description

Previous ID SR-13653
Radar rdar://problem/69958775
Original Reporter @xAlien95
Type Improvement

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s SourceKit-LSP
Labels Improvement
Assignee None
Priority Medium

md5: 082a2c11b6e53a2c078c70bdfa52294a

Issue Description:

Currently, when typing max you get

max(_ x: Comparable, _ y: Comparable) -> Comparable

as a suggested type signature, which may led the user into thinking that the function accepts existential protocol types instead of a unique type "T: Comparable" in both the arguments and result (see attached image, P1 and P2 are protocols, C1 is a class).

It may be more useful to show

max<T: Comparable>(_ x: T, _ y: T) -> T

as suggested type signature, although less readable.

We have the same issue when typing in the function body:

protocol SomeProtocol {}
class SomeClass {}

func foo<T: Collection>(_ x: T) {
    x  // suggested as "x: Collection" instead of "x: T"
}

func bar<T: SomeClass & SomeProtocol>(_ x: T) { 
    x // suggested as "x: SomeProtocol" instead of "x: T" 
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Swift completion examples for max, foo, and bar in SourceKit-LSP, then trace the completion path that formats displayed type signatures. Compare the current existential-style output with the generic signatures described here; done means completions preserve the type parameter and its constraints in both function declarations and local values.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.