From 7745db391cb626ddf6a8ef32a5aab0b8000d39de Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Wed, 21 Feb 2024 12:27:36 +0100 Subject: [PATCH] improvement: Add inlayHints fallback suite --- .../meta/internal/metals/Compilers.scala | 1 + .../feature/InlayHintsFallbackSuite.scala | 43 +++++++++++++++ .../scala/tests/BaseInlayHintsLspSuite.scala | 54 ++++++++++++++++++ .../main/scala/tests/TestMtagsResolver.scala | 15 ++--- .../tests/inlayHints/InlayHintsLspSuite.scala | 55 ++----------------- 5 files changed, 108 insertions(+), 60 deletions(-) create mode 100644 tests/slow/src/test/scala/tests/feature/InlayHintsFallbackSuite.scala create mode 100644 tests/unit/src/main/scala/tests/BaseInlayHintsLspSuite.scala diff --git a/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala b/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala index 8da3a94e58e..8ed669053dc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Compilers.scala @@ -585,6 +585,7 @@ class Compilers( if (d.kind() <= 2) InlayHintKind.Type else InlayHintKind.Parameter hint.setKind(kind) + hint.setData(Array("")) hint } ) diff --git a/tests/slow/src/test/scala/tests/feature/InlayHintsFallbackSuite.scala b/tests/slow/src/test/scala/tests/feature/InlayHintsFallbackSuite.scala new file mode 100644 index 00000000000..65eb47b92ad --- /dev/null +++ b/tests/slow/src/test/scala/tests/feature/InlayHintsFallbackSuite.scala @@ -0,0 +1,43 @@ +package tests.feature + +import tests.BaseInlayHintsLspSuite + +class InlayHintsFallbackSuite + extends BaseInlayHintsLspSuite( + "inlayHints-fallback", + "3.4.0", + ) { + + check( + "all-synthetics", + """|import scala.concurrent.Future + |case class Location(city: String) + |object Main{ + | def hello()(implicit name: String, from: Location)/*: Unit*/ = { + | println(s"Hello $$name from $${from.city}") + | } + | implicit val andy : String = "Andy" + | + | def greeting()/*: Unit*/ = { + | implicit val boston/*: Location*/ = Location("Boston") + | hello()/*(andy, boston)*/ + | hello()/*(andy, boston)*/; hello()/*(andy, boston)*/ + | } + | + | val ordered/*: String*/ = /*augmentString(*/"acb"/*)*/.sorted/*(Char)*/ + | /*augmentString(*/"foo"/*)*/.map(c/*: Char*/ => c.toInt) + | implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global + | Future{ + | println("") + | }/*(ec)*/ + |} + |""".stripMargin, + config = Some( + """|"show-implicit-arguments": true, + |"show-implicit-conversions-and-classes": true, + |"show-inferred-type": minimal + |""".stripMargin + ), + ) + +} diff --git a/tests/unit/src/main/scala/tests/BaseInlayHintsLspSuite.scala b/tests/unit/src/main/scala/tests/BaseInlayHintsLspSuite.scala new file mode 100644 index 00000000000..9522ec570d4 --- /dev/null +++ b/tests/unit/src/main/scala/tests/BaseInlayHintsLspSuite.scala @@ -0,0 +1,54 @@ +package tests + +import munit.Location +import munit.TestOptions +import tests.BaseLspSuite +import tests.TestInlayHints + +abstract class BaseInlayHintsLspSuite(name: String, scalaVersion: String) + extends BaseLspSuite(name) { + def check( + name: TestOptions, + expected: String, + config: Option[String] = None, + dependencies: List[String] = Nil, + )(implicit + loc: Location + ): Unit = { + val initConfig = config + .map(config => s"""{ + |$config + |} + |""".stripMargin) + .getOrElse("""{ + | "show-implicit-arguments": true, + | "show-implicit-conversions-and-classes": true, + | "show-inferred-type": "true" + |} + |""".stripMargin) + val fileName = "Main.scala" + val code = TestInlayHints.removeInlayHints(expected) + test(name) { + for { + _ <- initialize( + s"""/metals.json + |{"a":{ + | "scalaVersion": "$scalaVersion", + | "libraryDependencies": ${toJsonArray(dependencies)} + |}} + |/a/src/main/scala/a/$fileName + |$code + """.stripMargin + ) + _ <- server.didOpen(s"a/src/main/scala/a/$fileName") + _ <- server.didChangeConfiguration(initConfig) + _ <- server.assertInlayHints( + s"a/src/main/scala/a/$fileName", + code, + expected, + workspace, + ) + } yield () + } + } +} diff --git a/tests/unit/src/main/scala/tests/TestMtagsResolver.scala b/tests/unit/src/main/scala/tests/TestMtagsResolver.scala index f118345ef3c..62de4ab1514 100644 --- a/tests/unit/src/main/scala/tests/TestMtagsResolver.scala +++ b/tests/unit/src/main/scala/tests/TestMtagsResolver.scala @@ -14,17 +14,12 @@ class TestMtagsResolver extends MtagsResolver { val default: MtagsResolver = MtagsResolver.default() - /** - * We don't need to check unsupported versions in tests and that makes the tests run longer. - */ override def resolve(scalaVersion: String): Option[MtagsBinaries] = { - if (ScalaVersions.isSupportedAtReleaseMomentScalaVersion(scalaVersion)) - default.resolve(scalaVersion).orElse(Some(MtagsBinaries.BuildIn)) - else None - } - - override def isSupportedScalaVersion(version: String): Boolean = { - ScalaVersions.isSupportedAtReleaseMomentScalaVersion(version) + default.resolve(scalaVersion).orElse { + if (ScalaVersions.isSupportedAtReleaseMomentScalaVersion(scalaVersion)) + Some(MtagsBinaries.BuildIn) + else None + } } override def isSupportedInOlderVersion(version: String): Boolean = diff --git a/tests/unit/src/test/scala/tests/inlayHints/InlayHintsLspSuite.scala b/tests/unit/src/test/scala/tests/inlayHints/InlayHintsLspSuite.scala index 9074c9b5449..bb18983f637 100644 --- a/tests/unit/src/test/scala/tests/inlayHints/InlayHintsLspSuite.scala +++ b/tests/unit/src/test/scala/tests/inlayHints/InlayHintsLspSuite.scala @@ -1,11 +1,11 @@ package tests.inlayHints -import munit.Location -import munit.TestOptions -import tests.BaseLspSuite -import tests.TestInlayHints +import scala.meta.internal.metals.{BuildInfo => V} -class InlayHintsLspSuite extends BaseLspSuite("implicits") { +import tests.BaseInlayHintsLspSuite + +class InlayHintsLspSuite + extends BaseInlayHintsLspSuite("implicits", V.scala213) { check( "all-synthetics", @@ -343,49 +343,4 @@ class InlayHintsLspSuite extends BaseLspSuite("implicits") { dependencies = List("co.fs2::fs2-core:3.9.0"), ) - def check( - name: TestOptions, - expected: String, - config: Option[String] = None, - dependencies: List[String] = Nil, - )(implicit - loc: Location - ): Unit = { - val initConfig = config - .map(config => s"""{ - |$config - |} - |""".stripMargin) - .getOrElse("""{ - | "show-implicit-arguments": true, - | "show-implicit-conversions-and-classes": true, - | "show-inferred-type": "true" - |} - |""".stripMargin) - val fileName = "Main.scala" - val libraryDependencies = - if (dependencies.isEmpty) "" - else - s""""libraryDependencies": [${dependencies.map(dep => s"\"$dep\"").mkString(",")}]""" - val code = TestInlayHints.removeInlayHints(expected) - test(name) { - for { - _ <- initialize( - s"""/metals.json - |{"a":{$libraryDependencies}} - |/a/src/main/scala/a/$fileName - |$code - """.stripMargin - ) - _ <- server.didOpen(s"a/src/main/scala/a/$fileName") - _ <- server.didChangeConfiguration(initConfig) - _ <- server.assertInlayHints( - s"a/src/main/scala/a/$fileName", - code, - expected, - workspace, - ) - } yield () - } - } }