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

Add bsp JavaBuildServerForwardStubs #67

Merged
merged 2 commits into from
Jul 26, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package scala.build.bloop

import ch.epfl.scala.bsp4j

trait BuildServer extends bsp4j.BuildServer with bsp4j.ScalaBuildServer
trait BuildServer extends bsp4j.BuildServer with bsp4j.ScalaBuildServer with bsp4j.JavaBuildServer
2 changes: 1 addition & 1 deletion modules/build/src/main/scala/scala/build/bsp/BspImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ final class BspImpl(
)
actualLocalServer.setProjectName(inputs.workspace, inputs.projectName)

val localServer: b.BuildServer with b.ScalaBuildServer =
val localServer: b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer =
if (verbosity >= 3)
new LoggingBuildServerAll(actualLocalServer)
else
Expand Down
4 changes: 2 additions & 2 deletions modules/build/src/main/scala/scala/build/bsp/BspServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import scala.build.GeneratedSource
import scala.build.Logger

class BspServer(
bloopServer: b.BuildServer with b.ScalaBuildServer,
bloopServer: b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer,
compile: (() => CompletableFuture[b.CompileResult]) => CompletableFuture[b.CompileResult],
logger: Logger
) extends b.BuildServer with b.ScalaBuildServer with BuildServerForwardStubs with ScalaBuildServerForwardStubs with HasGeneratedSources {
) extends b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer with BuildServerForwardStubs with ScalaBuildServerForwardStubs with JavaBuildServerForwardStubs with HasGeneratedSources {

import BspServer._

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package scala.build.bsp

import ch.epfl.scala.bsp4j.{JavacOptionsParams, JavacOptionsResult}
import ch.epfl.scala.{bsp4j => b}

import java.util.concurrent.CompletableFuture

trait JavaBuildServerForwardStubs extends b.JavaBuildServer {
protected def forwardTo: b.JavaBuildServer

override def buildTargetJavacOptions(params: JavacOptionsParams): CompletableFuture[JavacOptionsResult] =
forwardTo.buildTargetJavacOptions(params)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package scala.build.bsp

import ch.epfl.scala.{bsp4j => b}

class LoggingBuildServerAll(val underlying: b.BuildServer with b.ScalaBuildServer)
extends LoggingBuildServer with LoggingScalaBuildServer
class LoggingBuildServerAll(val underlying: b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer)
extends LoggingBuildServer with LoggingScalaBuildServer with LoggingJavaBuildServer
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scala.build.bsp

import ch.epfl.scala.{bsp4j => b}

import java.util.concurrent.CompletableFuture

trait LoggingJavaBuildServer extends b.JavaBuildServer {
protected def underlying: b.JavaBuildServer
override def buildTargetJavacOptions(params: b.JavacOptionsParams): CompletableFuture[b.JavacOptionsResult] =
underlying.buildTargetJavacOptions(pprint.better.log(params)).logF
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ class BuildTests extends munit.FunSuite {
val end = new bsp4j.Position(2, 2)
val range = new bsp4j.Range(start, end)
val d = new bsp4j.Diagnostic(range, "not found: value zz")
d.setCode("zz")
d.setSource("bloop")
d.setSeverity(bsp4j.DiagnosticSeverity.ERROR)
d
Expand Down Expand Up @@ -282,7 +281,6 @@ class BuildTests extends munit.FunSuite {
val end = new bsp4j.Position(2, 0) // would have expected (2, 2) here :|
val range = new bsp4j.Range(start, end)
val d = new bsp4j.Diagnostic(range, "Not found: zz")
d.setCode("zz")
d.setSource("bloop")
d.setSeverity(bsp4j.DiagnosticSeverity.ERROR)
d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,34 @@
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.JavaBuildServer",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.JavacOptionsItem",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.JavacOptionsParams",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.JavacOptionsResult",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.JvmBuildServer",
"allDeclaredConstructors": true,
Expand Down Expand Up @@ -717,6 +745,13 @@
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "scala.build.bsp.JavaBuildServerForwardStubs",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "scala.build.bsp.LoggingBuildClient",
"allDeclaredConstructors": true,
Expand Down Expand Up @@ -745,6 +780,13 @@
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "scala.build.bsp.LoggingJavaBuildServer",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "scala.build.bsp.ScalaBuildServerForwardStubs",
"allDeclaredConstructors": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String]) extends m
pool.shutdown()
}

def withBsp[T](root: os.Path, args: Seq[String])(f: (TestBspClient, b.BuildServer with b.ScalaBuildServer) => Future[T]): T = {
def withBsp[T](root: os.Path, args: Seq[String])(f: (TestBspClient, b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer) => Future[T]): T = {

// Having issues with local sockets during the tests, never got those outside of tests…
val proc = os.proc(TestUtil.cli, "bsp", "--bloop-bsp-protocol", "tcp", extraOptions, args).spawn(cwd = root)
var remoteServer: b.BuildServer with b.ScalaBuildServer = null
var remoteServer: b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer = null

try {
val (localClient, remoteServer0, shutdownFuture) = TestBspClient.connect(proc.stdout, proc.stdin, pool)
Expand Down Expand Up @@ -179,6 +179,13 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String]) extends m
resp
}

val javacOptionsResp = {
val resp = await(remoteServer.buildTargetJavacOptions(new b.JavacOptionsParams(targets)).asScala)
val foundTargets = resp.getItems.asScala.map(_.getTarget.getUri).map(TestUtil.normalizeUri)
expect(foundTargets == Seq(targetUri))
resp
}

val classDir = os.Path(Paths.get(new URI(scalacOptionsResp.getItems.asScala.head.getClassDirectory)))

val compileResp = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class TestBspClient extends b.BuildClient {

object TestBspClient {

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

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

val localClient = new TestBspClient

Expand Down
2 changes: 1 addition & 1 deletion project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Deps {
}
def ammonite = ivy"com.lihaoyi:::ammonite:2.4.0-5-534c9436"
def asm = ivy"org.ow2.asm:asm:9.1"
def bloopConfig = ivy"ch.epfl.scala::bloop-config:1.4.8"
def bloopConfig = ivy"ch.epfl.scala::bloop-config:1.4.8-83-27d9d739"
def bsp4j = ivy"ch.epfl.scala:bsp4j:2.0.0-M13"
def caseApp = ivy"com.github.alexarchambault::case-app:2.1.0-M4"
def coursierJvm = ivy"io.get-coursier::coursier-jvm:${Versions.coursier}"
Expand Down