Skip to content

Commit

Permalink
Pass setup-ide java props to BSP
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Sep 12, 2024
1 parent 6304c20 commit 6bfd690
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions modules/cli/src/main/scala/scala/cli/ScalaCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ object ScalaCli {
def getDefaultScalaVersion: String =
launcherOptions.scalaRunner.cliUserScalaVersion.getOrElse(Constants.defaultScalaVersion)

private var launcherJavaPropArgs: List[String] = List.empty

def getLauncherJavaPropArgs: List[String] = launcherJavaPropArgs

private def partitionArgs(args: Array[String]): (Array[String], Array[String]) = {
val systemProps = args.takeWhile(_.startsWith("-D"))
(systemProps, args.drop(systemProps.size))
Expand Down Expand Up @@ -294,6 +298,7 @@ object ScalaCli {
}
}
val (systemProps, scalaCliArgs) = partitionArgs(remainingArgs)
if systemProps.nonEmpty then launcherJavaPropArgs = systemProps.toList
setSystemProps(systemProps)

(new BouncycastleSignerMaker).maybeInit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ abstract class ScalaCommand[T <: HasGlobalOptions](implicit myParser: Parser[T],
private val globalOptionsAtomic: AtomicReference[GlobalOptions] =
new AtomicReference(GlobalOptions.default)

private def globalOptions: GlobalOptions = globalOptionsAtomic.get()
protected def launcherOptions: LauncherOptions = ScalaCli.launcherOptions
protected def defaultScalaVersion: String = ScalaCli.getDefaultScalaVersion
private def globalOptions: GlobalOptions = globalOptionsAtomic.get()
protected def launcherOptions: LauncherOptions = ScalaCli.launcherOptions
protected def defaultScalaVersion: String = ScalaCli.getDefaultScalaVersion
protected def launcherJavaPropArgs: List[String] = ScalaCli.getLauncherJavaPropArgs

def sharedOptions(t: T): Option[SharedOptions] = // hello borked unused warning
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
val bspArgs =
List(launcher) ++
finalLauncherOptions.toCliArgs ++
launcherJavaPropArgs ++
List("bsp") ++
debugOpt ++
List("--json-options", scalaCliBspJsonDestination.toString) ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2202,4 +2202,17 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
expect(bspConfig.argv.indexOfSlice(cliVersionArgs) < bspConfig.argv.indexOf("bsp"))
}
}

test("setup-ide passes Java props to the BSP configuration correctly") {
val scriptName = "hello.sc"
TestInputs(os.rel / scriptName -> s"""println("Hello")""").fromRoot { root =>
val javaProps = List("-Dfoo=bar", "-Dbar=baz")
os.proc(TestUtil.cli, javaProps, "setup-ide", scriptName, extraOptions)
.call(cwd = root)
val bspConfig = readBspConfig(root)
expect(bspConfig.argv.head == TestUtil.cliPath)
expect(bspConfig.argv.containsSlice(javaProps))
expect(bspConfig.argv.indexOfSlice(javaProps) < bspConfig.argv.indexOf("bsp"))
}
}
}

0 comments on commit 6bfd690

Please sign in to comment.