Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - support jvmRunEnvironment request for native launcher of scala-cli #2342

Merged
merged 1 commit into from Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -149,8 +149,8 @@ class SourceGeneratorTests extends munit.FunSuite {
|}
|""".stripMargin
)
}
}
}

}

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