Skip to content

Commit

Permalink
improvement: Add inlayHints fallback suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Feb 28, 2024
1 parent 6496ae8 commit 7745db3
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ class Compilers(
if (d.kind() <= 2) InlayHintKind.Type
else InlayHintKind.Parameter
hint.setKind(kind)
hint.setData(Array(""))
hint
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
),
)

}
54 changes: 54 additions & 0 deletions tests/unit/src/main/scala/tests/BaseInlayHintsLspSuite.scala
Original file line number Diff line number Diff line change
@@ -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 ()
}
}
}
15 changes: 5 additions & 10 deletions tests/unit/src/main/scala/tests/TestMtagsResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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 ()
}
}
}

0 comments on commit 7745db3

Please sign in to comment.