Implement BSP buildTarget/resources command

This commit is contained in:
Samuel CLARENC 2021-06-17 11:09:08 +02:00
parent 56632c3893
commit a0e3d89855
3 changed files with 46 additions and 0 deletions

View File

@ -405,6 +405,8 @@ object Keys {
val bspBuildTarget = taskKey[BuildTarget]("Description of the BSP build targets").withRank(DTask)
val bspBuildTargetSources = inputKey[Unit]("").withRank(DTask)
val bspBuildTargetSourcesItem = taskKey[SourcesItem]("").withRank(DTask)
val bspBuildTargetResources = inputKey[Unit]("").withRank(DTask)
val bspBuildTargetResourcesItem = taskKey[ResourcesItem]("").withRank(DTask)
val bspBuildTargetDependencySources = inputKey[Unit]("").withRank(DTask)
val bspBuildTargetDependencySourcesItem = taskKey[DependencySourcesItem]("").withRank(DTask)
val bspBuildTargetCompile = inputKey[Unit]("").withRank(DTask)

View File

@ -117,6 +117,19 @@ object BuildServerProtocol {
}
}.evaluated,
bspBuildTargetSources / aggregate := false,
bspBuildTargetResources := Def.inputTaskDyn {
val s = state.value
val workspace = bspWorkspace.value
val targets = spaceDelimited().parsed.map(uri => BuildTargetIdentifier(URI.create(uri)))
val filter = ScopeFilter.in(targets.map(workspace))
// run the worker task concurrently
Def.task {
val items = bspBuildTargetResourcesItem.all(filter).value
val result = ResourcesResult(items.toVector)
s.respondEvent(result)
}
}.evaluated,
bspBuildTargetResources / aggregate := false,
bspBuildTargetDependencySources := Def.inputTaskDyn {
val s = state.value
val workspace = bspWorkspace.value
@ -201,6 +214,18 @@ object BuildServerProtocol {
})
SourcesItem(id, items)
},
bspBuildTargetResourcesItem := {
val id = bspTargetIdentifier.value
// Trigger resource generation
val _ = managedResources.value
val uris = resourceDirectories.value.toVector
.map { resourceDirectory =>
// Add any missing ending slash to the URI to explicitly mark it as a directory
// See https://github.com/build-server-protocol/build-server-protocol/issues/181 for more information
URI.create(s"${resourceDirectory.toURI.toString.replaceAll("([^/])$", "$1/")}")
}
ResourcesItem(id, uris)
},
bspBuildTargetDependencySourcesItem := dependencySourcesItemTask.value,
bspBuildTargetCompileItem := bspCompileTask.value,
bspBuildTargetRun := bspRunTask.evaluated,
@ -319,6 +344,12 @@ object BuildServerProtocol {
val targets = param.targets.map(_.uri).mkString(" ")
val command = Keys.bspScalaMainClasses.key
val _ = callback.appendExec(s"$command $targets", Some(r.id))
case r if r.method == "buildTarget/resources" =>
val param = Converter.fromJson[ResourcesParams](json(r)).get
val targets = param.targets.map(_.uri).mkString(" ")
val command = Keys.bspBuildTargetResources.key
val _ = callback.appendExec(s"$command $targets", Some(r.id))
},
onResponse = PartialFunction.empty,
onNotification = {

View File

@ -200,6 +200,19 @@ object BuildServerTest extends AbstractServerTest {
})
}
test("buildTarget/resources") { _ =>
val x = s"${svr.baseDirectory.getAbsoluteFile.toURI}#util/Compile"
svr.sendJsonRpc(
s"""{ "jsonrpc": "2.0", "id": "23", "method": "buildTarget/resources", "params": {
| "targets": [{ "uri": "$x" }]
|} }""".stripMargin
)
assert(processing("buildTarget/resources"))
assert(svr.waitForString(10.seconds) { s =>
(s contains """"id":"23"""") && (s contains "util/src/main/resources/")
})
}
private def initializeRequest(): Unit = {
svr.sendJsonRpc(
"""{ "jsonrpc": "2.0", "id": "10", "method": "build/initialize",