Skip to content

Commit 34a9063

Browse files
jturcottetgodzik
authored andcommitted
Implement BSP buildTarget/outputPaths
1 parent d54b8c9 commit 34a9063

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

frontend/src/main/scala/bloop/bsp/BloopBspServices.scala

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ final class BloopBspServices(
130130
.requestAsync(endpoints.BuildTarget.sources)(p => schedule(sources(p)))
131131
.requestAsync(endpoints.BuildTarget.inverseSources)(p => schedule(inverseSources(p)))
132132
.requestAsync(endpoints.BuildTarget.resources)(p => schedule(resources(p)))
133+
.requestAsync(endpoints.BuildTarget.outputPaths)(p => schedule(outputPaths(p)))
133134
.requestAsync(endpoints.BuildTarget.scalacOptions)(p => schedule(scalacOptions(p)))
134135
.requestAsync(endpoints.BuildTarget.javacOptions)(p => schedule(javacOptions(p)))
135136
.requestAsync(endpoints.BuildTarget.compile)(p => schedule(compile(p)))
@@ -311,7 +312,7 @@ final class BloopBspServices(
311312
dependencySourcesProvider = Some(true),
312313
dependencyModulesProvider = Some(true),
313314
resourcesProvider = Some(true),
314-
outputPathsProvider = None,
315+
outputPathsProvider = Some(true),
315316
buildTargetChangedProvider = Some(false),
316317
jvmTestEnvironmentProvider = Some(true),
317318
jvmRunEnvironmentProvider = Some(true),
@@ -1204,6 +1205,39 @@ final class BloopBspServices(
12041205
}
12051206
}
12061207

1208+
def outputPaths(
1209+
request: bsp.OutputPathsParams
1210+
): BspEndpointResponse[bsp.OutputPathsResult] = {
1211+
def outputPaths(
1212+
projects: Seq[ProjectMapping],
1213+
state: State
1214+
): BspResult[bsp.OutputPathsResult] = {
1215+
1216+
val response = bsp.OutputPathsResult(
1217+
projects.iterator.map {
1218+
case (target, project) =>
1219+
val outputPathItems =
1220+
List(
1221+
bsp.OutputPathItem(bsp.Uri(project.out.toBspUri), bsp.OutputPathItemKind.Directory)
1222+
)
1223+
bsp.OutputPathsItem(target, outputPathItems)
1224+
}.toList
1225+
)
1226+
1227+
Task.now((state, Right(response)))
1228+
}
1229+
1230+
ifInitialized(None) { (state: State, logger: BspServerLogger) =>
1231+
mapToProjects(request.targets, state) match {
1232+
case Left(error) =>
1233+
// Log the mapping error to the user via a log event + an error status code
1234+
logger.error(error)
1235+
Task.now((state, Right(bsp.OutputPathsResult(Nil))))
1236+
case Right(mappings) => outputPaths(mappings, state)
1237+
}
1238+
}
1239+
}
1240+
12071241
def dependencyModules(
12081242
request: bsp.DependencyModulesParams
12091243
): BspEndpointResponse[bsp.DependencyModulesResult] = {

frontend/src/test/scala/bloop/bsp/BspBaseSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ abstract class BspBaseSuite extends BaseSuite with BspClientTest {
349349
TestUtil.await(FiniteDuration(5, "s"))(resourcesTask)
350350
}
351351

352+
def requestOutputPaths(project: TestProject): bsp.OutputPathsResult = {
353+
val outputPathsTask = {
354+
client0
355+
.request(endpoints.BuildTarget.outputPaths, bsp.OutputPathsParams(List(project.bspId)))
356+
.map {
357+
case RpcFailure(_, error) => fail(s"Received error ${error}")
358+
case RpcSuccess(resources, _) => resources
359+
}
360+
}
361+
362+
TestUtil.await(FiniteDuration(5, "s"))(outputPathsTask)
363+
}
364+
352365
def requestDependencyModules(project: TestProject): bsp.DependencyModulesResult = {
353366
val dependencyModulesTask = {
354367
client0

frontend/src/test/scala/bloop/bsp/BspProtocolSpec.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,37 @@ class BspProtocolSpec(
516516
}
517517
}
518518

519+
test("outputPaths request works") {
520+
TestUtil.withinWorkspace { workspace =>
521+
val logger = new RecordingLogger(ansiCodesSupported = false)
522+
loadBspBuildFromResources("cross-test-build-scalajs-0.6", workspace, logger) { build =>
523+
val mainProject = build.projectFor("test-project")
524+
val testProject = build.projectFor("test-project-test")
525+
val mainJsProject = build.projectFor("test-projectJS")
526+
val testJsProject = build.projectFor("test-projectJS-test")
527+
val rootMain = build.projectFor("cross-test-build-scalajs-0-6")
528+
val rootTest = build.projectFor("cross-test-build-scalajs-0-6-test")
529+
530+
def checkOutputPaths(project: TestProject): Unit = {
531+
val outputPathsResult = build.state.requestOutputPaths(project)
532+
assert(outputPathsResult.items.size == 1)
533+
val outputPathsItem = outputPathsResult.items.head
534+
assert(outputPathsItem.target == project.bspId)
535+
val outputPaths = outputPathsItem.outputPaths.map(_.uri.toPath)
536+
val expectedOutputPaths = List(project.config.out.toAbsolutePath())
537+
assert(outputPaths == expectedOutputPaths)
538+
}
539+
540+
checkOutputPaths(mainProject)
541+
checkOutputPaths(testProject)
542+
checkOutputPaths(mainJsProject)
543+
checkOutputPaths(testJsProject)
544+
checkOutputPaths(rootMain)
545+
checkOutputPaths(rootTest)
546+
}
547+
}
548+
}
549+
519550
test("dependency modules request works") {
520551
TestUtil.withinWorkspace { workspace =>
521552
val logger = new RecordingLogger(ansiCodesSupported = false)

frontend/src/test/scala/bloop/bsp/TestConstants.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ object TestConstants {
1818
"dependencySourcesProvider": true,
1919
"dependencyModulesProvider": true,
2020
"resourcesProvider": true,
21+
"outputPathsProvider":true,
2122
"buildTargetChangedProvider": false,
2223
"jvmRunEnvironmentProvider": true,
2324
"jvmTestEnvironmentProvider": true,

0 commit comments

Comments
 (0)