Skip to content

Commit

Permalink
Add support for cancel request for native launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Jun 9, 2023
1 parent db0dcd5 commit d16a80e
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -950,20 +950,104 @@
}
]
},
{
"name": "org.eclipse.lsp4j.jsonrpc.RemoteEndpoint",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.json.MessageConstants",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.json.MethodProvider",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.json.adapters.JsonElementTypeAdapter$Factory",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.CancelParams",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.Either",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.Message",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.MessageIssue",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.NotificationMessage",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.RequestMessage",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.ResponseError",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allDeclaredFields": true
},
{
"name": "org.scalajs.jsenv.ExternalJSRun",
"allDeclaredConstructors": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
attempts: Int = if (TestUtil.isCI) 3 else 1,
pauseDuration: FiniteDuration = 5.seconds,
bspOptions: List[String] = List.empty,
reuseRoot: Option[os.Path] = None
reuseRoot: Option[os.Path] = None,
stdErrOpt: Option[os.RelPath] = None
)(
f: (
os.Path,
Expand All @@ -88,10 +89,13 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
): T = {

def attempt(): Try[T] = Try {
val root = reuseRoot.getOrElse(inputs.root())
val inputsRoot = inputs.root()
val root = reuseRoot.getOrElse(inputsRoot)
val stdErrPathOpt: Option[os.ProcessOutput] = stdErrOpt.map(path => inputsRoot / path)
val stderr: os.ProcessOutput = stdErrPathOpt.getOrElse(os.Inherit)

val proc = os.proc(TestUtil.cli, "bsp", bspOptions ++ extraOptions, args)
.spawn(cwd = root)
.spawn(cwd = root, stderr = stderr)
var remoteServer: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer = null

val bspServerExited = Promise[Unit]()
Expand Down Expand Up @@ -1263,6 +1267,43 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
}
}
}
test("bsp should support cancel request for compile") {
val fileName = "Hello.scala"
val inputs = TestInputs(
os.rel / fileName ->
s"""object Hello extends App {
| while(true) {
| println("Hello World")
| }
|}
|""".stripMargin
)
withBsp(inputs, Seq("."), stdErrOpt = Some(os.rel / "stderr.txt")) {
(root, _, remoteServer) =>
async {
// prepare build
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
// build code
val targets = buildTargetsResp.getTargets.asScala.map(_.getId())
val compileResp = await {
remoteServer
.buildTargetCompile(new b.CompileParams(targets.asJava))
.asScala
}
expect(compileResp.getStatusCode == b.StatusCode.OK)

val Some(mainTarget) = targets.find(!_.getUri.contains("-test"))
val runRespFuture =
remoteServer
.buildTargetRun(new b.RunParams(mainTarget))
runRespFuture.cancel(true)
expect(runRespFuture.isCancelled || runRespFuture.isCompletedExceptionally)
expect(!os.read(root / "stderr.txt").contains(
"Unmatched cancel notification for request id null"
))
}
}
}
test("bsp should report actionable diagnostic when enabled") {
val fileName = "Hello.scala"
val inputs = TestInputs(
Expand Down

0 comments on commit d16a80e

Please sign in to comment.