-
Notifications
You must be signed in to change notification settings - Fork 950
Bsp build target resources #6552
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 build target resources #6552
Conversation
2109ff9
to
e3edd09
Compare
main/src/main/scala/sbt/internal/server/BuildServerProtocol.scala
Outdated
Show resolved
Hide resolved
I created an example project to show that in some case, the build client lacks some information about the resource file. The build file is: val hello = project.in(file("."))
.settings(
scalaVersion := "2.13.6",
Compile / resourceGenerators += Def.task {
val greeting = (Compile / resourceManaged).value / "assets" / "greeting.txt"
IO.write(greeting, "Hello, World!")
Seq(greeting)
}
) This generates a The main method read the content of that resource and prints it: package hello
import scala.io.Source
object Main extends App {
Source.fromResource("assets/greeting.txt", getClass.getClassLoader)
.getLines()
.foreach(println)
} Note that the resource is Running the main to check that it works as expected:
When importing the project in IntelliJ the {
"items": [
{
"target": {
"uri": "file:/home/piquerez/sbt/sbt-6552/#hello/Test"
},
"resources": [
"file:/home/piquerez/sbt/sbt-6552/src/test/resources"
]
},
{
"target": {
"uri": "file:/home/piquerez/sbt/sbt-6552/#hello/Compile"
},
"resources": [
"file:/home/piquerez/sbt/sbt-6552/src/main/resources",
"file:/home/piquerez/sbt/sbt-6552/target/scala-2.13/resource_managed/main/assets/greeting.txt"
]
}
]
} Here Intellij does not know that the resource file is supposed to be Here IntelliJ assumes that the resource folder is Reproduction repo: https://github.com/adpi2/sbt-6552 |
I think the solution for now is to send back the managed resource folders rather than the managed resource files: val id = bspTargetIdentifier.value
val unmanagedDirs = unmanagedResourceDirectories.value
val managedDirs = managedResourceDirectories.value
ResourcesItem(id, unmanagedDirs.toVector.map(_.toURI) ++ managedDirs.toVector.map(_.toURI)) Or more simply val id = bspTargetIdentifier.value
val resourcDirs = resourceDirectories.value
ResourcesItem(id, resourcDirs.toVector.map(_.toURI)) One drawback of this solution is that it does not trigger the resource generation (of the managed resources). We can handle that with: val id = bspTargetIdentifier.value
val resourcDirs = resourceDirectories.value
// trigger resource generation
val _ = managedResources.value
ResourcesItem(id, resourcDirs.toVector.map(_.toURI)) |
You're right, the main problem comes from the lack of resources kind, like we have with sources I also tried with BSP importing a project with a I think it comes from BspResolverLogic that creates either a resource from a file or its own parent Edit : I pushed a modification that adds an extra ending slash when missing on resource directories URIs. |
cadacca
to
f3ec202
Compare
Thanks for the contribution. I'll trust @adpi2's review and hit merge since it's been approved. |
Fixes #6550
This PR adds an implementation for BSP resource request
When sending the following command to
sbt -bsp
:We should now get the following response :