return build targets sources from `buildTarget/dependencySources` request #8403

This commit is contained in:
Aleksandra Zdrojowa 2025-12-14 13:35:25 +01:00
parent 9d62f5e940
commit 14f1839647
1 changed files with 23 additions and 4 deletions

View File

@ -26,7 +26,7 @@ import sbt.internal.protocol.JsonRpcRequestMessage
import sbt.internal.util.{ Attributed, ErrorHandling }
import sbt.internal.util.complete.{ Parser, Parsers }
import sbt.librarymanagement.CrossVersion.binaryScalaVersion
import sbt.librarymanagement.{ Configuration, ScalaArtifacts }
import sbt.librarymanagement.{ Configuration, ScalaArtifacts, UpdateReport }
import sbt.std.TaskExtra
import sbt.util.Logger
import sjsonnew.shaded.scalajson.ast.unsafe.{ JNull, JValue }
@ -158,7 +158,18 @@ object BuildServerProtocol {
import sbt.internal.bsp.codec.JsonProtocol._
val items = bspBuildTargetDependencySourcesItem.result.all(filter).value
val successfulItems = anyOrThrow(items)
val result = DependencySourcesResult(successfulItems.toVector)
val buildItems = workspace.builds
.map {
case (targetId, loadedBuildUnit) =>
val projRef = ProjectRef(loadedBuildUnit.unit.uri, loadedBuildUnit.root)
(projRef / updateSbtClassifiers).map(getDependencySourceItem(targetId, _))
}
.toSeq
.join
.value
val result = DependencySourcesResult((successfulItems ++ buildItems).toVector)
state.respondEvent(result)
}
}.evaluated,
@ -770,8 +781,16 @@ object BuildServerProtocol {
}
private def dependencySourcesItemTask: Def.Initialize[Task[DependencySourcesItem]] = Def.task {
val targetId = Keys.bspTargetIdentifier.value
val updateReport = Keys.updateClassifiers.value
getDependencySourceItem(
Keys.bspTargetIdentifier.value,
Keys.updateClassifiers.value
)
}
private def getDependencySourceItem(
targetId: BuildTargetIdentifier,
updateReport: UpdateReport
): DependencySourcesItem = {
val sources = for {
configuration <- updateReport.configurations.view
module <- configuration.modules.view