-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: show correct bsp status for focused workspace folder (#5772
- Loading branch information
1 parent
728623b
commit b5a2d8d
Showing
13 changed files
with
217 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
metals/src/main/scala/scala/meta/internal/bsp/ConnectionBspStatus.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
metals/src/main/scala/scala/meta/internal/metals/BspStatus.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.