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 support for BSP's buildTarget/outputPaths and update bsp4j to 2… #1439

Merged
merged 1 commit into from
Oct 11, 2022
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
25 changes: 25 additions & 0 deletions modules/build/src/main/scala/scala/build/bsp/BspServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class BspServer(
logger.debug(s"invalid target in Test request: $target")
params
}
private def check(params: b.OutputPathsParams): params.type = {
val invalidTargets = params.getTargets.asScala.filter(!validTarget(_))
for (target <- invalidTargets)
logger.debug(s"invalid target in buildTargetOutputPaths request: $target")
params
}
private def mapGeneratedSources(res: b.SourcesResult): Unit = {
val gen = generatedSources.values.toVector
for {
Expand Down Expand Up @@ -221,6 +227,25 @@ class BspServer(
: CompletableFuture[b.DebugSessionAddress] =
super.debugSessionStart(check(params))

override def buildTargetOutputPaths(params: b.OutputPathsParams)
: CompletableFuture[b.OutputPathsResult] = {
check(params)
val targets = params.getTargets.asScala.filter(validTarget)
val outputPathsItem =
targets
.map(buildTargetId => (buildTargetId, targetWorkspaceDirOpt(buildTargetId)))
.collect { case (buildTargetId, Some(targetUri)) => (buildTargetId, targetUri) }
.map {
case (buildTargetId, targetUri) =>
new b.OutputPathsItem(
buildTargetId,
List(b.OutputPathItem(targetUri, b.OutputPathItemKind.DIRECTORY)).asJava
)
}

CompletableFuture.completedFuture(new b.OutputPathsResult(outputPathsItem.asJava))
}

override def workspaceBuildTargets(): CompletableFuture[b.WorkspaceBuildTargetsResult] =
super.workspaceBuildTargets().thenApply { res =>
maybeUpdateProjectTargetUri(res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class BuildServerProxy(
override def buildTargetWrappedSources(params: WrappedSourcesParams)
: CompletableFuture[WrappedSourcesResult] = bspServer().buildTargetWrappedSources(params)

override def buildTargetOutputPaths(params: b.OutputPathsParams)
: CompletableFuture[b.OutputPathsResult] =
bspServer().buildTargetOutputPaths(params)
override def workspaceReload(): CompletableFuture[AnyRef] =
onReload()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scala.build.bsp

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

import scala.build.internal.Constants
import scala.build.options.Scope
import scala.build.{GeneratedSource, Inputs}
import scala.collection.mutable
Expand Down Expand Up @@ -43,6 +44,11 @@ trait HasGeneratedSourcesImpl extends HasGeneratedSources {
generatedSources(scope) = GeneratedSources(sources)
}

protected def targetWorkspaceDirOpt(id: b.BuildTargetIdentifier): Option[String] =
projectNames.collectFirst {
case (_, projName) if projName.targetUriOpt.contains(id.getUri) =>
(projName.bloopWorkspace / Constants.workspaceDirName).toIO.toURI.toASCIIString
}
protected def targetScopeOpt(id: b.BuildTargetIdentifier): Option[Scope] =
projectNames.collectFirst {
case (scope, projName) if projName.targetUriOpt.contains(id.getUri) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ class LoggingBuildServerAll(
: CompletableFuture[WrappedSourcesResult] =
underlying.buildTargetWrappedSources(pprint.err.log(params)).logF

override def buildTargetOutputPaths(params: b.OutputPathsParams)
: CompletableFuture[b.OutputPathsResult] =
underlying.buildTargetOutputPaths(pprint.err.log(params)).logF

}
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,41 @@
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.OutputPathItem",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.OutputPathItemKind",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.OutputPathsItem",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.OutputPathsParams",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.OutputPathsResult",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "ch.epfl.scala.bsp4j.Position",
"allDeclaredConstructors": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,41 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
}
}

test("return .scala-build directory as a output paths") {
val inputs = TestInputs(
os.rel / "Hello.scala" ->
"""object Hello extends App {
| println("Hello World")
|}
|""".stripMargin
)
withBsp(inputs, Seq(".")) { (root, _, remoteServer) =>
async {
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
val target = {
val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
extractTestTargets(targets)
}

val resp = await(
remoteServer.buildTargetOutputPaths(new b.OutputPathsParams(List(target).asJava)).asScala
)
val outputPathsItems = resp.getItems.asScala
assert(outputPathsItems.nonEmpty)

val outputPathItem = outputPathsItems.head
val expectedOutputPathUri = (root / Constants.workspaceDirName).toIO.toURI.toASCIIString
val expectedOutputPathItem =
new b.OutputPathsItem(
target,
List(new b.OutputPathItem(expectedOutputPathUri, b.OutputPathItemKind.DIRECTORY)).asJava
)
expect(outputPathItem == expectedOutputPathItem)

}
}
}

test("using directive") {
val inputs = TestInputs(
os.rel / "test.sc" ->
Expand Down
2 changes: 1 addition & 1 deletion project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object Deps {
def asm = ivy"org.ow2.asm:asm:9.3"
// Force using of 2.13 - is there a better way?
def bloopConfig = ivy"io.github.alexarchambault.bleep:bloop-config_2.13:1.5.3-sc-1"
def bsp4j = ivy"ch.epfl.scala:bsp4j:2.1.0-M1"
def bsp4j = ivy"ch.epfl.scala:bsp4j:2.1.0-M2"
def caseApp = ivy"com.github.alexarchambault:case-app_2.13:2.1.0-M17"
def collectionCompat = ivy"org.scala-lang.modules::scala-collection-compat:2.8.1"
// Force using of 2.13 - is there a better way?
Expand Down