Skip to content

Commit

Permalink
refactor: split metalsLspService to main and fallback parts
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Oct 24, 2023
1 parent b859a4a commit bdb9373
Show file tree
Hide file tree
Showing 17 changed files with 1,457 additions and 1,220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import scala.meta.io.AbsolutePath

import org.eclipse.{lsp4j => l}

class BspErrorHandler(
class ShowBspErrorHandler(
languageClient: MetalsLanguageClient,
workspaceFolder: AbsolutePath,
currentSession: () => Option[BspSession],
tables: Tables,
)(implicit context: ExecutionContext) {
)(implicit context: ExecutionContext)
extends BspErrorHandler {

protected def logsPath: AbsolutePath =
workspaceFolder.resolve(Directories.log)
Expand Down Expand Up @@ -53,19 +54,19 @@ class BspErrorHandler(
protected def logError(message: String): Unit = scribe.error(message)

private def showError(message: String): Future[Unit] = {
val bspError = s"${BspErrorHandler.errorInBsp} $message"
val bspError = s"${ShowBspErrorHandler.errorInBsp} $message"
logError(bspError)
val params = BspErrorHandler.makeShowMessage(message)
val params = ShowBspErrorHandler.makeShowMessage(message)
languageClient.showMessageRequest(params).asScala.flatMap {
case BspErrorHandler.goToLogs =>
case ShowBspErrorHandler.goToLogs =>
val errorMsgStartLine =
bspError.linesIterator.headOption
.flatMap(findLine(_))
.getOrElse(0)
Future.successful(gotoLogs(errorMsgStartLine))
case BspErrorHandler.dismiss =>
case ShowBspErrorHandler.dismiss =>
Future.successful(dismissedErrors.add(message)).ignoreValue
case BspErrorHandler.doNotShowErrors =>
case ShowBspErrorHandler.doNotShowErrors =>
Future.successful {
tables.dismissedNotifications.BspErrors.dismissForever
}.ignoreValue
Expand Down Expand Up @@ -102,7 +103,7 @@ class BspErrorHandler(
}
}

object BspErrorHandler {
object ShowBspErrorHandler {
def makeShowMessage(
message: String
): l.ShowMessageRequestParams = {
Expand Down Expand Up @@ -145,3 +146,12 @@ object BspErrorHandler {
private val MESSAGE_MAX_LENGTH = 150

}

trait BspErrorHandler {
def onError(message: String): Future[Unit]
}

object LogBspErrorHandler extends BspErrorHandler {
def onError(message: String): Future[Unit] =
Future.successful(scribe.error(message))
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ final class BuildToolSelector(
): Future[Boolean] = {
languageClient
.showMessageRequest(
Messages.NewBuildToolDetected.params(newBuildTool, currentBuildTool)
Messages.NewBuildToolDetected
.params(newBuildTool.executableName, currentBuildTool.executableName)
)
.asScala
.map {
Expand Down
Loading

0 comments on commit bdb9373

Please sign in to comment.