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

BSP: Add JavaModule.bspBuildTargetData to make JavaModule reports workable BuildTarget #2930

Merged
merged 3 commits into from
Jan 3, 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
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