Skip to content

Commit

Permalink
bugfix: Don't show unhelpful renames in hover
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Feb 29, 2024
1 parent 4903c4f commit 8ac1f70
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ trait Signatures { compiler: MetalsGlobal =>
}

def getUsedRenames: Map[Symbol, String] = lookedUpRenames.flatMap { key =>
renames.get(key).map(v => key -> v.toString())
renames.get(key).collect {
case v if key.nameString != v.toString => key -> v.toString()
}
}.toMap

def this(context: Context) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class ShortenedNames(
s"type $to = ${from.showName}"
}.toList

def getUsedRenames: Map[Symbol, String] = foundRenames.toMap
def getUsedRenames(using Context): Map[Symbol, String] =
foundRenames.toMap.filter { case (k, v) => k.showName != v }

/**
* Returns a list of shortened names
Expand Down
20 changes: 20 additions & 0 deletions tests/cross/src/test/scala/tests/hover/HoverTermSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,24 @@ class HoverTermSuite extends BaseHoverSuite {
)
)

check(
"import-no-rename",
"""
|import scala.collection
|
|object O {
| <<val ab@@c = collection.Map(1 -> 2)>>
|}
|""".stripMargin,
"""|```scala
|val abc: collection.Map[Int,Int]
|```
|""".stripMargin,
compat = Map(
"3" -> """|```scala
|val abc: scala.collection.Map[Int, Int]
|```
|""".stripMargin
)
)
}

0 comments on commit 8ac1f70

Please # to comment.