diff --git a/metals/src/main/scala/scala/meta/internal/builds/BSPErrorHandler.scala b/metals/src/main/scala/scala/meta/internal/builds/BSPErrorHandler.scala index 152c12926dc..d5e6bfd30cc 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/BSPErrorHandler.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/BSPErrorHandler.scala @@ -28,9 +28,14 @@ class BspErrorHandler( workspaceFolder.resolve(Directories.log) private val lastError = new AtomicReference[String]("") private val dismissedErrors = ConcurrentHashSet.empty[String] + @volatile private var doNotShowErrors = false def onError(message: String): Future[Unit] = { - if (shouldShowBspError && !dismissedErrors.contains(message)) { + if ( + !doNotShowErrors && + shouldShowBspError && + !dismissedErrors.contains(message) + ) { val previousError = lastError.getAndSet(message) if (message != previousError) { showError(message) @@ -62,6 +67,8 @@ class BspErrorHandler( restartBspServer().ignoreValue case BspErrorHandler.dismiss => Future.successful(dismissedErrors.add(message)).ignoreValue + case BspErrorHandler.doNotShowErrors => + Future.successful { doNotShowErrors = true } case _ => Future.successful(()) } } @@ -103,12 +110,12 @@ object BspErrorHandler { if (message.length() <= MESSAGE_MAX_LENGTH) { ( makeShortMessage(message), - List(restartBuildServer, dismiss), + List(restartBuildServer, dismiss, doNotShowErrors), ) } else { ( makeLongMessage(message), - List(goToLogs, restartBuildServer, dismiss), + List(goToLogs, restartBuildServer, dismiss, doNotShowErrors), ) } val params = new l.ShowMessageRequestParams() @@ -130,6 +137,7 @@ object BspErrorHandler { val dismiss = new l.MessageActionItem("Dismiss.") val restartBuildServer = new l.MessageActionItem("Restart build server.") + val doNotShowErrors = new l.MessageActionItem("Stop showing bsp errors.") val errorHeader = "Encountered an error in the build server:" private val gotoLogsToSeeFull = "Go to logs to see the full error" diff --git a/tests/unit/src/test/scala/tests/BspErrorHandlerSuite.scala b/tests/unit/src/test/scala/tests/BspErrorHandlerSuite.scala index 7ae270373ca..0ff14647f16 100644 --- a/tests/unit/src/test/scala/tests/BspErrorHandlerSuite.scala +++ b/tests/unit/src/test/scala/tests/BspErrorHandlerSuite.scala @@ -52,6 +52,10 @@ class BspErrorHandlerSuite extends BaseSuite { _ = client.bspError = BspErrorHandler.goToLogs _ <- errorHandler.onError(longError) _ <- errorHandler.onError(exampleError1) + _ = client.bspError = BspErrorHandler.doNotShowErrors + _ <- errorHandler.onError(exampleError2) + _ <- errorHandler.onError(longError) + _ <- errorHandler.onError(exampleError2) } yield { assertNoDiff( client.workspaceMessageRequests, @@ -59,6 +63,7 @@ class BspErrorHandlerSuite extends BaseSuite { |${BspErrorHandler.makeShortMessage(exampleError2)} |${BspErrorHandler.makeShortMessage(exampleError1)} |${BspErrorHandler.makeLongMessage(longError)} + |${BspErrorHandler.makeShortMessage(exampleError2)} |""".stripMargin, ) assert(client.clientCommands.asScala.nonEmpty)