Skip to content

Commit

Permalink
improvement: Update mtags to 1.4.0 and backport remaining changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Oct 31, 2024
1 parent 31e7359 commit b9e7721
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ class CompletionKeywordSuite extends BaseCompletionSuite:
|given
|extension
|type
|opaque type
|class
|enum
|case class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ class CompletionSuite extends BaseCompletionSuite:
| scala@@
|}
|""".stripMargin,
"""|scala <root>
"""|scala `<root>`
|""".stripMargin
)

Expand Down Expand Up @@ -1726,8 +1726,8 @@ class CompletionSuite extends BaseCompletionSuite:
check(
"""|import @@
|""".stripMargin,
"""|java <root>
|javax <root>
"""|java `<root>`
|javax `<root>`
|""".stripMargin,
filter = _.startsWith("java")
)
Expand All @@ -1745,8 +1745,8 @@ class CompletionSuite extends BaseCompletionSuite:
check(
"""|export @@
|""".stripMargin,
"""|java <root>
|javax <root>
"""|java `<root>`
|javax `<root>`
|""".stripMargin,
filter = _.startsWith("java")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-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 <<foo>> = 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 <<foo>> = 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 <<foo>> = 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 {
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ object Build {
BuildInfoPlugin.buildInfoDefaultSettings

lazy val presentationCompilerSettings = {
val mtagsVersion = "1.3.5"
val mtagsVersion = "1.4.0+13-e3812b3f-SNAPSHOT"
Seq(
libraryDependencies ++= Seq(
"org.lz4" % "lz4-java" % "1.8.0",
Expand Down

0 comments on commit b9e7721

Please sign in to comment.