Skip to content

Commit

Permalink
change createBspFileArgs to return option
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek authored and tgodzik committed Jul 11, 2023
1 parent 3bca616 commit 72baaee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,18 @@ trait BuildServerProvider extends BuildTool {
workspace: AbsolutePath,
systemProcess: List[String] => Future[BspConfigGenerationStatus],
): Future[BspConfigGenerationStatus] =
if (workspaceSupportsBsp(workspace)) {
systemProcess(createBspFileArgs(workspace))
} else {
createBspFileArgs(workspace).map(systemProcess).getOrElse {
Future.successful(
Failed(Right(Messages.NoBspSupport.toString()))
)
}

/**
* Args necessary for build tool to generate the bsp config file.
*/
protected def createBspFileArgs(workspace: AbsolutePath): List[String]

/**
* Whether or not the build tool workspace supports BSP. Many times this is
* Args necessary for build tool to generate the bsp config file
* if the build tool workspace supports BSP. Many times this is
* limited by the version of the build tool that introduces BSP support.
*/
protected def workspaceSupportsBsp(workspace: AbsolutePath): Boolean
protected def createBspFileArgs(workspace: AbsolutePath): Option[List[String]]

/**
* Name of the build server if different than the actual build-tool that is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,15 @@ case class MillBuildTool(userConfig: () => UserConfiguration)
Files.write(tempDir.resolve(predefScriptName), predefScript)
}

override def createBspFileArgs(workspace: AbsolutePath): List[String] = {
val cmd = "mill.bsp.BSP/install" :: Nil
putTogetherArgs(cmd, getMillVersion(workspace), workspace)
}
override def createBspFileArgs(
workspace: AbsolutePath
): Option[List[String]] =
Option.when(workspaceSupportsBsp(workspace: AbsolutePath)) {
val cmd = "mill.bsp.BSP/install" :: Nil
putTogetherArgs(cmd, getMillVersion(workspace), workspace)
}

override def workspaceSupportsBsp(workspace: AbsolutePath): Boolean = {
def workspaceSupportsBsp(workspace: AbsolutePath): Boolean = {
val minimumVersionForBsp = "0.10.0-M4"
val millVersion = getMillVersion(workspace)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ case class SbtBuildTool(
override val minimumVersion: String = "0.13.17"
override val recommendedVersion: String = BuildInfo.sbtVersion

override def createBspFileArgs(workspace: AbsolutePath): List[String] = {
val bspConfigArgs = List[String](
"bspConfig"
)
val bspDir = workspace.resolve(".bsp").toNIO
composeArgs(bspConfigArgs, workspace, bspDir)
}
override def createBspFileArgs(
workspace: AbsolutePath
): Option[List[String]] =
Option.when(workspaceSupportsBsp(workspace)) {
val bspConfigArgs = List[String]("bspConfig")
val bspDir = workspace.resolve(".bsp").toNIO
composeArgs(bspConfigArgs, workspace, bspDir)
}

def shutdownBspServer(
shellRunner: ShellRunner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class ScalaCliBuildTool(
workspace: AbsolutePath,
systemProcess: List[String] => Future[BspConfigGenerationStatus],
): Future[BspConfigGenerationStatus] =
if (runScalaCliCommand.nonEmpty) {
systemProcess(createBspFileArgs(workspace))
} else {
createBspFileArgs(workspace).map(systemProcess).getOrElse {
// fallback to creating `.bsp/scala-cli.json` that starts JVM launcher
val bspConfig = workspace.resolve(".bsp").resolve("scala-cli.json")
bspConfig.writeText(ScalaCli.scalaCliBspJsonContent())
Expand All @@ -42,14 +40,16 @@ class ScalaCliBuildTool(
else generateBspConfig(workspace, systemProcess)
}

override def createBspFileArgs(workspace: AbsolutePath): List[String] =
runScalaCliCommand.getOrElse(Seq("scala-cli")).toList ++ List(
"setup-ide",
workspace.toString(),
override def createBspFileArgs(
workspace: AbsolutePath
): Option[List[String]] =
runScalaCliCommand.map(
_.toList ++ List(
"setup-ide",
workspace.toString(),
)
)

override def workspaceSupportsBsp(workspace: AbsolutePath): Boolean = true

override def bloopInstall(
workspace: AbsolutePath,
systemProcess: List[String] => Future[WorkspaceLoadedStatus],
Expand Down

0 comments on commit 72baaee

Please sign in to comment.