scalameta / metals-feature-requests

Issue tracker for Metals feature requests
37 stars 4 forks source link

Disambiguate inferred type hints #268

Closed dzanot closed 10 months ago

dzanot commented 2 years ago

Is your feature request related to a problem? Please describe.

I have been using a pattern of re-using type names, and relying on package structure and qualified type references to distinguish them.

For example:

//repro.errors.scala
package com.repro.errors

case class A()
//repro.requests.scala
package com.repro.requests

case class A()
//repro.scala
package com.repro

object Main {
  case class A()
  val request = requests.A()
  val error   = errors.A()
  val local   = A()
}

Yields (in scala 3.1.1, vscode metals v1.13.0):

Screen Shot 2022-04-07 at 1 46 20 PM

Describe the solution you'd like

It would be nice if the inferred type hint had some disambiguation. Type on hover is more clear, for example: Screen Shot 2022-04-07 at 1 48 08 PM Screen Shot 2022-04-07 at 1 48 03 PM Screen Shot 2022-04-07 at 1 47 55 PM

Describe alternatives you've considered

Currently, you can get kind of disambiguated by exploiting how path dependent types are rendered:

//repro2.scala
package com.repro

object responses extends ResponsesT

trait ResponsesT {
  case class A()
}

object Main {
  case class A()

  val request  = requests.A()
  val error    = errors.A()
  val local    = A()
  val response = responses.A()
}

yields: Screen Shot 2022-04-07 at 1 51 16 PM

But bending code like this for the sake of this quirk seems not worth it.

Additional contex

Discussion in chat: https://discord.com/channels/632642981228314653/632652693013528589/961380730934525974

Search terms

Hints

tgodzik commented 10 months ago

Looks like this got fixed by @jkciesluk when he added the support in presentation compiler. This will be released today.