Skip to content

Commit 68b3ce8

Browse files
authored
Apply increased verbosity when compiling via BSP (#3202)
1 parent f178f93 commit 68b3ce8

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

modules/build/src/main/scala/scala/build/bsp/BspServer.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class BspServer(
2626
with JavaBuildServerForwardStubs
2727
with JvmBuildServerForwardStubs
2828
with HasGeneratedSourcesImpl {
29-
3029
private var client: Option[BuildClient] = None
3130

3231
@volatile private var intelliJ: Boolean = presetIntelliJ
@@ -200,7 +199,7 @@ class BspServer(
200199
super.buildTargetCleanCache(check(params))
201200

202201
override def buildTargetCompile(params: b.CompileParams): CompletableFuture[b.CompileResult] =
203-
compile(() => super.buildTargetCompile(check(params)))
202+
compile(() => super.buildTargetCompile(check(params.withVerbosity(logger.verbosity > 0))))
204203

205204
override def buildTargetDependencySources(
206205
params: b.DependencySourcesParams

modules/build/src/main/scala/scala/build/bsp/package.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ import scala.jdk.CollectionConverters.*
99

1010
package object bsp {
1111

12+
extension (compileParams: b.CompileParams) {
13+
def duplicate(): b.CompileParams = {
14+
val params = new b.CompileParams(compileParams.getTargets)
15+
params.setOriginId(compileParams.getOriginId)
16+
params.setArguments(compileParams.getArguments)
17+
params
18+
}
19+
20+
def withExtraArgs(extraArgs: List[String]): b.CompileParams = {
21+
val params = compileParams.duplicate()
22+
val previousArguments = Option(params.getArguments).toList.flatMap(_.asScala)
23+
val newArguments = (previousArguments ++ extraArgs).asJava
24+
params.setArguments(newArguments)
25+
params
26+
}
27+
28+
def withVerbosity(verbose: Boolean): b.CompileParams = {
29+
val verboseArg = "--verbose"
30+
val argumentsContainVerboseArg =
31+
Option(compileParams.getArguments).exists(_.contains(verboseArg))
32+
if verbose && !argumentsContainVerboseArg then compileParams.withExtraArgs(List(verboseArg))
33+
else compileParams
34+
}
35+
}
36+
1237
implicit class Ext[T](private val f: CompletableFuture[T]) extends AnyVal {
1338
def logF: CompletableFuture[T] =
1439
f.handle { (res, err) =>

modules/integration/src/test/scala/scala/cli/integration/BspSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ trait BspSuite { _: ScalaCliSuite =>
8686
def attempt(): Try[T] = Try {
8787
val inputsRoot = inputs.root()
8888
val root = reuseRoot.getOrElse(inputsRoot)
89-
val stdErrPathOpt: Option[os.ProcessOutput] = stdErrOpt.map(path => inputsRoot / path)
89+
val stdErrPathOpt: Option[os.ProcessOutput] = stdErrOpt.map(path => root / path)
9090
val stderr: os.ProcessOutput = stdErrPathOpt.getOrElse(os.Inherit)
9191

9292
val proc = os.proc(TestUtil.cli, "bsp", bspOptions ++ extraOptionsOverride, args)

modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,4 +2215,65 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
22152215
expect(bspConfig.argv.indexOfSlice(javaProps) < bspConfig.argv.indexOf("bsp"))
22162216
}
22172217
}
2218+
2219+
test("BSP loads verbosity on compile") {
2220+
val stderrFile = os.rel / "stderr.txt"
2221+
val inputs = TestInputs(
2222+
os.rel / "Hello.scala" ->
2223+
s"""object Hello extends App {
2224+
| println("Hello World")
2225+
|}
2226+
|""".stripMargin
2227+
)
2228+
withBsp(inputs, Seq(".", "-v"), stdErrOpt = Some(stderrFile)) {
2229+
(root, _, remoteServer) =>
2230+
async {
2231+
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
2232+
val targets = buildTargetsResp.getTargets.asScala.map(_.getId())
2233+
val compileResp = await {
2234+
remoteServer
2235+
.buildTargetCompile(new b.CompileParams(targets.asJava))
2236+
.asScala
2237+
}
2238+
expect(compileResp.getStatusCode == b.StatusCode.OK)
2239+
expect(os.read(root / stderrFile).contains("Scheduling compilation"))
2240+
}
2241+
}
2242+
}
2243+
2244+
test("BSP loads verbosity on compile when passed from setup-ide") {
2245+
val stderrFile = os.rel / "stderr.txt"
2246+
val inputs = TestInputs(
2247+
os.rel / "Hello.scala" ->
2248+
s"""object Hello extends App {
2249+
| println("Hello World")
2250+
|}
2251+
|""".stripMargin
2252+
)
2253+
inputs.fromRoot { root =>
2254+
os.proc(TestUtil.cli, "setup-ide", ".", "-v").call(cwd = root)
2255+
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
2256+
val jsonOptions = List("--json-options", ideOptionsPath.toString)
2257+
withBsp(
2258+
inputs = inputs,
2259+
args = Seq("."),
2260+
bspOptions = jsonOptions,
2261+
reuseRoot = Some(root),
2262+
stdErrOpt = Some(stderrFile)
2263+
) {
2264+
(_, _, remoteServer) =>
2265+
async {
2266+
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
2267+
val targets = buildTargetsResp.getTargets.asScala.map(_.getId())
2268+
val compileResp = await {
2269+
remoteServer
2270+
.buildTargetCompile(new b.CompileParams(targets.asJava))
2271+
.asScala
2272+
}
2273+
expect(compileResp.getStatusCode == b.StatusCode.OK)
2274+
expect(os.read(root / stderrFile).contains("Scheduling compilation"))
2275+
}
2276+
}
2277+
}
2278+
}
22182279
}

0 commit comments

Comments
 (0)