Merge pull request #8029 from eed3si9n/wip/metals

[2.x] fix: Fix semanticdbEnabled
This commit is contained in:
eugene yokota 2025-02-02 20:02:45 -05:00 committed by GitHub
commit c60142e061
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 34 additions and 52 deletions

View File

@ -55,8 +55,9 @@ object SemanticdbPlugin extends AutoPlugin {
lazy val configurationSettings: Seq[Def.Setting[?]] = List( lazy val configurationSettings: Seq[Def.Setting[?]] = List(
semanticdbTargetRoot := { semanticdbTargetRoot := {
val converter = fileConverter.value
val in = semanticdbIncludeInJar.value val in = semanticdbIncludeInJar.value
if (in) classDirectory.value if in then converter.toPath(backendOutput.value).toFile()
else semanticdbTargetRoot.value else semanticdbTargetRoot.value
}, },
semanticdbOptions --= Def.settingDyn { semanticdbOptions --= Def.settingDyn {
@ -69,29 +70,24 @@ object SemanticdbPlugin extends AutoPlugin {
}.value, }.value,
semanticdbOptions ++= semanticdbOptions ++=
targetRootOptions(scalaVersion.value, semanticdbTargetRoot.value), targetRootOptions(scalaVersion.value, semanticdbTargetRoot.value),
// todo: scalacOptions := (Def.taskDyn {
// scalacOptions --= { val orig = scalacOptions.value
// Def val config = configuration.value
// .task { (configuration.value, semanticdbEnabled.value) } if semanticdbEnabled.value then
// .flatMapTask { case (config, enabled) => Def.task {
// if enabled then val xs =
// Def.task { (orig diff semanticdbOptions.?.all(ancestorConfigs(config)).value.flatten.flatten) ++
// (semanticdbOptions.?.all(ancestorConfigs(config)).value.flatten.flatten: Seq[String]) semanticdbOptions.value
// } println(xs.toString)
// else Def.task { (Nil: Seq[String]) } xs
// } }
// .value else
// }, Def.task {
scalacOptions ++= { orig
if (semanticdbEnabled.value) }
semanticdbOptions.value }).value,
else Seq.empty
}
) )
@deprecated("use configurationSettings only", "1.5.0")
lazy val testSettings: Seq[Def.Setting[?]] = List()
def targetRootOptions(scalaVersion: String, targetRoot: File): Seq[String] = { def targetRootOptions(scalaVersion: String, targetRoot: File): Seq[String] = {
if (ScalaInstance.isDotty(scalaVersion)) { if (ScalaInstance.isDotty(scalaVersion)) {
Seq("-semanticdb-target", targetRoot.toString) Seq("-semanticdb-target", targetRoot.toString)

View File

@ -1,20 +1,17 @@
ThisBuild / scalaVersion := "2.12.20" scalaVersion := "2.13.16"
ThisBuild / semanticdbEnabled := true semanticdbEnabled := true
ThisBuild / semanticdbIncludeInJar := true semanticdbIncludeInJar := true
// see https://github.com/sbt/sbt/issues/5886 // see https://github.com/sbt/sbt/issues/5886
lazy val check = taskKey[Unit]("Checks that scalacOptions have the same number of parameters across configurations") lazy val check = taskKey[Unit]("Checks that scalacOptions have the same number of parameters across configurations")
lazy val anyConfigInThisProject = ScopeFilter(configurations = inAnyConfiguration) lazy val anyConfigInThisProject = ScopeFilter(configurations = inAnyConfiguration)
lazy val Custom = config("custom").extend(Compile) lazy val Custom = config("custom").extend(Compile)
lazy val SystemTest = config("st").extend(IntegrationTest)
lazy val root = (project in file(".")) lazy val root = (project in file("."))
.configs(IntegrationTest, Custom, SystemTest) .configs(Custom)
.settings( .settings(
inConfig(IntegrationTest)(Defaults.testSettings ++ sbt.plugins.SemanticdbPlugin.configurationSettings),
inConfig(Custom)(Defaults.configSettings ++ sbt.plugins.SemanticdbPlugin.configurationSettings), inConfig(Custom)(Defaults.configSettings ++ sbt.plugins.SemanticdbPlugin.configurationSettings),
inConfig(SystemTest)(Defaults.testSettings ++ sbt.plugins.SemanticdbPlugin.configurationSettings),
check := { check := {
val scalacOptionsCountsAcrossConfigs = scalacOptions.?.all(anyConfigInThisProject) val scalacOptionsCountsAcrossConfigs = scalacOptions.?.all(anyConfigInThisProject)
.value .value
@ -25,6 +22,12 @@ lazy val root = (project in file("."))
scalacOptionsCountsAcrossConfigs.size == 1, scalacOptionsCountsAcrossConfigs.size == 1,
s"Configurations expected to have the same number of scalacOptions but found different numbers: $scalacOptionsCountsAcrossConfigs" s"Configurations expected to have the same number of scalacOptions but found different numbers: $scalacOptionsCountsAcrossConfigs"
) )
}
val converter = fileConverter.value
val p = converter.toPath((Compile / packageBin).value)
IO.unzip(p.toFile(), target.value / "extracted")
val testp = converter.toPath((Test / packageBin).value)
IO.unzip(testp.toFile(), target.value / "test-extracted")
}
) )

View File

@ -0,0 +1,5 @@
> check
$ exists target/**/extracted/META-INF/semanticdb/src/main/scala/foo/Compile.scala.semanticdb
$ exists target/**/test-extracted/META-INF/semanticdb/src/test/scala/foo/Test.scala.semanticdb

View File

@ -1,3 +0,0 @@
package foo
object IntegrationTest

View File

@ -1,3 +0,0 @@
package foo
object SystemTest

View File

@ -1,16 +0,0 @@
> compile
$ exists target/scala-2.12/classes/META-INF/semanticdb/src/main/scala/foo/Compile.scala.semanticdb
> Test/compile
$ exists target/scala-2.12/test-classes/META-INF/semanticdb/src/test/scala/foo/Test.scala.semanticdb
> IntegrationTest/compile
$ exists target/scala-2.12/it-classes/META-INF/semanticdb/src/it/scala/foo/IntegrationTest.scala.semanticdb
> Custom/compile
$ exists target/scala-2.12/custom-classes/META-INF/semanticdb/src/custom/scala/foo/Custom.scala.semanticdb
> SystemTest/compile
$ exists target/scala-2.12/st-classes/META-INF/semanticdb/src/st/scala/foo/SystemTest.scala.semanticdb
> check