Skip to content

Commit

Permalink
Implementing buildTarget/cleanCache to support Rebuild operations f…
Browse files Browse the repository at this point in the history
…rom IntelliJ
  • Loading branch information
hmemcpy committed Aug 27, 2021
1 parent a199875 commit d5ae7a2
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main/src/main/scala/sbt/Keys.scala
Expand Up @@ -402,7 +402,7 @@ object Keys {
val bspTargetIdentifier = settingKey[BuildTargetIdentifier]("Build target identifier of a project and configuration.").withRank(DSetting)
val bspWorkspace = settingKey[Map[BuildTargetIdentifier, Scope]]("Mapping of BSP build targets to sbt scopes").withRank(DSetting)
private[sbt] val bspFullWorkspace = settingKey[BspFullWorkspace]("Mapping of BSP build targets to sbt scopes and meta-targets for the SBT build itself").withRank(DSetting)
val bspInternalDependencyConfigurations = settingKey[Seq[(ProjectRef, Set[ConfigKey])]]("The project configurations that this configuration depends on, possibly transitivly").withRank(DSetting)
val bspInternalDependencyConfigurations = settingKey[Seq[(ProjectRef, Set[ConfigKey])]]("The project configurations that this configuration depends on, possibly transitively").withRank(DSetting)
val bspWorkspaceBuildTargets = taskKey[Seq[BuildTarget]]("List all the BSP build targets").withRank(DTask)
val bspBuildTarget = taskKey[BuildTarget]("Description of the BSP build targets").withRank(DTask)
val bspBuildTargetSources = inputKey[Unit]("").withRank(DTask)
Expand All @@ -415,6 +415,7 @@ object Keys {
val bspBuildTargetCompileItem = taskKey[Int]("").withRank(DTask)
val bspBuildTargetTest = inputKey[Unit]("Corresponds to buildTarget/test request").withRank(DTask)
val bspBuildTargetRun = inputKey[Unit]("Corresponds to buildTarget/run request").withRank(DTask)
val bspBuildTargetCleanCache = inputKey[Unit]("Corresponds to buildTarget/cleanCache request").withRank(DTask)
val bspBuildTargetScalacOptions = inputKey[Unit]("").withRank(DTask)
val bspBuildTargetScalacOptionsItem = taskKey[ScalacOptionsItem]("").withRank(DTask)
val bspScalaTestClasses = inputKey[Unit]("Corresponds to buildTarget/scalaTestClasses request").withRank(DTask)
Expand Down
24 changes: 24 additions & 0 deletions main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala
Expand Up @@ -186,6 +186,23 @@ object BuildServerProtocol {
bspBuildTargetCompile / aggregate := false,
bspBuildTargetTest := bspTestTask.evaluated,
bspBuildTargetTest / aggregate := false,
bspBuildTargetCleanCache := Def.inputTaskDyn {
val s: State = state.value
val targets = spaceDelimited().parsed.map(uri => BuildTargetIdentifier(URI.create(uri)))
val workspace = bspFullWorkspace.value.filter(targets)
workspace.warnIfBuildsNonEmpty(Method.Compile, s.log)
// val filter = ScopeFilter.in(workspace.scopes.values.toList)
Def.task {
// val statusCodes = Keys.bspBuildTargetCleanCache.key.all(filter).value
// val statusCode = allOrThrow(statusCodes) match {
// case Seq() => false
// case other => true
// }
s.respondEvent(CleanCacheResult(None, true))
}
}.evaluated,
bspBuildTargetCleanCache / aggregate := false,
bspBuildTargetTest / aggregate := false,
bspBuildTargetScalacOptions := Def.inputTaskDyn {
val s = state.value

Expand Down Expand Up @@ -310,6 +327,7 @@ object BuildServerProtocol {
final val Compile = "buildTarget/compile"
final val Test = "buildTarget/test"
final val Run = "buildTarget/run"
final val CleanCache = "buildTarget/cleanCache"
final val ScalacOptions = "buildTarget/scalacOptions"
final val ScalaTestClasses = "buildTarget/scalaTestClasses"
final val ScalaMainClasses = "buildTarget/scalaMainClasses"
Expand Down Expand Up @@ -397,6 +415,12 @@ object BuildServerProtocol {
Some(r.id)
)

case r if r.method == Method.CleanCache =>
val param = Converter.fromJson[CleanCacheParams](json(r)).get
val targets = param.targets.map(_.uri).mkString(" ")
val command = Keys.bspBuildTargetCleanCache.key
val _ = callback.appendExec(s"$command $targets", Some(r.id))

case r if r.method == Method.ScalacOptions =>
val param = Converter.fromJson[ScalacOptionsParams](json(r)).get
val targets = param.targets.map(_.uri).mkString(" ")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions protocol/src/main/contraband/bsp.contra
Expand Up @@ -368,6 +368,21 @@ type BspCompileResult {
# data: any
}

## Clean Cache Request
type CleanCacheParams {
## A sequence of build targets to clean
targets: [sbt.internal.bsp.BuildTargetIdentifier]
}

## Clean Cache Response
type CleanCacheResult {
## Optional message to display to the user
message: String

## Indicates whether the clean cache request was performed or not
cleaned: Boolean!
}

## Compile Notifications

type CompileTask {
Expand Down
14 changes: 13 additions & 1 deletion server-test/src/test/scala/testpkg/BuildServerTest.scala
Expand Up @@ -7,7 +7,7 @@

package testpkg

import sbt.internal.bsp.{ BspCompileResult, SourcesResult, StatusCode, WorkspaceBuildTargetsResult }
import sbt.internal.bsp._
import sbt.internal.langserver.ErrorCodes
import sbt.IO

Expand Down Expand Up @@ -108,6 +108,18 @@ object BuildServerTest extends AbstractServerTest {
})
}

test("buildTarget/cleanCache") { _ =>
val buildTarget = buildTargetUri("util", "Compile")
svr.sendJsonRpc(
s"""{ "jsonrpc": "2.0", "id": "32", "method": "buildTarget/cleanCache", "params": {
| "targets": [{ "uri": "$buildTarget" }]
|} }""".stripMargin
)
assert(processing("buildTarget/cleanCache"))
val res = svr.waitFor[CleanCacheResult](10.seconds)
assert(res.cleaned)
}

test("workspace/reload") { _ =>
svr.sendJsonRpc(
"""{ "jsonrpc": "2.0", "id": "48", "method": "workspace/reload"}"""
Expand Down

0 comments on commit d5ae7a2

Please sign in to comment.