Skip to content

Commit

Permalink
test: bsp status test
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Oct 26, 2023
1 parent cdb71ca commit c080bef
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class MetalsLspService(
connectionBspStatus,
)

private val buildClient: ForwardingMetalsBuildClient =
val buildClient: ForwardingMetalsBuildClient =
new ForwardingMetalsBuildClient(
languageClient,
diagnostics,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/src/main/scala/tests/TestingClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
74 changes: 73 additions & 1 deletion tests/unit/src/test/scala/tests/BspStatusSuite.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,6 +60,63 @@ class BspStatusSuite extends BaseSuite {
assertEquals(client.status, "some other other text")
}

test("bsp-status") {
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 {
Expand Down

0 comments on commit c080bef

Please sign in to comment.