diff --git a/main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala b/main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala index 0853d83c5..401bf6d31 100644 --- a/main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala +++ b/main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala @@ -194,7 +194,13 @@ object BuildServerProtocol { val filter = ScopeFilter.in(workspace.scopes.values.toList) Def.task { val results = Keys.clean.result.all(filter).value - val cleaned = anyOrThrow(results).size == targets.size + val successes = anyOrThrow(results).size + + // When asking to Rebuild Project, IntelliJ sends the root build as an additional target, however it is + // not returned as part of the results. In this case, there's 1 build entry in the workspace, and we're + // checking that the executed results plus this entry is equal to the total number of targets. + // When rebuilding a single module, the root build isn't sent, just the requested targets. + val cleaned = successes + workspace.builds.size == targets.size s.respondEvent(CleanCacheResult(None, cleaned)) } }.evaluated, diff --git a/server-test/src/test/scala/testpkg/BuildServerTest.scala b/server-test/src/test/scala/testpkg/BuildServerTest.scala index d29a8c880..d54659038 100644 --- a/server-test/src/test/scala/testpkg/BuildServerTest.scala +++ b/server-test/src/test/scala/testpkg/BuildServerTest.scala @@ -138,6 +138,26 @@ object BuildServerTest extends AbstractServerTest { assert(targetDir.list().isEmpty) } + test("buildTarget/cleanCache: rebuild project") { _ => + svr.sendJsonRpc( + """{ "jsonrpc": "2.0", "id": "45", "method": "workspace/buildTargets", "params": {} }""" + ) + assert(processing("workspace/buildTargets")) + val result = svr.waitFor[WorkspaceBuildTargetsResult](10.seconds) + val allTargets = result.targets.map(_.id.uri) + + svr.sendJsonRpc( + s"""{ "jsonrpc": "2.0", "id": "46", "method": "buildTarget/cleanCache", "params": { + | "targets": [ + | ${allTargets.map(uri => s"""{ "uri": "$uri" }""").mkString(",\n")} + | ] + |} }""".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"}"""