Skip to content

Commit

Permalink
Fix - support jvmRunEnvironment request for native launcher of scala-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Aug 9, 2023
1 parent 694df1d commit d052e99
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class SourceGeneratorTests extends munit.FunSuite {
|}
|""".stripMargin
)
}
}
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.JvmMainClass",
"queryAllDeclaredMethods": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.JvmRunEnvironmentParams",
"allDeclaredConstructors": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scala.cli.integration

import ch.epfl.scala.bsp4j.BuildTargetIdentifier
import ch.epfl.scala.bsp4j.{BuildTargetIdentifier, JvmTestEnvironmentParams}
import ch.epfl.scala.bsp4j as b
import com.eed3si9n.expecty.Expecty.expect
import com.github.plokhotnyuk.jsoniter_scala.core.*
Expand Down Expand Up @@ -84,7 +84,7 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
f: (
os.Path,
TestBspClient,
b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer
b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer & b.JvmBuildServer
) => Future[T]
): T = {

Expand All @@ -96,7 +96,8 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])

val proc = os.proc(TestUtil.cli, "bsp", bspOptions ++ extraOptions, args)
.spawn(cwd = root, stderr = stderr)
var remoteServer: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer = null
var remoteServer: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer & b.JvmBuildServer =
null

val bspServerExited = Promise[Unit]()
val t = new Thread("bsp-server-watcher") {
Expand Down Expand Up @@ -1364,6 +1365,40 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
}
}
}
test("bsp should support jvmRunEnvironment request") {
val inputs = TestInputs(
os.rel / "Hello.scala" ->
s"""//> using dep "com.lihaoyi::os-lib:0.7.8"
|
|object Hello extends App {
| println("Hello")
|}
|""".stripMargin
)
withBsp(inputs, Seq(".")) {
(_, _, remoteServer) =>
async {
// prepare build
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
// build code
val targets = buildTargetsResp.getTargets.asScala.map(_.getId()).asJava

val jvmRunEnvironmentResult: b.JvmRunEnvironmentResult = await {
remoteServer
.jvmRunEnvironment(new b.JvmRunEnvironmentParams(targets))
.asScala
}
expect(jvmRunEnvironmentResult.getItems.asScala.toList.nonEmpty)

val jvmTestEnvironmentResult: b.JvmTestEnvironmentResult = await {
remoteServer
.jvmTestEnvironment(new JvmTestEnvironmentParams(targets))
.asScala
}
expect(jvmTestEnvironmentResult.getItems.asScala.toList.nonEmpty)
}
}
}

if (actualScalaVersion.startsWith("3"))
test("@main in script") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ trait RunScalaJsTestDefinitions { _: RunTestDefinitions =>
)
inputs.fromRoot { root =>
val thrown = os.proc(TestUtil.cli, extraOptions, fileName, "--js", "--server=false")
.call(cwd = root, env = Map("PATH" -> "", "PATHEXT" -> ""), check = false, mergeErrIntoOut = true)
.call(
cwd = root,
env = Map("PATH" -> "", "PATHEXT" -> ""),
check = false,
mergeErrIntoOut = true
)
val output = thrown.out.trim()

assert(thrown.exitCode == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ class TestBspClient extends b.BuildClient {
object TestBspClient {

private trait BuildServer extends b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer
with b.JvmBuildServer

def connect(
in: InputStream,
out: OutputStream,
es: ExecutorService
): (TestBspClient, b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer, Future[Unit]) = {
): (
TestBspClient,
b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer & b.JvmBuildServer,
Future[Unit]
) = {

val localClient = new TestBspClient

Expand Down

0 comments on commit d052e99

Please sign in to comment.