diff --git a/tests/unit/src/test/scala/tests/BillLspSuite.scala b/tests/unit/src/test/scala/tests/BillLspSuite.scala index 5a50c4ad3ec..87518ac29b1 100644 --- a/tests/unit/src/test/scala/tests/BillLspSuite.scala +++ b/tests/unit/src/test/scala/tests/BillLspSuite.scala @@ -10,6 +10,7 @@ import scala.meta.internal.metals.ServerCommands import scala.meta.io.AbsolutePath import bill._ +import ch.epfl.scala.bsp4j.StatusCode class BillLspSuite extends BaseLspSuite("bill") { @@ -222,4 +223,40 @@ class BillLspSuite extends BaseLspSuite("bill") { Bill.installGlobal(globalBsp.toNIO, "Bob") testSelectServerDialogue() } + + test("basic") { + val cancelPattern = + """Sending notification '\$\/cancelRequest'\s*Params: \{\s*\"id\": \"([0-9]+)\"\s*\}""".r + cleanWorkspace() + Bill.installWorkspace(workspace.toNIO, "Bill") + def trace = workspace.resolve(".metals/bsp.trace.json").readText + for { + _ <- initialize( + """|/src/com/App.scala + |object App { + | val x: Int = 1 + |} + |/.metals/bsp.trace.json + |""".stripMargin + ) + (compileReport, _) <- server.server.compilations + .compileFile( + workspace.resolve("src/com/App.scala") + ) + .zip { + // wait until the compilation start + Thread.sleep(1000) + server.executeCommand(ServerCommands.CancelCompile) + } + _ = assertEquals(compileReport.getStatusCode(), StatusCode.CANCELLED) + currentTrace = trace + cancelId = cancelPattern.findFirstMatchIn(currentTrace).get.group(1) + _ = assert(currentTrace.contains(s"buildTarget/compile - ($cancelId)")) + compileReport <- server.server.compilations + .compileFile( + workspace.resolve("src/com/App.scala") + ) + _ = assertEquals(compileReport.getStatusCode(), StatusCode.OK) + } yield () + } }