diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala index f9e2cfb8160..d04d33c324b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -392,7 +392,7 @@ class MetalsLspService( connectionBspStatus, ) - private val buildClient: ForwardingMetalsBuildClient = + val buildClient: ForwardingMetalsBuildClient = new ForwardingMetalsBuildClient( languageClient, diagnostics, diff --git a/tests/unit/src/main/scala/tests/TestingClient.scala b/tests/unit/src/main/scala/tests/TestingClient.scala index c342711b6ef..d1eb871b78b 100644 --- a/tests/unit/src/main/scala/tests/TestingClient.scala +++ b/tests/unit/src/main/scala/tests/TestingClient.scala @@ -187,6 +187,8 @@ class TestingClient(workspace: AbsolutePath, val buffers: Buffers) clientCommands.asScala.toList.map(_.getCommand) } + def pollStatusBar(): String = statusParams.poll().text + def statusBarHistory: String = { statusParams.asScala .map { params => diff --git a/tests/unit/src/test/scala/tests/BspStatusSuite.scala b/tests/unit/src/test/scala/tests/BspStatusSuite.scala index b0525ef79e5..e0e38824786 100644 --- a/tests/unit/src/test/scala/tests/BspStatusSuite.scala +++ b/tests/unit/src/test/scala/tests/BspStatusSuite.scala @@ -1,13 +1,28 @@ package tests +import java.nio.file.Files import java.nio.file.Paths import scala.meta.internal.metals.BspStatus +import scala.meta.internal.metals.Icons +import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.metals.MetalsServerConfig +import scala.meta.internal.metals.StatusBarConfig import scala.meta.internal.metals.clients.language.MetalsStatusParams import scala.meta.internal.metals.clients.language.NoopLanguageClient import scala.meta.io.AbsolutePath -class BspStatusSuite extends BaseSuite { +import bill.Bill +import org.eclipse.lsp4j.DidChangeWatchedFilesParams +import org.eclipse.lsp4j.FileChangeType +import org.eclipse.lsp4j.FileEvent +import org.eclipse.lsp4j.MessageParams +import org.eclipse.lsp4j.MessageType + +class BspStatusSuite extends BaseLspSuite("bsp-status-suite") { + + override def serverConfig: MetalsServerConfig = + MetalsServerConfig.default.copy(bspStatusBar = StatusBarConfig.on) test("basic") { val client = new StatusClient @@ -45,6 +60,63 @@ class BspStatusSuite extends BaseSuite { assertEquals(client.status, "some other other text") } + test("bsp-error") { + cleanWorkspace() + Bill.installWorkspace(workspace.resolve("billWorkspace").toNIO, "Bill") + def bloopReports = server.server.reports.bloop.getReports() + for { + _ <- initialize( + Map( + "bloopWorkspace" -> + """|/metals.json + |{ "a": { } } + | + |/a/src/main/scala/Main.scala + |object Main { + | val x: Int = 1 + |} + |""".stripMargin, + "billWorkspace" -> + """|/src/com/App.scala + |object App { + | val x: Int = 1 + |} + |""".stripMargin, + ), + expectError = false, + ) + _ <- server.didOpen("bloopWorkspace/a/src/main/scala/Main.scala") + _ = assertNoDiff(client.pollStatusBar(), s"Bloop ${Icons.default.link}") + _ = client.statusParams.clear() + _ <- server.didOpen("billWorkspace/src/com/App.scala") + _ = assertNoDiff(client.pollStatusBar(), s"Bill ${Icons.default.link}") + _ = client.statusParams.clear() + _ = server.server.buildClient.onBuildLogMessage( + new MessageParams(MessageType.Error, "This is an error.") + ) + _ = assert(client.statusParams.isEmpty()) + _ <- server.didFocus("bloopWorkspace/a/src/main/scala/Main.scala") + _ = assertNoDiff( + client.pollStatusBar(), + s"Bloop 1 ${Icons.default.alert}", + ) + reports = bloopReports + _ = assert(reports.nonEmpty) + reportUri = reports.head.file.toURI().toString + newPath = (reportUri ++ ".seen").toAbsolutePath.toNIO + _ = Files.move(reports.head.toPath, newPath) + _ <- server.fullServer + .didChangeWatchedFiles( + new DidChangeWatchedFilesParams( + List(new FileEvent(reportUri, FileChangeType.Deleted)).asJava + ) + ) + .asScala + _ = assertNoDiff(client.pollStatusBar(), s"Bloop ${Icons.default.link}") + _ = assert(bloopReports.nonEmpty) + } yield () + } + } class StatusClient extends NoopLanguageClient {