Ensuring both "Rebuild Project" and "Rebuild module" work from IntelliJ

This commit is contained in:
Igal Tabachnik 2021-08-28 13:50:12 +03:00
parent a920693c96
commit 20fcab4651
2 changed files with 27 additions and 1 deletions

View File

@ -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,

View File

@ -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"}"""