From d5eff2d89a13265c0850103fa61911972f115abb Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Wed, 2 Aug 2023 13:44:53 +0200 Subject: [PATCH] improvement: don't print rhs in type completion label --- .../pc/completions/CompletionValue.scala | 2 +- .../internal/pc/printer/MetalsPrinter.scala | 5 +++ .../test/scala/tests/pc/CompletionSuite.scala | 41 ++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionValue.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionValue.scala index 5e022f42e35..e618208fe53 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionValue.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionValue.scala @@ -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 = diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala index c0898d3688d..3f2f9bb552f 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/printer/MetalsPrinter.scala @@ -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 diff --git a/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala index 56ad5e7f55e..f7e4bdf0bbb 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala @@ -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@@ @@ -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@@ @@ -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 {