Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply increased verbosity when compiling via BSP #3202

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions modules/build/src/main/scala/scala/build/bsp/BspServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BspServer(
with JavaBuildServerForwardStubs
with JvmBuildServerForwardStubs
with HasGeneratedSourcesImpl {

private var client: Option[BuildClient] = None

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

override def buildTargetCompile(params: b.CompileParams): CompletableFuture[b.CompileResult] =
compile(() => super.buildTargetCompile(check(params)))
compile(() => super.buildTargetCompile(check(params.withVerbosity(logger.verbosity > 0))))

override def buildTargetDependencySources(
params: b.DependencySourcesParams
Expand Down
25 changes: 25 additions & 0 deletions modules/build/src/main/scala/scala/build/bsp/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ import scala.jdk.CollectionConverters.*

package object bsp {

extension (compileParams: b.CompileParams) {
def duplicate(): b.CompileParams = {
val params = new b.CompileParams(compileParams.getTargets)
params.setOriginId(compileParams.getOriginId)
params.setArguments(compileParams.getArguments)
params
}

def withExtraArgs(extraArgs: List[String]): b.CompileParams = {
val params = compileParams.duplicate()
val previousArguments = Option(params.getArguments).toList.flatMap(_.asScala)
val newArguments = (previousArguments ++ extraArgs).asJava
params.setArguments(newArguments)
params
}

def withVerbosity(verbose: Boolean): b.CompileParams = {
val verboseArg = "--verbose"
val argumentsContainVerboseArg =
Option(compileParams.getArguments).exists(_.contains(verboseArg))
if verbose && !argumentsContainVerboseArg then compileParams.withExtraArgs(List(verboseArg))
else compileParams
}
}

implicit class Ext[T](private val f: CompletableFuture[T]) extends AnyVal {
def logF: CompletableFuture[T] =
f.handle { (res, err) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ trait BspSuite { _: ScalaCliSuite =>
def attempt(): Try[T] = Try {
val inputsRoot = inputs.root()
val root = reuseRoot.getOrElse(inputsRoot)
val stdErrPathOpt: Option[os.ProcessOutput] = stdErrOpt.map(path => inputsRoot / path)
val stdErrPathOpt: Option[os.ProcessOutput] = stdErrOpt.map(path => root / path)
val stderr: os.ProcessOutput = stdErrPathOpt.getOrElse(os.Inherit)

val proc = os.proc(TestUtil.cli, "bsp", bspOptions ++ extraOptionsOverride, args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2215,4 +2215,65 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
expect(bspConfig.argv.indexOfSlice(javaProps) < bspConfig.argv.indexOf("bsp"))
}
}

test("BSP loads verbosity on compile") {
val stderrFile = os.rel / "stderr.txt"
val inputs = TestInputs(
os.rel / "Hello.scala" ->
s"""object Hello extends App {
| println("Hello World")
|}
|""".stripMargin
)
withBsp(inputs, Seq(".", "-v"), stdErrOpt = Some(stderrFile)) {
(root, _, remoteServer) =>
async {
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
val targets = buildTargetsResp.getTargets.asScala.map(_.getId())
val compileResp = await {
remoteServer
.buildTargetCompile(new b.CompileParams(targets.asJava))
.asScala
}
expect(compileResp.getStatusCode == b.StatusCode.OK)
expect(os.read(root / stderrFile).contains("Scheduling compilation"))
}
}
}

test("BSP loads verbosity on compile when passed from setup-ide") {
val stderrFile = os.rel / "stderr.txt"
val inputs = TestInputs(
os.rel / "Hello.scala" ->
s"""object Hello extends App {
| println("Hello World")
|}
|""".stripMargin
)
inputs.fromRoot { root =>
os.proc(TestUtil.cli, "setup-ide", ".", "-v").call(cwd = root)
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
val jsonOptions = List("--json-options", ideOptionsPath.toString)
withBsp(
inputs = inputs,
args = Seq("."),
bspOptions = jsonOptions,
reuseRoot = Some(root),
stdErrOpt = Some(stderrFile)
) {
(_, _, remoteServer) =>
async {
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
val targets = buildTargetsResp.getTargets.asScala.map(_.getId())
val compileResp = await {
remoteServer
.buildTargetCompile(new b.CompileParams(targets.asJava))
.asScala
}
expect(compileResp.getStatusCode == b.StatusCode.OK)
expect(os.read(root / stderrFile).contains("Scheduling compilation"))
}
}
}
}
}
Loading