Skip to content

Commit

Permalink
improvement: add do not show bsp errors option
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 26, 2023
1 parent 27fed26 commit 1dcbaeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(())
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/src/test/scala/tests/BspErrorHandlerSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@ 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,
s"""|${BspErrorHandler.makeShortMessage(exampleError1)}
|${BspErrorHandler.makeShortMessage(exampleError2)}
|${BspErrorHandler.makeShortMessage(exampleError1)}
|${BspErrorHandler.makeLongMessage(longError)}
|${BspErrorHandler.makeShortMessage(exampleError2)}
|""".stripMargin,
)
assert(client.clientCommands.asScala.nonEmpty)
Expand Down

0 comments on commit 1dcbaeb

Please sign in to comment.