mirror of https://github.com/sbt/sbt.git
Merge pull request #8029 from eed3si9n/wip/metals
[2.x] fix: Fix semanticdbEnabled
This commit is contained in:
commit
c60142e061
|
|
@ -55,8 +55,9 @@ object SemanticdbPlugin extends AutoPlugin {
|
|||
|
||||
lazy val configurationSettings: Seq[Def.Setting[?]] = List(
|
||||
semanticdbTargetRoot := {
|
||||
val converter = fileConverter.value
|
||||
val in = semanticdbIncludeInJar.value
|
||||
if (in) classDirectory.value
|
||||
if in then converter.toPath(backendOutput.value).toFile()
|
||||
else semanticdbTargetRoot.value
|
||||
},
|
||||
semanticdbOptions --= Def.settingDyn {
|
||||
|
|
@ -69,29 +70,24 @@ object SemanticdbPlugin extends AutoPlugin {
|
|||
}.value,
|
||||
semanticdbOptions ++=
|
||||
targetRootOptions(scalaVersion.value, semanticdbTargetRoot.value),
|
||||
// todo:
|
||||
// scalacOptions --= {
|
||||
// Def
|
||||
// .task { (configuration.value, semanticdbEnabled.value) }
|
||||
// .flatMapTask { case (config, enabled) =>
|
||||
// if enabled then
|
||||
// Def.task {
|
||||
// (semanticdbOptions.?.all(ancestorConfigs(config)).value.flatten.flatten: Seq[String])
|
||||
// }
|
||||
// else Def.task { (Nil: Seq[String]) }
|
||||
// }
|
||||
// .value
|
||||
// },
|
||||
scalacOptions ++= {
|
||||
if (semanticdbEnabled.value)
|
||||
semanticdbOptions.value
|
||||
else Seq.empty
|
||||
}
|
||||
scalacOptions := (Def.taskDyn {
|
||||
val orig = scalacOptions.value
|
||||
val config = configuration.value
|
||||
if semanticdbEnabled.value then
|
||||
Def.task {
|
||||
val xs =
|
||||
(orig diff semanticdbOptions.?.all(ancestorConfigs(config)).value.flatten.flatten) ++
|
||||
semanticdbOptions.value
|
||||
println(xs.toString)
|
||||
xs
|
||||
}
|
||||
else
|
||||
Def.task {
|
||||
orig
|
||||
}
|
||||
}).value,
|
||||
)
|
||||
|
||||
@deprecated("use configurationSettings only", "1.5.0")
|
||||
lazy val testSettings: Seq[Def.Setting[?]] = List()
|
||||
|
||||
def targetRootOptions(scalaVersion: String, targetRoot: File): Seq[String] = {
|
||||
if (ScalaInstance.isDotty(scalaVersion)) {
|
||||
Seq("-semanticdb-target", targetRoot.toString)
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
ThisBuild / scalaVersion := "2.12.20"
|
||||
ThisBuild / semanticdbEnabled := true
|
||||
ThisBuild / semanticdbIncludeInJar := true
|
||||
scalaVersion := "2.13.16"
|
||||
semanticdbEnabled := true
|
||||
semanticdbIncludeInJar := true
|
||||
|
||||
// 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 anyConfigInThisProject = ScopeFilter(configurations = inAnyConfiguration)
|
||||
|
||||
lazy val Custom = config("custom").extend(Compile)
|
||||
lazy val SystemTest = config("st").extend(IntegrationTest)
|
||||
|
||||
lazy val root = (project in file("."))
|
||||
.configs(IntegrationTest, Custom, SystemTest)
|
||||
.configs(Custom)
|
||||
.settings(
|
||||
inConfig(IntegrationTest)(Defaults.testSettings ++ sbt.plugins.SemanticdbPlugin.configurationSettings),
|
||||
inConfig(Custom)(Defaults.configSettings ++ sbt.plugins.SemanticdbPlugin.configurationSettings),
|
||||
inConfig(SystemTest)(Defaults.testSettings ++ sbt.plugins.SemanticdbPlugin.configurationSettings),
|
||||
check := {
|
||||
val scalacOptionsCountsAcrossConfigs = scalacOptions.?.all(anyConfigInThisProject)
|
||||
.value
|
||||
|
|
@ -25,6 +22,12 @@ lazy val root = (project in file("."))
|
|||
scalacOptionsCountsAcrossConfigs.size == 1,
|
||||
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")
|
||||
}
|
||||
)
|
||||
|
|
@ -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
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
package foo
|
||||
|
||||
object IntegrationTest
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
package foo
|
||||
|
||||
object SystemTest
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue