diff --git a/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala b/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala index d9c11a5ada8c..b66fbe56fb9b 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala @@ -3,6 +3,7 @@ package dotty.tools.pc.printer import scala.collection.mutable import scala.meta.internal.jdk.CollectionConverters.* import scala.meta.internal.metals.ReportContext +import scala.meta.internal.mtags.KeywordWrapper import scala.meta.pc.SymbolDocumentation import scala.meta.pc.SymbolSearch @@ -64,6 +65,11 @@ class ShortenedTypePrinter( private val foundRenames = collection.mutable.LinkedHashMap.empty[Symbol, String] + override def nameString(name: Name): String = + val nameStr = super.nameString(name) + if (nameStr.nonEmpty) KeywordWrapper.Scala3Keywords.backtickWrap(nameStr) + else nameStr + def getUsedRenames: Map[Symbol, String] = foundRenames.toMap.filter { case (k, v) => k.showName != v } diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionKeywordSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionKeywordSuite.scala index bf7077d47b3f..5db0cf96d9ef 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionKeywordSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionKeywordSuite.scala @@ -433,6 +433,7 @@ class CompletionKeywordSuite extends BaseCompletionSuite: |given |extension |type + |opaque type |class |enum |case class diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala index 1d525c17bdf1..7be2ea6181ef 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala @@ -1136,7 +1136,7 @@ class CompletionSuite extends BaseCompletionSuite: | scala@@ |} |""".stripMargin, - """|scala + """|scala `` |""".stripMargin ) @@ -1726,8 +1726,8 @@ class CompletionSuite extends BaseCompletionSuite: check( """|import @@ |""".stripMargin, - """|java - |javax + """|java `` + |javax `` |""".stripMargin, filter = _.startsWith("java") ) @@ -1745,8 +1745,8 @@ class CompletionSuite extends BaseCompletionSuite: check( """|export @@ |""".stripMargin, - """|java - |javax + """|java `` + |javax `` |""".stripMargin, filter = _.startsWith("java") ) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala index f12cab7e65ef..a96dd78be138 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala @@ -597,6 +597,78 @@ class InsertInferredTypeSuite extends BaseCodeActionSuite: |""".stripMargin ) + @Test def `backticks-4` = + checkEdit( + """|case class `Foo-Foo`(i: Int) + |object O{ + | val <> = `Foo-Foo`(1) + |}""".stripMargin, + """|case class `Foo-Foo`(i: Int) + |object O{ + | val foo: `Foo-Foo` = `Foo-Foo`(1) + |} + |""".stripMargin + ) + + + @Test def `backticks-5` = + checkEdit( + """|object A{ + | case class `Foo-Foo`(i: Int) + |} + |object O{ + | val <> = A.`Foo-Foo`(1) + |}""".stripMargin, + """|import A.`Foo-Foo` + |object A{ + | case class `Foo-Foo`(i: Int) + |} + |object O{ + | val foo: `Foo-Foo` = A.`Foo-Foo`(1) + |} + |""".stripMargin + ) + + + @Test def `backticks-6` = + checkEdit( + """|object A{ + | case class `Foo-Foo`[A](i: A) + |} + |object O{ + | val <> = A.`Foo-Foo`(1) + |}""".stripMargin, + """|import A.`Foo-Foo` + |object A{ + | case class `Foo-Foo`[A](i: A) + |} + |object O{ + | val foo: `Foo-Foo`[Int] = A.`Foo-Foo`(1) + |} + |""".stripMargin + ) + + @Test def `backticks-7` = + checkEdit( + """|object A{ + | class `x-x` + | case class Foo[A](i: A) + |} + |object O{ + | val <> = A.Foo(new A.`x-x`) + |}""".stripMargin, + """|import A.Foo + |import A.`x-x` + |object A{ + | class `x-x` + | case class Foo[A](i: A) + |} + |object O{ + | val foo: Foo[`x-x`] = A.Foo(new A.`x-x`) + |} + |""".stripMargin + ) + @Test def `literal-types1` = checkEdit( """|object O { diff --git a/project/Build.scala b/project/Build.scala index 464ba4a86411..c1bf9c3e69f3 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1434,7 +1434,7 @@ object Build { BuildInfoPlugin.buildInfoDefaultSettings lazy val presentationCompilerSettings = { - val mtagsVersion = "1.3.5" + val mtagsVersion = "1.4.0" Seq( libraryDependencies ++= Seq( "org.lz4" % "lz4-java" % "1.8.0",