From b5a2d8d731ea3b99ba533342b96bb5c38a0ab1b8 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Tue, 24 Oct 2023 16:22:52 +0200 Subject: [PATCH] improvement: show correct bsp status for focused workspace folder (#5772) --- .../meta/internal/bsp/BspConnector.scala | 10 ++-- .../scala/meta/internal/bsp/BspServers.scala | 4 +- .../internal/bsp/ConnectionBspStatus.scala | 58 +++++++++++++++++++ .../meta/internal/metals/BloopServers.scala | 5 +- .../meta/internal/metals/BspStatus.scala | 37 ++++++++++++ .../metals/BuildServerConnection.scala | 12 ++-- .../internal/metals/MetalsLspService.scala | 6 ++ .../metals/ServerLivenessMonitor.scala | 58 +++---------------- .../internal/metals/WorkspaceLspService.scala | 20 ++++++- .../src/main/scala/tests/TestingClient.scala | 4 +- .../src/test/scala/tests/BspStatusSuite.scala | 56 ++++++++++++++++++ .../tests/ServerLivenessMonitorLspSuite.scala | 4 +- .../tests/ServerLivenessMonitorSuite.scala | 20 +++++-- 13 files changed, 217 insertions(+), 77 deletions(-) create mode 100644 metals/src/main/scala/scala/meta/internal/bsp/ConnectionBspStatus.scala create mode 100644 metals/src/main/scala/scala/meta/internal/metals/BspStatus.scala create mode 100644 tests/unit/src/test/scala/tests/BspStatusSuite.scala diff --git a/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala b/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala index c662f3f7e0c..163119842e2 100644 --- a/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala +++ b/metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala @@ -36,6 +36,7 @@ class BspConnector( bspConfigGenerator: BspConfigGenerator, currentConnection: () => Option[BuildServerConnection], restartBspServer: () => Future[Boolean], + bspStatus: ConnectionBspStatus, )(implicit ec: ExecutionContext) { /** @@ -83,6 +84,7 @@ class BspConnector( bspTraceRoot: AbsolutePath, addLivenessMonitor: Boolean, ): Future[Option[BuildServerConnection]] = { + def bspStatusOpt = Option.when(addLivenessMonitor)(bspStatus) scribe.info("Attempting to connect to the build server...") resolve() match { case ResolvedNone => @@ -94,7 +96,7 @@ class BspConnector( projectRoot, bspTraceRoot, userConfiguration, - addLivenessMonitor, + bspStatusOpt, ) .map(Some(_)) case ResolvedBspOne(details) @@ -118,7 +120,7 @@ class BspConnector( projectRoot, bspTraceRoot, details, - addLivenessMonitor, + bspStatusOpt, ) _ <- if (shouldReload) connection.workspaceReload() @@ -130,7 +132,7 @@ class BspConnector( case ResolvedBspOne(details) => tables.buildServers.chooseServer(details.getName()) bspServers - .newServer(projectRoot, bspTraceRoot, details, addLivenessMonitor) + .newServer(projectRoot, bspTraceRoot, details, bspStatusOpt) .map(Some(_)) case ResolvedMultiple(_, availableServers) => val distinctServers = availableServers @@ -167,7 +169,7 @@ class BspConnector( projectRoot, bspTraceRoot, item, - addLivenessMonitor, + bspStatusOpt, ) } yield Some(conn) } diff --git a/metals/src/main/scala/scala/meta/internal/bsp/BspServers.scala b/metals/src/main/scala/scala/meta/internal/bsp/BspServers.scala index 1f00eaf0bae..f252c6abafb 100644 --- a/metals/src/main/scala/scala/meta/internal/bsp/BspServers.scala +++ b/metals/src/main/scala/scala/meta/internal/bsp/BspServers.scala @@ -69,7 +69,7 @@ final class BspServers( projectDirectory: AbsolutePath, bspTraceRoot: AbsolutePath, details: BspConnectionDetails, - addLivenessMonitor: Boolean, + bspStatusOpt: Option[ConnectionBspStatus], ): Future[BuildServerConnection] = { def newConnection(): Future[SocketConnection] = { @@ -143,7 +143,7 @@ final class BspServers( tables.dismissedNotifications.ReconnectBsp, config, details.getName(), - addLivenessMonitor, + bspStatusOpt, ) } diff --git a/metals/src/main/scala/scala/meta/internal/bsp/ConnectionBspStatus.scala b/metals/src/main/scala/scala/meta/internal/bsp/ConnectionBspStatus.scala new file mode 100644 index 00000000000..0aab3d7f22f --- /dev/null +++ b/metals/src/main/scala/scala/meta/internal/bsp/ConnectionBspStatus.scala @@ -0,0 +1,58 @@ +package scala.meta.internal.bsp + +import java.util.concurrent.atomic.AtomicBoolean + +import scala.meta.internal.metals.BspStatus +import scala.meta.internal.metals.Icons +import scala.meta.internal.metals.ServerCommands +import scala.meta.internal.metals.clients.language.MetalsStatusParams +import scala.meta.internal.metals.clients.language.StatusType +import scala.meta.io.AbsolutePath + +class ConnectionBspStatus( + bspStatus: BspStatus, + folderPath: AbsolutePath, + icons: Icons, +) { + private val isServerResponsive = new AtomicBoolean(false) + val status: MetalsStatusParams => Unit = bspStatus.status(folderPath, _) + + def connected(serverName: String): Unit = + if (isServerResponsive.compareAndSet(false, true)) + status(ConnectionBspStatus.connectedParams(serverName, icons)) + def noResponse(serverName: String): Unit = + if (isServerResponsive.compareAndSet(true, false)) { + scribe.debug("server liveness monitor detected no response") + status(ConnectionBspStatus.noResponseParams(serverName, icons)) + } + + def disconnected(): Unit = { + isServerResponsive.set(false) + status(ConnectionBspStatus.disconnectedParams) + } + + def isBuildServerResponsive: Boolean = isServerResponsive.get() +} + +object ConnectionBspStatus { + def connectedParams(serverName: String, icons: Icons): MetalsStatusParams = + MetalsStatusParams( + s"$serverName ${icons.link}", + "info", + show = true, + tooltip = s"Metals is connected to the build server ($serverName).", + ).withStatusType(StatusType.bsp) + + val disconnectedParams: MetalsStatusParams = + MetalsStatusParams("", hide = true).withStatusType(StatusType.bsp) + + def noResponseParams(serverName: String, icons: Icons): MetalsStatusParams = + MetalsStatusParams( + s"$serverName ${icons.error}", + "error", + show = true, + tooltip = s"Build sever ($serverName) is not responding.", + command = ServerCommands.ConnectBuildServer.id, + commandTooltip = "Reconnect.", + ).withStatusType(StatusType.bsp) +} diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index 9be67e903c5..287446ce1f6 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -16,6 +16,7 @@ import scala.util.Success import scala.util.Try import scala.meta.internal.bsp.BuildChange +import scala.meta.internal.bsp.ConnectionBspStatus import scala.meta.internal.metals.BloopJsonUpdateCause.BloopJsonUpdateCause import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.clients.language.MetalsLanguageClient @@ -81,7 +82,7 @@ final class BloopServers( projectRoot: AbsolutePath, bspTraceRoot: AbsolutePath, userConfiguration: UserConfiguration, - addLivenessMonitor: Boolean, + bspStatusOpt: Option[ConnectionBspStatus], ): Future[BuildServerConnection] = { val bloopVersion = userConfiguration.currentBloopVersion BuildServerConnection @@ -95,7 +96,7 @@ final class BloopServers( tables.dismissedNotifications.ReconnectBsp, config, name, - addLivenessMonitor, + bspStatusOpt, ) } diff --git a/metals/src/main/scala/scala/meta/internal/metals/BspStatus.scala b/metals/src/main/scala/scala/meta/internal/metals/BspStatus.scala new file mode 100644 index 00000000000..21fcf64ce7f --- /dev/null +++ b/metals/src/main/scala/scala/meta/internal/metals/BspStatus.scala @@ -0,0 +1,37 @@ +package scala.meta.internal.metals + +import java.util.Collections +import java.util.concurrent.atomic.AtomicReference + +import scala.meta.internal.bsp.ConnectionBspStatus +import scala.meta.internal.metals.clients.language.MetalsLanguageClient +import scala.meta.internal.metals.clients.language.MetalsStatusParams +import scala.meta.io.AbsolutePath + +class BspStatus(client: MetalsLanguageClient, isBspStatusProvider: Boolean) { + val focusedFolder: AtomicReference[Option[AbsolutePath]] = + new AtomicReference(None) + val messages: java.util.Map[AbsolutePath, MetalsStatusParams] = + Collections.synchronizedMap( + new java.util.HashMap[AbsolutePath, MetalsStatusParams] + ) + + def status(folder: AbsolutePath, params: MetalsStatusParams): Unit = { + messages.put(folder, params) + if (focusedFolder.get().isEmpty || focusedFolder.get().contains(folder)) { + client.metalsStatus(params) + } + } + + def focus(folder: AbsolutePath): Unit = { + if (isBspStatusProvider) { + val prev = focusedFolder.getAndSet(Some(folder)) + if (!prev.contains(folder)) { + client.metalsStatus( + messages.getOrDefault(folder, ConnectionBspStatus.disconnectedParams) + ) + } + } + } + +} diff --git a/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala b/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala index b07c8d1cc63..648fcc1497a 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BuildServerConnection.scala @@ -22,6 +22,7 @@ import scala.reflect.ClassTag import scala.util.Success import scala.util.Try +import scala.meta.internal.bsp.ConnectionBspStatus import scala.meta.internal.builds.MillBuildTool import scala.meta.internal.builds.SbtBuildTool import scala.meta.internal.metals.MetalsEnrichments._ @@ -444,7 +445,7 @@ object BuildServerConnection { reconnectNotification: DismissedNotifications#Notification, config: MetalsServerConfig, serverName: String, - addLivenessMonitor: Boolean = false, + bspStatusOpt: Option[ConnectionBspStatus] = None, retry: Int = 5, supportsWrappedSources: Option[Boolean] = None, )(implicit @@ -454,12 +455,8 @@ object BuildServerConnection { def setupServer(): Future[LauncherConnection] = { connect().map { case conn @ SocketConnection(_, output, input, _, _) => val tracePrinter = Trace.setupTracePrinter("BSP", bspTraceRoot) - val bspStatusOpt = - if (addLivenessMonitor) - Some(new BspStatus(languageClient, serverName, config.icons)) - else None val requestMonitorOpt = - bspStatusOpt.map(new RequestMonitorImpl(_)) + bspStatusOpt.map(new RequestMonitorImpl(_, serverName)) val wrapper: MessageConsumer => MessageConsumer = requestMonitorOpt.map(_.wrapper).getOrElse(identity) val launcher = @@ -497,6 +494,7 @@ object BuildServerConnection { config.metalsToIdleTime, config.pingInterval, bspStatus, + serverName, ) LauncherConnection( @@ -535,7 +533,7 @@ object BuildServerConnection { reconnectNotification, config, serverName, - addLivenessMonitor, + bspStatusOpt, retry - 1, ) } else { 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 8ba4ebc850d..a8554a23cec 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -26,6 +26,7 @@ import scala.meta.internal.bsp.BspConnector import scala.meta.internal.bsp.BspServers import scala.meta.internal.bsp.BspSession import scala.meta.internal.bsp.BuildChange +import scala.meta.internal.bsp.ConnectionBspStatus import scala.meta.internal.bsp.ScalaCliBspScope import scala.meta.internal.builds.BloopInstall import scala.meta.internal.builds.BspErrorHandler @@ -130,6 +131,7 @@ class MetalsLspService( folder: AbsolutePath, folderVisibleName: Option[String], headDoctor: HeadDoctor, + bspStatus: BspStatus, ) extends Folder(folder, folderVisibleName, isKnownMetalsProject = true) with Cancelable with TextDocumentService { @@ -423,6 +425,9 @@ class MetalsLspService( clientConfig.initialConfig, ) + private val connectionBspStatus = + new ConnectionBspStatus(bspStatus, folder, clientConfig.icons()) + private val bspServers: BspServers = new BspServers( folder, charset, @@ -445,6 +450,7 @@ class MetalsLspService( bspConfigGenerator, () => bspSession.map(_.mainConnection), restartBspServer, + connectionBspStatus, ) private val workspaceSymbols: WorkspaceSymbolProvider = diff --git a/metals/src/main/scala/scala/meta/internal/metals/ServerLivenessMonitor.scala b/metals/src/main/scala/scala/meta/internal/metals/ServerLivenessMonitor.scala index a5ae48829fd..9acaa9ae1ba 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ServerLivenessMonitor.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ServerLivenessMonitor.scala @@ -4,13 +4,10 @@ import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.ScheduledFuture import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicBoolean import scala.concurrent.duration.Duration -import scala.meta.internal.metals.clients.language.MetalsLanguageClient -import scala.meta.internal.metals.clients.language.MetalsStatusParams -import scala.meta.internal.metals.clients.language.StatusType +import scala.meta.internal.bsp.ConnectionBspStatus import org.eclipse.lsp4j.jsonrpc.MessageConsumer import org.eclipse.lsp4j.jsonrpc.messages.Message @@ -23,7 +20,8 @@ trait RequestMonitor { def lastIncoming: Option[Long] } -class RequestMonitorImpl(bspStatus: BspStatus) extends RequestMonitor { +class RequestMonitorImpl(bspStatus: ConnectionBspStatus, serverName: String) + extends RequestMonitor { @volatile private var lastOutgoing_ : Option[Long] = None @volatile private var lastIncoming_ : Option[Long] = None @@ -45,7 +43,7 @@ class RequestMonitorImpl(bspStatus: BspStatus) extends RequestMonitor { private def outgoingMessage() = lastOutgoing_ = now private def incomingMessage(): Unit = { - bspStatus.connected() + bspStatus.connected(serverName) lastIncoming_ = now } private def now = Some(System.currentTimeMillis()) @@ -59,7 +57,8 @@ class ServerLivenessMonitor( ping: () => Unit, metalsIdleInterval: Duration, pingInterval: Duration, - bspStatus: BspStatus, + bspStatus: ConnectionBspStatus, + serverName: String, ) { @volatile private var lastPing: Long = 0 val scheduler: ScheduledExecutorService = Executors.newScheduledThreadPool(1) @@ -75,7 +74,7 @@ class ServerLivenessMonitor( def notResponding = lastIncoming > (pingInterval.toMillis * 2) if (!metalsIsIdle) { if (lastPingOk && notResponding) { - bspStatus.noResponse() + bspStatus.noResponse(serverName) } scribe.debug("server liveness monitor: pinging build server...") lastPing = now @@ -125,46 +124,3 @@ object ServerLivenessMonitor { object Running extends State } - -class BspStatus( - client: MetalsLanguageClient, - serverName: String, - icons: Icons, -) { - private val isServerResponsive = new AtomicBoolean(false) - - def connected(): Unit = - if (isServerResponsive.compareAndSet(false, true)) - client.metalsStatus(BspStatus.connectedParams(serverName, icons)) - def noResponse(): Unit = - if (isServerResponsive.compareAndSet(true, false)) { - scribe.debug("server liveness monitor detected no response") - client.metalsStatus(BspStatus.noResponseParams(serverName, icons)) - } - def disconnected(): Unit = client.metalsStatus(BspStatus.disconnectedParams) - - def isBuildServerResponsive: Boolean = isServerResponsive.get() -} - -object BspStatus { - def connectedParams(serverName: String, icons: Icons): MetalsStatusParams = - MetalsStatusParams( - s"$serverName ${icons.link}", - "info", - show = true, - tooltip = s"Metals is connected to the build server ($serverName).", - ).withStatusType(StatusType.bsp) - - val disconnectedParams: MetalsStatusParams = - MetalsStatusParams("", hide = true).withStatusType(StatusType.bsp) - - def noResponseParams(serverName: String, icons: Icons): MetalsStatusParams = - MetalsStatusParams( - s"$serverName ${icons.error}", - "error", - show = true, - tooltip = s"Build sever ($serverName) is not responding.", - command = ServerCommands.ConnectBuildServer.id, - commandTooltip = "Reconnect.", - ).withStatusType(StatusType.bsp) -} diff --git a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala index 07e1bb93b8f..d708fb744d6 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scala @@ -22,6 +22,7 @@ import scala.meta.internal.metals.MetalsLspService import scala.meta.internal.metals.WindowStateDidChangeParams import scala.meta.internal.metals.clients.language.ConfiguredLanguageClient import scala.meta.internal.metals.clients.language.MetalsLanguageClient +import scala.meta.internal.metals.config.StatusBarState import scala.meta.internal.metals.debug.BuildTargetNotFoundException import scala.meta.internal.metals.debug.BuildTargetUndefinedException import scala.meta.internal.metals.debug.DebugProvider @@ -150,6 +151,18 @@ class WorkspaceLspService( languageClient, ) + private val bspStatus = new BspStatus( + languageClient, + isBspStatusProvider = clientConfig.bspStatusBarState() == StatusBarState.On, + ) + + def setFocusedDocument(newFocusedDocument: Option[AbsolutePath]): Unit = { + newFocusedDocument + .flatMap(getServiceForOpt) + .foreach(service => bspStatus.focus(service.path)) + focusedDocument = newFocusedDocument + } + def createService(folder: Folder): MetalsLspService = folder match { case Folder(uri, name) => @@ -168,6 +181,7 @@ class WorkspaceLspService( uri, name, doctor, + bspStatus, ) } @@ -324,7 +338,7 @@ class WorkspaceLspService( focusedDocument.foreach(recentlyFocusedFiles.add) val uri = params.getTextDocument.getUri val path = uri.toAbsolutePath - focusedDocument = Some(path) + setFocusedDocument(Some(path)) val service = getServiceForOpt(path) .orElse { if (path.filename.isScalaOrJavaFilename) { @@ -344,7 +358,7 @@ class WorkspaceLspService( override def didClose(params: DidCloseTextDocumentParams): Unit = { val path = params.getTextDocument.getUri.toAbsolutePath if (focusedDocument.contains(path)) { - focusedDocument = recentlyFocusedFiles.pollRecent() + setFocusedDocument(recentlyFocusedFiles.pollRecent()) } getServiceFor(params.getTextDocument().getUri()).didClose(params) } @@ -611,7 +625,7 @@ class WorkspaceLspService( } uriOpt match { case Some(uri) => - focusedDocument = Some(uri.toAbsolutePath) + setFocusedDocument(Some(uri.toAbsolutePath)) getServiceFor(uri).didFocus(uri) case None => CompletableFuture.completedFuture(DidFocusResult.NoBuildTarget) diff --git a/tests/unit/src/main/scala/tests/TestingClient.scala b/tests/unit/src/main/scala/tests/TestingClient.scala index 16d3da53cd0..2252c135a6f 100644 --- a/tests/unit/src/main/scala/tests/TestingClient.scala +++ b/tests/unit/src/main/scala/tests/TestingClient.scala @@ -12,11 +12,11 @@ import scala.concurrent.Future import scala.concurrent.Promise import scala.meta.inputs.Input +import scala.meta.internal.bsp.ConnectionBspStatus import scala.meta.internal.builds.BspErrorHandler import scala.meta.internal.builds.BuildTool import scala.meta.internal.builds.BuildTools import scala.meta.internal.decorations.PublishDecorationsParams -import scala.meta.internal.metals.BspStatus import scala.meta.internal.metals.Buffers import scala.meta.internal.metals.ClientCommands import scala.meta.internal.metals.FileOutOfScalaCliBspScope @@ -375,7 +375,7 @@ class TestingClient(workspace: AbsolutePath, val buffers: Buffers) ) { bspError } else if ( - params.getMessage() == BspStatus + params.getMessage() == ConnectionBspStatus .noResponseParams("Bill", Icons.default) .logMessage(Icons.default) ) { diff --git a/tests/unit/src/test/scala/tests/BspStatusSuite.scala b/tests/unit/src/test/scala/tests/BspStatusSuite.scala new file mode 100644 index 00000000000..b0525ef79e5 --- /dev/null +++ b/tests/unit/src/test/scala/tests/BspStatusSuite.scala @@ -0,0 +1,56 @@ +package tests + +import java.nio.file.Paths + +import scala.meta.internal.metals.BspStatus +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 { + + test("basic") { + val client = new StatusClient + val bspStatus = new BspStatus(client, isBspStatusProvider = true) + val folder1 = AbsolutePath(Paths.get(".")).resolve("folder1") + val folder2 = AbsolutePath(Paths.get(".")).resolve("folder2") + bspStatus.status(folder1, new MetalsStatusParams("some text")) + assertEquals(client.status, "some text") + bspStatus.status(folder2, new MetalsStatusParams("other text")) + assertEquals(client.status, "other text") + bspStatus.focus(folder1) + assertEquals(client.status, "some text") + bspStatus.status(folder2, new MetalsStatusParams("some other other text")) + assertEquals(client.status, "some text") + bspStatus.focus(folder1) + assertEquals(client.status, "some text") + bspStatus.focus(folder2) + assertEquals(client.status, "some other other text") + } + + test("no-bsp-status") { + val client = new StatusClient + val bspStatus = new BspStatus(client, isBspStatusProvider = false) + val folder1 = AbsolutePath(Paths.get(".")).resolve("folder1") + val folder2 = AbsolutePath(Paths.get(".")).resolve("folder2") + bspStatus.status(folder1, new MetalsStatusParams("some text")) + assertEquals(client.status, "some text") + bspStatus.status(folder2, new MetalsStatusParams("other text")) + assertEquals(client.status, "other text") + bspStatus.focus(folder1) + assertEquals(client.status, "other text") + bspStatus.status(folder2, new MetalsStatusParams("some other other text")) + assertEquals(client.status, "some other other text") + bspStatus.focus(folder1) + assertEquals(client.status, "some other other text") + } + +} + +class StatusClient extends NoopLanguageClient { + + var status: String = "" + + override def metalsStatus(params: MetalsStatusParams): Unit = + status = params.text +} diff --git a/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala b/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala index 3fcc0b08d7a..02fdc0d20e1 100644 --- a/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala +++ b/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala @@ -2,7 +2,7 @@ package tests import scala.concurrent.duration.Duration -import scala.meta.internal.metals.BspStatus +import scala.meta.internal.bsp.ConnectionBspStatus import scala.meta.internal.metals.Icons import scala.meta.internal.metals.Messages import scala.meta.internal.metals.MetalsEnrichments._ @@ -60,7 +60,7 @@ class ServerLivenessMonitorLspSuite extends BaseLspSuite("liveness-monitor") { ) ) _ = Thread.sleep(sleepTime) - noResponseParams = BspStatus.noResponseParams( + noResponseParams = ConnectionBspStatus.noResponseParams( "Bill", Icons.default, ) diff --git a/tests/unit/src/test/scala/tests/ServerLivenessMonitorSuite.scala b/tests/unit/src/test/scala/tests/ServerLivenessMonitorSuite.scala index 7b60b765f4b..14757dcd04f 100644 --- a/tests/unit/src/test/scala/tests/ServerLivenessMonitorSuite.scala +++ b/tests/unit/src/test/scala/tests/ServerLivenessMonitorSuite.scala @@ -1,5 +1,6 @@ package tests +import java.nio.file.Paths import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicReference @@ -8,12 +9,14 @@ import scala.concurrent.ExecutionContext import scala.concurrent.ExecutionContextExecutorService import scala.concurrent.duration.Duration +import scala.meta.internal.bsp.ConnectionBspStatus import scala.meta.internal.metals.BspStatus import scala.meta.internal.metals.Icons import scala.meta.internal.metals.RequestMonitor import scala.meta.internal.metals.ServerLivenessMonitor import scala.meta.internal.metals.clients.language.MetalsStatusParams import scala.meta.internal.metals.clients.language.NoopLanguageClient +import scala.meta.io.AbsolutePath class ServerLivenessMonitorSuite extends BaseSuite { implicit val ex: ExecutionContextExecutorService = @@ -23,15 +26,21 @@ class ServerLivenessMonitorSuite extends BaseSuite { val pingInterval = Duration("3s") val server = new ResponsiveServer(pingInterval) val client = new CountMessageRequestsClient - val bspStatus = new BspStatus(client, "responsive-server", Icons.default) + val bspStatus = new BspStatus(client, isBspStatusProvider = true) + val connectionBspStatus = new ConnectionBspStatus( + bspStatus, + AbsolutePath(Paths.get(".")), + Icons.default, + ) val livenessMonitor = new ServerLivenessMonitor( server, () => server.sendRequest(true), metalsIdleInterval = pingInterval * 4, pingInterval, - bspStatus, + connectionBspStatus, + "responsive-server", ) - bspStatus.connected() + connectionBspStatus.connected("responsive-server") Thread.sleep(pingInterval.toMillis * 3 / 2) assert(livenessMonitor.metalsIsIdle) server.sendRequest(false) @@ -89,7 +98,10 @@ class CountMessageRequestsClient extends NoopLanguageClient { override def metalsStatus(params: MetalsStatusParams): Unit = if ( - params == BspStatus.noResponseParams("responsive-server", Icons.default) + params == ConnectionBspStatus.noResponseParams( + "responsive-server", + Icons.default, + ) ) { showMessageRequests += 1 }