bspWorkspace is a setting

This commit is contained in:
Adrien Piquerez 2020-05-14 13:28:27 +02:00
parent f3bce7e976
commit 2c8a322bd8
3 changed files with 17 additions and 16 deletions

View File

@ -1941,7 +1941,7 @@ object Defaults extends BuildCommon {
}, },
compilerReporter := { compilerReporter := {
new BuildServerReporter( new BuildServerReporter(
buildTargetIdentifier.value, bspTargetIdentifier.value,
maxErrors.value, maxErrors.value,
streams.value.log, streams.value.log,
foldMappers(sourcePositionMappers.value), foldMappers(sourcePositionMappers.value),

View File

@ -339,8 +339,9 @@ object Keys {
val closeClassLoaders = settingKey[Boolean]("Close classloaders in run and test when the task completes.").withRank(DSetting) val closeClassLoaders = settingKey[Boolean]("Close classloaders in run and test when the task completes.").withRank(DSetting)
val allowZombieClassLoaders = settingKey[Boolean]("Allow a classloader that has previously been closed by `run` or `test` to continue loading classes.") val allowZombieClassLoaders = settingKey[Boolean]("Allow a classloader that has previously been closed by `run` or `test` to continue loading classes.")
val buildTargetIdentifier = settingKey[BuildTargetIdentifier]("Id for BSP build target.").withRank(DSetting) val bspTargetIdentifier = settingKey[BuildTargetIdentifier]("Id for BSP build target.").withRank(DSetting)
val bspWorkspace = taskKey[Map[BuildTargetIdentifier, Scope]]("Mapping of BSP build targets to sbt scopes").withRank(DTask) val bspWorkspace = settingKey[Map[BuildTargetIdentifier, Scope]]("Mapping of BSP build targets to sbt scopes").withRank(DSetting)
val bspInternalDependencyConfigurations = settingKey[Seq[(ProjectRef, Set[String])]]("The project configurations that this configuration depends on, possibly transitivly").withRank(DSetting)
val bspWorkspaceBuildTargets = taskKey[Seq[BuildTarget]]("List all the BSP build targets").withRank(DTask) val bspWorkspaceBuildTargets = taskKey[Seq[BuildTarget]]("List all the BSP build targets").withRank(DTask)
val bspBuildTarget = taskKey[BuildTarget]("Description of the BSP build targets").withRank(DTask) val bspBuildTarget = taskKey[BuildTarget]("Description of the BSP build targets").withRank(DTask)
val bspBuildTargetSources = inputKey[Unit]("").withRank(DTask) val bspBuildTargetSources = inputKey[Unit]("").withRank(DTask)
@ -351,7 +352,6 @@ object Keys {
val bspBuildTargetCompileItem = taskKey[Int]("").withRank(DTask) val bspBuildTargetCompileItem = taskKey[Int]("").withRank(DTask)
val bspBuildTargetScalacOptions = inputKey[Unit]("").withRank(DTask) val bspBuildTargetScalacOptions = inputKey[Unit]("").withRank(DTask)
val bspBuildTargetScalacOptionsItem = taskKey[ScalacOptionsItem]("").withRank(DTask) val bspBuildTargetScalacOptionsItem = taskKey[ScalacOptionsItem]("").withRank(DTask)
val bspInternalDependencyConfigurations = settingKey[Seq[(ProjectRef, Set[String])]]("The project configurations that this configuration depends on, possibly transitivly").withRank(DTask)
val useCoursier = settingKey[Boolean]("Use Coursier for dependency resolution.").withRank(BSetting) val useCoursier = settingKey[Boolean]("Use Coursier for dependency resolution.").withRank(BSetting)
val csrCacheDirectory = settingKey[File]("Coursier cache directory. Uses -Dsbt.coursier.home or Coursier's default.").withRank(CSetting) val csrCacheDirectory = settingKey[File]("Coursier cache directory. Uses -Dsbt.coursier.home or Coursier's default.").withRank(CSetting)

View File

@ -34,13 +34,14 @@ object BuildServerProtocol {
) )
lazy val globalSettings: Seq[Def.Setting[_]] = Seq( lazy val globalSettings: Seq[Def.Setting[_]] = Seq(
bspWorkspace := Def.taskDyn { bspWorkspace := Def.settingDyn {
val structure = Keys.buildStructure.value val loadedBuild = Keys.loadedBuild.value
val scopes: Seq[Scope] = structure.allProjectRefs.flatMap { ref => val scopes: Seq[Scope] = loadedBuild.allProjectRefs.flatMap {
bspTargetConfigs.toSeq.map(name => Scope.Global.in(ref, ConfigKey(name))) case (ref, _) =>
bspTargetConfigs.toSeq.map(name => Scope.Global.in(ref, ConfigKey(name)))
} }
Def.task { Def.setting {
val targetIds = scopes.map(_ / Keys.buildTargetIdentifier).join.value val targetIds = scopes.map(_ / Keys.bspTargetIdentifier).join.value
targetIds.zip(scopes).toMap targetIds.zip(scopes).toMap
} }
}.value, }.value,
@ -111,14 +112,14 @@ object BuildServerProtocol {
// This will be scoped to Compile, Test, etc // This will be scoped to Compile, Test, etc
lazy val configSettings: Seq[Def.Setting[_]] = Seq( lazy val configSettings: Seq[Def.Setting[_]] = Seq(
buildTargetIdentifier := { bspTargetIdentifier := {
val ref = thisProjectRef.value val ref = thisProjectRef.value
val c = configuration.value val c = configuration.value
toId(ref, c) toId(ref, c)
}, },
bspBuildTarget := buildTargetTask.value, bspBuildTarget := buildTargetTask.value,
bspBuildTargetSourcesItem := { bspBuildTargetSourcesItem := {
val id = buildTargetIdentifier.value val id = bspTargetIdentifier.value
val dirs = unmanagedSourceDirectories.value val dirs = unmanagedSourceDirectories.value
val managed = managedSources.value val managed = managedSources.value
val items = (dirs.toVector map { dir => val items = (dirs.toVector map { dir =>
@ -190,7 +191,7 @@ object BuildServerProtocol {
) )
private def buildTargetTask: Def.Initialize[Task[BuildTarget]] = Def.taskDyn { private def buildTargetTask: Def.Initialize[Task[BuildTarget]] = Def.taskDyn {
val buildTargetIdentifier = Keys.buildTargetIdentifier.value val buildTargetIdentifier = Keys.bspTargetIdentifier.value
val thisProject = Keys.thisProject.value val thisProject = Keys.thisProject.value
val thisProjectRef = Keys.thisProjectRef.value val thisProjectRef = Keys.thisProjectRef.value
val thisConfig = Keys.configuration.value val thisConfig = Keys.configuration.value
@ -212,7 +213,7 @@ object BuildServerProtocol {
(dep, configs) <- Keys.bspInternalDependencyConfigurations.value (dep, configs) <- Keys.bspInternalDependencyConfigurations.value
config <- configs config <- configs
if (dep != thisProjectRef || config != thisConfig.name) && bspTargetConfigs.contains(config) if (dep != thisProjectRef || config != thisConfig.name) && bspTargetConfigs.contains(config)
} yield Keys.buildTargetIdentifier.in(dep, ConfigKey(config)) } yield Keys.bspTargetIdentifier.in(dep, ConfigKey(config))
val capabilities = BuildTargetCapabilities(canCompile = true, canTest = false, canRun = false) val capabilities = BuildTargetCapabilities(canCompile = true, canTest = false, canRun = false)
val tags = BuildTargetTag.fromConfig(configuration.name) val tags = BuildTargetTag.fromConfig(configuration.name)
Def.task { Def.task {
@ -231,7 +232,7 @@ object BuildServerProtocol {
} }
private def scalacOptionsTask: Def.Initialize[Task[ScalacOptionsItem]] = Def.taskDyn { private def scalacOptionsTask: Def.Initialize[Task[ScalacOptionsItem]] = Def.taskDyn {
val target = Keys.buildTargetIdentifier.value val target = Keys.bspTargetIdentifier.value
val scalacOptions = Keys.scalacOptions.value val scalacOptions = Keys.scalacOptions.value
val classDirectory = Keys.classDirectory.value val classDirectory = Keys.classDirectory.value
val externalDependencyClasspath = Keys.externalDependencyClasspath.value val externalDependencyClasspath = Keys.externalDependencyClasspath.value
@ -254,7 +255,7 @@ object BuildServerProtocol {
} }
private def dependencySourcesItemTask: Def.Initialize[Task[DependencySourcesItem]] = Def.task { private def dependencySourcesItemTask: Def.Initialize[Task[DependencySourcesItem]] = Def.task {
val targetId = Keys.buildTargetIdentifier.value val targetId = Keys.bspTargetIdentifier.value
val updateReport = Keys.updateClassifiers.value val updateReport = Keys.updateClassifiers.value
val sources = for { val sources = for {
configuration <- updateReport.configurations.view configuration <- updateReport.configurations.view