mirror of https://github.com/sbt/sbt.git
Implement BSP buildTarget/resources command
This commit is contained in:
parent
56632c3893
commit
a0e3d89855
|
|
@ -405,6 +405,8 @@ object Keys {
|
||||||
val bspBuildTarget = taskKey[BuildTarget]("Description of the BSP build targets").withRank(DTask)
|
val bspBuildTarget = taskKey[BuildTarget]("Description of the BSP build targets").withRank(DTask)
|
||||||
val bspBuildTargetSources = inputKey[Unit]("").withRank(DTask)
|
val bspBuildTargetSources = inputKey[Unit]("").withRank(DTask)
|
||||||
val bspBuildTargetSourcesItem = taskKey[SourcesItem]("").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 bspBuildTargetDependencySources = inputKey[Unit]("").withRank(DTask)
|
||||||
val bspBuildTargetDependencySourcesItem = taskKey[DependencySourcesItem]("").withRank(DTask)
|
val bspBuildTargetDependencySourcesItem = taskKey[DependencySourcesItem]("").withRank(DTask)
|
||||||
val bspBuildTargetCompile = inputKey[Unit]("").withRank(DTask)
|
val bspBuildTargetCompile = inputKey[Unit]("").withRank(DTask)
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,19 @@ object BuildServerProtocol {
|
||||||
}
|
}
|
||||||
}.evaluated,
|
}.evaluated,
|
||||||
bspBuildTargetSources / aggregate := false,
|
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 {
|
bspBuildTargetDependencySources := Def.inputTaskDyn {
|
||||||
val s = state.value
|
val s = state.value
|
||||||
val workspace = bspWorkspace.value
|
val workspace = bspWorkspace.value
|
||||||
|
|
@ -201,6 +214,18 @@ object BuildServerProtocol {
|
||||||
})
|
})
|
||||||
SourcesItem(id, items)
|
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,
|
bspBuildTargetDependencySourcesItem := dependencySourcesItemTask.value,
|
||||||
bspBuildTargetCompileItem := bspCompileTask.value,
|
bspBuildTargetCompileItem := bspCompileTask.value,
|
||||||
bspBuildTargetRun := bspRunTask.evaluated,
|
bspBuildTargetRun := bspRunTask.evaluated,
|
||||||
|
|
@ -319,6 +344,12 @@ object BuildServerProtocol {
|
||||||
val targets = param.targets.map(_.uri).mkString(" ")
|
val targets = param.targets.map(_.uri).mkString(" ")
|
||||||
val command = Keys.bspScalaMainClasses.key
|
val command = Keys.bspScalaMainClasses.key
|
||||||
val _ = callback.appendExec(s"$command $targets", Some(r.id))
|
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,
|
onResponse = PartialFunction.empty,
|
||||||
onNotification = {
|
onNotification = {
|
||||||
|
|
|
||||||
|
|
@ -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 = {
|
private def initializeRequest(): Unit = {
|
||||||
svr.sendJsonRpc(
|
svr.sendJsonRpc(
|
||||||
"""{ "jsonrpc": "2.0", "id": "10", "method": "build/initialize",
|
"""{ "jsonrpc": "2.0", "id": "10", "method": "build/initialize",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue