From b511ce90152c13ac20ee2dfef8bc8fef8fa97f9d Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Thu, 14 Sep 2023 12:32:43 +0200 Subject: [PATCH] bugfix: deduplicate auto connect requests for scala-cli --- .../internal/builds/ScalaCliBuildTool.scala | 10 -------- .../internal/metals/MetalsLspService.scala | 23 +++++++++++-------- .../scala/tests/scalacli/ScalaCliSuite.scala | 2 +- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/builds/ScalaCliBuildTool.scala b/metals/src/main/scala/scala/meta/internal/builds/ScalaCliBuildTool.scala index 31860b39924..d26e7675c54 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/ScalaCliBuildTool.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/ScalaCliBuildTool.scala @@ -35,16 +35,6 @@ class ScalaCliBuildTool( Future.successful(Generated) } - def createBspConfigIfNone( - workspace: AbsolutePath, - systemProcess: List[String] => Future[BspConfigGenerationStatus], - statusBar: StatusBar, - ): Future[BspConfigGenerationStatus] = { - if (ScalaCliBuildTool.pathsToScalaCliBsp(workspace).exists(_.isFile)) - Future.successful(Generated) - else generateBspConfig(workspace, systemProcess, statusBar) - } - override def createBspFileArgs( workspace: AbsolutePath ): Option[List[String]] = 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 7b9246aa0d1..4bac58f3c17 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -1991,16 +1991,19 @@ class MetalsLspService( Future.successful(BuildChange.None) case (Some(_), buildTool: ScalaCliBuildTool) if chosenBuildServer.isEmpty => - for { - _ <- buildTool.createBspConfigIfNone( - folder, - args => - bspConfigGenerator.runUnconditionally(buildTool, args), - statusBar, - ) - _ = tables.buildServers.chooseServer(ScalaCliBuildTool.name) - buildChange <- quickConnectToBuildServer() - } yield buildChange + tables.buildServers.chooseServer(ScalaCliBuildTool.name) + val scalaCliBspConfigExists = + ScalaCliBuildTool.pathsToScalaCliBsp(folder).exists(_.isFile) + if (scalaCliBspConfigExists) Future.successful(BuildChange.None) + else + buildTool + .generateBspConfig( + folder, + args => + bspConfigGenerator.runUnconditionally(buildTool, args), + statusBar, + ) + .flatMap(_ => quickConnectToBuildServer()) case (Some(digest), _) if isBloopOrEmpty => slowConnectToBloopServer(forceImport, buildTool, digest) case (Some(digest), _) => diff --git a/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala b/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala index b6b01c4d93b..8c690a1743e 100644 --- a/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala +++ b/tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala @@ -388,7 +388,7 @@ class ScalaCliSuite extends BaseScalaCliSuite(V.scala3) { .inverseSources(workspace.resolve(fileName)) .isDefined for { - _ <- scalaCliInitialize(useBsp = false)( + _ <- initialize( s"""/src/Main.scala |object Main: | def foo = 3