diff --git a/examples/simple-no-errors/.bsp/bazel-bsp.json b/examples/simple-no-errors/.bsp/bazel-bsp.json index 86cd996..d9d8b87 100644 --- a/examples/simple-no-errors/.bsp/bazel-bsp.json +++ b/examples/simple-no-errors/.bsp/bazel-bsp.json @@ -1,12 +1,12 @@ + { "name": "BazelBsp", - "version": "0.0.1", - "bspVersion": "2.0.0", + "version": "0.0.13", + "bspVersion": "2.0.0-M2", "languages": [ "scala" ], "argv": [ - "../../target/universal/stage/bin/bazel-bsp", - "--verbose" + "bazel-bsp" ] -} \ No newline at end of file +} diff --git a/examples/simple-no-errors/bazel b/examples/simple-no-errors/bazel index 25e3fdf..36b22a6 100755 Binary files a/examples/simple-no-errors/bazel and b/examples/simple-no-errors/bazel differ diff --git a/examples/simple-with-errors/.bsp/bazel-bsp.json b/examples/simple-with-errors/.bsp/bazel-bsp.json index 86cd996..d9d8b87 100644 --- a/examples/simple-with-errors/.bsp/bazel-bsp.json +++ b/examples/simple-with-errors/.bsp/bazel-bsp.json @@ -1,12 +1,12 @@ + { "name": "BazelBsp", - "version": "0.0.1", - "bspVersion": "2.0.0", + "version": "0.0.13", + "bspVersion": "2.0.0-M2", "languages": [ "scala" ], "argv": [ - "../../target/universal/stage/bin/bazel-bsp", - "--verbose" + "bazel-bsp" ] -} \ No newline at end of file +} diff --git a/examples/simple-with-errors/bazel b/examples/simple-with-errors/bazel index 25e3fdf..36b22a6 100755 Binary files a/examples/simple-with-errors/bazel and b/examples/simple-with-errors/bazel differ diff --git a/src/main/scala/afenton/bazel/bsp/BazelBspApp.scala b/src/main/scala/afenton/bazel/bsp/BazelBspApp.scala index ebf6588..e9285b2 100644 --- a/src/main/scala/afenton/bazel/bsp/BazelBspApp.scala +++ b/src/main/scala/afenton/bazel/bsp/BazelBspApp.scala @@ -22,15 +22,18 @@ import fs2.Pipe import fs2.Stream import fs2.io.file.Files import fs2.io.file.Flags -import fs2.io.file.Path import fs2.text import io.bazel.rules_scala.diagnostics.diagnostics.FileDiagnostics import io.circe.Json import io.circe.syntax.* import java.net.ServerSocket +import java.nio.file.Path import java.nio.file.Paths import cats.data.Nested +import java.nio.file.StandardOpenOption +import scala.concurrent.duration.FiniteDuration +import java.util.concurrent.TimeUnit object BazelBspApp extends CommandIOApp( @@ -72,7 +75,11 @@ object BazelBspApp def main: Opts[IO[ExitCode]] = (verboseOpt, verifySetupOpt, setupOpt).mapN { (verbose, verify, setup) => - if setup then writeBspConfig(BuildMetaData.Version).as(ExitCode.Success) + if setup then + for + cwd <- FilesIO.cwd + _ <- writeBspConfig(cwd) + yield ExitCode.Success else if verify then for result <- Verifier.validateSetup @@ -92,27 +99,32 @@ object BazelBspApp } } - private def writeBspConfig(version: String): IO[Unit] = - val toPath = fs2.io.file.Path(".bsp/bazel-bsp.json") - - Stream - .emits(bspConfig(version).getBytes()) - .through( - fs2.io.file.Files[IO].writeAll(toPath) - ) - .compile - .drain - .flatMap(_ => - Console[IO].println( - s"Write setup config to ${toPath.toNioPath.toAbsolutePath()}" + def writeBspConfig(workspaceRoot: Path): IO[Unit] = + val toPath = workspaceRoot.resolve(".bsp") + + for + _ <- Files[IO].createDirectories(toPath) + _ <- Stream + .emits(bspConfig.getBytes()) + .through( + Files[IO].writeAll( + toPath.resolve("bazel-bsp.json"), + List( + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING + ) + ) ) - ) + .compile + .drain + _ <- Console[IO].println(s"Wrote setup config to ${toPath}") + yield () - private def bspConfig(version: String): String = """ + private lazy val bspConfig: String = s""" { "name": "BazelBsp", - "version": "${version}", - "bspVersion": "2.1.0-M1", + "version": "${BuildMetaData.Version}", + "bspVersion": "${BuildMetaData.BspVersion}", "languages": [ "scala" ], diff --git a/src/main/scala/afenton/bazel/bsp/BuildMetaData.scala b/src/main/scala/afenton/bazel/bsp/BuildMetaData.scala index 91ca37d..2f6d5dc 100644 --- a/src/main/scala/afenton/bazel/bsp/BuildMetaData.scala +++ b/src/main/scala/afenton/bazel/bsp/BuildMetaData.scala @@ -1,6 +1,6 @@ package afenton.bazel.bsp object BuildMetaData { - val Version = "0.0.2-alpha" + val Version = "0.0.13" val BspVersion = "2.0.0-M2" } \ No newline at end of file diff --git a/src/main/scala/afenton/bazel/bsp/FilesIO.scala b/src/main/scala/afenton/bazel/bsp/FilesIO.scala index 01265b0..fe21787 100644 --- a/src/main/scala/afenton/bazel/bsp/FilesIO.scala +++ b/src/main/scala/afenton/bazel/bsp/FilesIO.scala @@ -12,11 +12,14 @@ import java.nio.file.Path import java.nio.file.PathMatcher import scala.jdk.CollectionConverters.* import scala.util.Try +import java.nio.file.Paths object FilesIO: private val fileSystem: FileSystem = FileSystems.getDefault + def cwd: IO[Path] = IO.blocking(Paths.get("").toAbsolutePath.normalize) + def readLines(file: Path): IO[Either[Throwable, List[String]]] = IO.blocking { Try { diff --git a/src/main/scala/afenton/bazel/bsp/runner/BazelRunner.scala b/src/main/scala/afenton/bazel/bsp/runner/BazelRunner.scala index fbe5c10..1a2dcdd 100644 --- a/src/main/scala/afenton/bazel/bsp/runner/BazelRunner.scala +++ b/src/main/scala/afenton/bazel/bsp/runner/BazelRunner.scala @@ -103,7 +103,7 @@ object BazelRunner: ) .withArgs(command.asString :: expr.toList) .runUntilExit - .timeout(FiniteDuration(30, TimeUnit.SECONDS)) + .timeout(FiniteDuration(30, TimeUnit.MINUTES)) _ <- logger.info(s"Exited with ${er.exitCode}") yield er diff --git a/src/test/scala/afenton/bazel/bsp/End2EndTest.scala b/src/test/scala/afenton/bazel/bsp/End2EndTest.scala index 955d9a5..e6c993c 100644 --- a/src/test/scala/afenton/bazel/bsp/End2EndTest.scala +++ b/src/test/scala/afenton/bazel/bsp/End2EndTest.scala @@ -24,7 +24,7 @@ import scala.reflect.Typeable class End2EndTest extends munit.CatsEffectSuite with BspHelpers: - override val munitTimeout = 1.minute + override val munitTimeout = 2.minute val projectRoot = Paths.get("").toAbsolutePath @@ -45,7 +45,7 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers: .test("should successfully initialize") { (root, bazel) => val (responses, notifications) = Lsp.start - .runFor(root, 2.seconds) + .runFor(root, 30.seconds) .unsafeRunSync() assertEquals(notifications, Nil) @@ -54,8 +54,8 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers: responses.select[InitializeBuildResult], InitializeBuildResult( "Bazel", - "0.1", - "2.0.0-M2", + BuildMetaData.Version, + BuildMetaData.BspVersion, BuildServerCapabilities( compileProvider = Some(CompileProvider(List("scala"))), inverseSourcesProvider = Some(true), @@ -71,7 +71,7 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers: val (_, notifications) = Lsp.start .compile("//...") - .runFor(root, 10.seconds) + .runFor(root, 30.seconds) .unsafeRunSync() assertEquals(notifications.length, 2) @@ -96,7 +96,7 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers: val (_, notifications) = Lsp.start .compile("//...") - .runFor(root, 10.seconds) + .runFor(root, 30.seconds) .unsafeRunSync() assertEquals(notifications.length, 6) diff --git a/src/test/scala/afenton/bazel/bsp/runner/SubProcessTest.scala b/src/test/scala/afenton/bazel/bsp/runner/SubProcessTest.scala index b227356..022352e 100644 --- a/src/test/scala/afenton/bazel/bsp/runner/SubProcessTest.scala +++ b/src/test/scala/afenton/bazel/bsp/runner/SubProcessTest.scala @@ -23,7 +23,8 @@ class SubProcessTest extends munit.CatsEffectSuite: .runUntilExit .unsafeRunSync() - assertEquals(er2.exitCode, 2) + // Note: Specific exit code is different on Mac vs. Linux + assert(er2.exitCode > 0) assert( er2.stderrLines.unsafeRunSync().head.endsWith("No such file or directory") )