Skip to content

Commit

Permalink
BSP: Add JavaModule.bspBuildTargetData to make JavaModule reports wor…
Browse files Browse the repository at this point in the history
…kable BuildTarget (#2930)

* JavaModule` was not reporting `BuildTarget.dataKind` and `data` such that IJ will
not ask `BuildTargetJavacOptions` for `JavaModule` and resolved as no
dependency at all.

This change also reuses/sets  the `JvmBuildTarget` in the `ScalaBuildTarget` data.
---------

Co-authored-by: Tobias Roeser <le.petit.fou@web.de>
  • Loading branch information
chikei and lefou authored Jan 3, 2024
1 parent 393e4df commit 7c9c11c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
12 changes: 11 additions & 1 deletion scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import mill.api.{Ctx, JarManifest, MillException, PathRef, Result, internal}
import mill.define.{Command, ModuleRef, Segment, Task, TaskModule}
import mill.scalalib.internal.ModuleUtils
import mill.scalalib.api.CompilationResult
import mill.scalalib.bsp.{BspBuildTarget, BspModule}
import mill.scalalib.bsp.{BspBuildTarget, BspModule, BspUri, JvmBuildTarget}
import mill.scalalib.publish.Artifact
import mill.util.Jvm
import os.{Path, ProcessOutput}
Expand Down Expand Up @@ -1025,4 +1025,14 @@ trait JavaModule
canRun = true
)

@internal
override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = T.task {
Some((
JvmBuildTarget.dataKind,
JvmBuildTarget(
javaHome = Option(System.getProperty("java.home")).map(p => BspUri(os.Path(p))),
javaVersion = Option(System.getProperty("java.version"))
)
))
}
}
25 changes: 21 additions & 4 deletions scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import mill.util.Jvm.createJar
import mill.api.Loose.Agg
import mill.scalalib.api.{CompilationResult, Versions, ZincWorkerUtil}
import mainargs.Flag
import mill.scalalib.bsp.{BspBuildTarget, BspModule, ScalaBuildTarget, ScalaPlatform}
import mill.scalalib.bsp.{
BspBuildTarget,
BspModule,
BspUri,
JvmBuildTarget,
ScalaBuildTarget,
ScalaPlatform
}
import mill.scalalib.dependency.versions.{ValidVersion, Version}

import scala.reflect.internal.util.ScalaClassLoader
Expand Down Expand Up @@ -590,12 +597,22 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
scalaBinaryVersion = ZincWorkerUtil.scalaBinaryVersion(scalaVersion()),
platform = ScalaPlatform.JVM,
jars = scalaCompilerClasspath().map(_.path.toNIO.toUri.toString).iterator.toSeq,
jvmBuildTarget = None
// this is what we want to use, but can't due to a resulting binary incompatibility
// jvmBuildTarget = super.bspBuildTargetData().flatMap {
// case (JvmBuildTarget.dataKind, bt: JvmBuildTarget) => Some(bt)
// case _ => None
// }
jvmBuildTarget = Some(
JvmBuildTarget(
javaHome = Option(System.getProperty("java.home")).map(p => BspUri(os.Path(p))),
javaVersion = Option(System.getProperty("java.version"))
)
)
)
))
}

override def semanticDbScalaVersion = scalaVersion()
override def semanticDbScalaVersion: T[String] = scalaVersion()

override protected def semanticDbPluginClasspath = T {
resolveDeps(T.task {
Expand All @@ -604,7 +621,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
})()
}

def semanticDbData: T[PathRef] = T.persistent {
override def semanticDbData: T[PathRef] = T.persistent {
val sv = scalaVersion()

val scalacOptions = (
Expand Down

0 comments on commit 7c9c11c

Please sign in to comment.