Skip to content

Commit

Permalink
bugfix: deduplicate auto connect requests for scala-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 14, 2023
1 parent d7be734 commit a3edc1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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), _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3edc1e

Please sign in to comment.