Skip to content

Commit

Permalink
improvement: don't print rhs in type completion label
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Aug 2, 2023
1 parent 31f1812 commit d5eff2d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object CompletionValue:
if isFromWorkspace then
s"${labelWithSuffix(printer)} -${description(printer)}"
else s"${labelWithSuffix(printer)}${description(printer)}"
else if symbol.isType then s"$label${description(printer)}"
else if symbol.isType then labelWithSuffix(printer)
else s"$label: ${description(printer)}"

private def labelWithSuffix(printer: MetalsPrinter)(using Context): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class MetalsPrinter(
else " " + dotcPrinter.fullName(sym.effectiveOwner)
else if sym.is(Flags.Method) then
defaultMethodSignature(sym, info, onlyMethodParams = true)
else if sym.isType
then
info match
case TypeAlias(t) => " = " + tpe(t.resultType)
case t => tpe(t.resultType)
else tpe(info)
end if
end completionSymbol
Expand Down
41 changes: 40 additions & 1 deletion tests/cross/src/test/scala/tests/pc/CompletionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,20 @@ class CompletionSuite extends BaseCompletionSuite {

check(
"type-with-params",
s"""|object O {
| type TTT[A <: Int] = List[A]
| val t: TT@@
|}
|""".stripMargin,
"TTT",
compat = Map(
"3" -> "TTT[A <: Int]"
),
includeDetail = false,
)

check(
"type-with-params-with-detail",
s"""|object O {
| type TTT[A <: Int] = List[A]
| val t: TT@@
Expand All @@ -1643,11 +1657,23 @@ class CompletionSuite extends BaseCompletionSuite {
| val t: TT@@
|}
|""".stripMargin,
"TTT[A <: Int] = List[A]",
"TTT[A <: Int]",
includeDetail = false,
)

check(
"type-lambda2".tag(IgnoreScala2),
s"""|object O {
| type TTT[K <: Int] = [V] =>> Map[K, V]
| val t: TT@@
|}
|""".stripMargin,
"TTT[K <: Int]",
includeDetail = false,
)

check(
"type-lambda2-with-detail".tag(IgnoreScala2),
s"""|object O {
| type TTT[K <: Int] = [V] =>> Map[K, V]
| val t: TT@@
Expand All @@ -1656,6 +1682,19 @@ class CompletionSuite extends BaseCompletionSuite {
"TTT[K <: Int] = [V] =>> Map[K, V]",
)

check(
"type-bound",
s"""|trait O {
| type TTT <: Int
| val t: TT@@
|}
|""".stripMargin,
"TTT<: O.TTT",
compat = Map(
"3" -> "TTT <: Int"
),
)

check(
"class-with-params",
s"""|object O {
Expand Down

0 comments on commit d5eff2d

Please sign in to comment.