From 2dc3125df8f8c281a29c2a478e627dc44a078241 Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Wed, 18 Oct 2023 17:01:33 +0200 Subject: [PATCH] bugfix: Future filter error during connecting to build server If we get to the state that selected build tool is no longer available, Metals would crash. This happend in `MetalsLspService.buildTool` if `BuildToolSelector.checkForChosenBuildTool` returned Future(None) --- .../scala/scala/meta/internal/builds/BuildToolSelector.scala | 4 ++-- .../scala/scala/meta/internal/metals/MetalsLspService.scala | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala b/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala index e30da44a4de..b7d526b75d9 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/BuildToolSelector.scala @@ -23,9 +23,9 @@ final class BuildToolSelector( buildTools: List[BuildTool] ): Future[Option[BuildTool]] = tables.buildTool.selectedBuildTool match { - case Some(chosen) => + case Some(chosen) if buildTools.exists(_.executableName == chosen) => Future(buildTools.find(_.executableName == chosen)) - case None => + case _ => buildTools match { case buildTool :: Nil => tables.buildTool.chooseBuildTool(buildTool.executableName) diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala index bee629d9737..8ba4ebc850d 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -1970,11 +1970,10 @@ class MetalsLspService( case Nil => Future(None) case buildTools => for { - Some(buildTool) <- buildToolSelector.checkForChosenBuildTool( + buildTool <- buildToolSelector.checkForChosenBuildTool( buildTools ) - if isCompatibleVersion(buildTool) - } yield Some(buildTool) + } yield buildTool.filter(isCompatibleVersion) } }