Skip to content

Commit

Permalink
Another probes
Browse files Browse the repository at this point in the history
  • Loading branch information
rochala committed Dec 19, 2023
1 parent abe0c24 commit 7d9a990
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ import java.lang
object BspClient {
case class BuildOutput(process: ProcessBuilder, diagnostics: List[Problem])

val runner212 = Fetch().addDependencies(
Dependency(Module(Organization("org.scastie"), ModuleName("runner_2.12")), BuildInfo.versionRuntime)
).run()

val runner213 = Fetch().addDependencies(
Dependency(Module(Organization("org.scastie"), ModuleName("runner_2.13")), BuildInfo.versionRuntime)
).run()

val runner3 = Fetch().addDependencies(
Dependency(Module(Organization("org.scastie"), ModuleName("runner_3")), BuildInfo.versionRuntime)
).run()

private def diagSeverityToSeverity(severity: DiagnosticSeverity): Severity = {
if (severity == DiagnosticSeverity.ERROR) api.Error
else if (severity == DiagnosticSeverity.INFORMATION) api.Info
Expand All @@ -71,18 +83,6 @@ trait ScalaCliServer extends BuildServer with ScalaBuildServer with JvmBuildServ
class BspClient(coloredStackTrace: Boolean, workingDir: Path, compilationTimeout: FiniteDuration, reloadTimeout: FiniteDuration) {
import BspClient._

val runner212 = Fetch().addDependencies(
Dependency(Module(Organization("org.scastie"), ModuleName("runner_2.12")), BuildInfo.versionRuntime)
).run()

val runner213 = Fetch().addDependencies(
Dependency(Module(Organization("org.scastie"), ModuleName("runner_2.13")), BuildInfo.versionRuntime)
).run()

val runner3 = Fetch().addDependencies(
Dependency(Module(Organization("org.scastie"), ModuleName("runner_3")), BuildInfo.versionRuntime)
).run()

private implicit val defaultTimeout: FiniteDuration = FiniteDuration(10, TimeUnit.SECONDS)
val diagnostics: AtomicReference[List[Diagnostic]] = new AtomicReference(Nil)
val gson = new Gson
Expand All @@ -95,17 +95,16 @@ class BspClient(coloredStackTrace: Boolean, workingDir: Path, compilationTimeout
Process(Seq("scala-cli", "setup-ide", workingDir.toAbsolutePath.toString)).!

private val processBuilder: java.lang.ProcessBuilder = new java.lang.ProcessBuilder()
val scalaCliExec = "/Users/jrochala/Library/Application Support/Coursier/bin/.scala-cli.aux"
val logFile = Files.createFile(workingDir.toAbsolutePath.resolve("bsp.error.log"))
processBuilder
.command("scala-cli", "--cli-version", "nightly", "bsp", workingDir.toAbsolutePath.toString)
.command("scala-cli", "--cli-version", "nightly", "bsp", "-v", "-v", "-v", workingDir.toAbsolutePath.toString)
.redirectError(logFile.toFile)

val scalaCliServer = processBuilder.start()

private val bspIn = scalaCliServer.getInputStream()
private val bspOut = scalaCliServer.getOutputStream()
private val bspErr = scalaCliServer.getOutputStream()
private val bspErr = scalaCliServer.getErrorStream()

log.info(s"Starting Scala-CLI BSP in folder ${workingDir.toAbsolutePath().normalize().toString()}")

Expand Down Expand Up @@ -137,15 +136,18 @@ class BspClient(coloredStackTrace: Boolean, workingDir: Path, compilationTimeout
private def requestWithTimeout[T](f: ScalaCliServer => CompletableFuture[T])(implicit timeout: FiniteDuration): Future[T] =
f(bspServer).orTimeout(timeout.length, timeout.unit).asScala

private def reloadWorkspace(): BspTask[Unit] = EitherT(requestWithTimeout(_.workspaceReload())(using reloadTimeout).map {
private def reloadWorkspace(retry: Int = 0): BspTask[Unit] = EitherT(requestWithTimeout(_.workspaceReload())(using reloadTimeout).flatMap {
case gsonMap: LinkedTreeMap[?, ?] if !gsonMap.isEmpty =>
val gson = new Gson()
val error = gson.fromJson(gson.toJson(gsonMap), classOf[ResponseError])
log.error(error.toString)
println(gsonMap)
println(error.getCode)
Left(InternalBspError(error.getMessage))
case _ => ().asRight
val gson = new Gson()
val error = gson.fromJson(gson.toJson(gsonMap), classOf[ResponseError])
log.info(s"Reload failed: ${error.getMessage}")
if (retry < 3) {
log.info(s"Reload failed, retry #$retry/3")
reloadWorkspace(retry + 1).value
} else {
Future.successful(Left(InternalBspError(error.getMessage)))
}
case _ => Future.successful(().asRight)
}
)

Expand Down

0 comments on commit 7d9a990

Please sign in to comment.