From 4e8be0e0bb4e09d2f15c2f0b1da5dff5612b88e9 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Thu, 28 Sep 2023 10:55:27 +0200 Subject: [PATCH] filter icons from show message --- .../clients/language/ConfiguredLanguageClient.scala | 12 ++++++------ .../clients/language/MetalsLanguageClient.scala | 12 +++++++++--- .../scala/tests/ServerLivenessMonitorLspSuite.scala | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala b/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala index 9c4182b4331..8adffc6b95e 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/clients/language/ConfiguredLanguageClient.scala @@ -52,10 +52,10 @@ 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) @@ -63,7 +63,7 @@ final class ConfiguredLanguageClient( .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 { @@ -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 _ => } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsLanguageClient.scala b/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsLanguageClient.scala index 324acd0dc90..524d2423fa5 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsLanguageClient.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/clients/language/MetalsLanguageClient.scala @@ -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 @@ -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) diff --git a/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala b/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala index dd14037906a..64489908b19 100644 --- a/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala +++ b/tests/unit/src/test/scala/tests/ServerLivenessMonitorLspSuite.scala @@ -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)