Skip to content

Commit

Permalink
filter icons from show message
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 28, 2023
1 parent 3b8fb32 commit 4e8be0e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ final class ConfiguredLanguageClient(
case _ => clientConfig.statusBarState()
}

val logMessage = params.logMessage(clientConfig.icons())
statusBarState match {
case On => underlying.metalsStatus(params)
case ShowMessage
if params.logMessage.nonEmpty && !pendingShowMessage.get() =>
case ShowMessage if logMessage.nonEmpty && !pendingShowMessage.get() =>
if (params.command != null && params.command.nonEmpty) {
val action = new MessageActionItem(
Option(params.commandTooltip)
.filter(_.nonEmpty)
.getOrElse(params.command)
)
val requestParams = new ShowMessageRequestParams()
requestParams.setMessage(params.logMessage)
requestParams.setMessage(logMessage)
requestParams.setType(level)
requestParams.setActions(List(action).asJava)
underlying.showMessageRequest(requestParams).asScala.map {
Expand All @@ -74,10 +74,10 @@ final class ConfiguredLanguageClient(
case _ =>
}
} else {
underlying.showMessage(new MessageParams(level, params.logMessage))
underlying.showMessage(new MessageParams(level, logMessage))
}
case LogMessage if params.logMessage.nonEmpty =>
underlying.logMessage(new MessageParams(level, params.logMessage))
case LogMessage if logMessage.nonEmpty =>
underlying.logMessage(new MessageParams(level, logMessage))
case _ =>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import javax.annotation.Nullable
import scala.util.Try

import scala.meta.internal.decorations.DecorationClient
import scala.meta.internal.metals.Icons
import scala.meta.internal.tvp._

import org.eclipse.lsp4j.ExecuteCommandParams
Expand Down Expand Up @@ -143,11 +144,16 @@ case class MetalsStatusParams(
@Nullable statusType: String = StatusType.metals.toString(),
) {

def logMessage: String =
def logMessage(icons: Icons): String = {
val decodedText =
if (icons != Icons.unicode && icons != Icons.none)
icons.all.foldLeft(text)((acc, icon) => acc.replace(icon, ""))
else text
if (statusType == StatusType.bsp.toString())
if (level == "info") ""
else s"$text: $tooltip"
else text
else s"$decodedText: $tooltip"
else decodedText
}

def getStatusType: StatusType.Value =
Try(StatusType.withName(statusType)).toOption.getOrElse(StatusType.metals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ServerLivenessMonitorLspSuite extends BaseLspSuite("liveness-monitor") {
)
_ = assertNoDiff(
server.client.workspaceShowMessages,
noResponseParams.logMessage,
noResponseParams.logMessage(Icons.none),
)
_ = assertEquals(isServerResponsive, Some(false))
_ = Thread.sleep(sleepTime)
Expand Down

0 comments on commit 4e8be0e

Please sign in to comment.