Skip to content

Commit ea5fcc4

Browse files
committed
Use InputsComposer in Bsp
1 parent 0092651 commit ea5fcc4

File tree

12 files changed

+296
-212
lines changed

12 files changed

+296
-212
lines changed

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,8 @@ object Build {
10201020
resourceDirs = sources.resourceDirs,
10211021
scope = scope,
10221022
javaHomeOpt = Option(options.javaHomeLocation().value),
1023-
javacOptions = javacOptions
1023+
javacOptions = javacOptions,
1024+
moduleDependencies = inputs.moduleDependencies
10241025
)
10251026
project
10261027
}

modules/build/src/main/scala/scala/build/Project.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ final case class Project(
2929
resourceDirs: Seq[os.Path],
3030
javaHomeOpt: Option[os.Path],
3131
scope: Scope,
32-
javacOptions: List[String]
32+
javacOptions: List[String],
33+
moduleDependencies: Seq[ProjectName]
3334
) {
3435

3536
import Project._
@@ -66,7 +67,8 @@ final case class Project(
6667
platform = Some(platform),
6768
`scala` = scalaConfigOpt,
6869
java = Some(BloopConfig.Java(javacOptions)),
69-
resolution = resolution
70+
resolution = resolution,
71+
dependencies = moduleDependencies.map(_.name).toList
7072
)
7173
}
7274

modules/build/src/main/scala/scala/build/bsp/BloopSession.scala

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,33 @@ import scala.build.compiler.BloopCompiler
99
import scala.build.input.{ModuleInputs, OnDisk, SingleFile, Virtual}
1010

1111
final class BloopSession(
12-
val inputs: ModuleInputs,
13-
val inputsHash: String,
12+
val inputs: Seq[ModuleInputs],
13+
// val inputsHash: String, TODO Fix inputs hash comparing
1414
val remoteServer: BloopCompiler,
1515
val bspServer: BspServer,
1616
val watcher: Build.Watcher
1717
) {
1818
// TODO this resets diagnostics using paths that do not belong to the build targets
19-
def resetDiagnostics(localClient: BspClient): Unit =
20-
for (targetId <- bspServer.targetIds)
21-
inputs.flattened().foreach {
22-
case f: SingleFile =>
23-
localClient.resetDiagnostics(f.path, targetId)
24-
case _: Virtual =>
25-
}
19+
def resetDiagnostics(localClient: BspClient): Unit = for {
20+
moduleInputs <- inputs
21+
targetId <- bspServer.targetProjectIdOpt(moduleInputs.projectName)
22+
} do
23+
moduleInputs.flattened().foreach {
24+
case f: SingleFile =>
25+
localClient.resetDiagnostics(f.path, targetId)
26+
case _: Virtual =>
27+
}
28+
2629
def dispose(): Unit = {
2730
watcher.dispose()
2831
remoteServer.shutdown()
2932
}
3033

31-
def registerWatchInputs(): Unit =
32-
inputs.elements.foreach {
34+
def registerWatchInputs(): Unit = for {
35+
module <- inputs
36+
element <- module.elements
37+
} do
38+
element match {
3339
case elem: OnDisk =>
3440
val eventFilter: PathWatchers.Event => Boolean = { event =>
3541
val newOrDeletedFile =
@@ -38,8 +44,11 @@ final class BloopSession(
3844
lazy val p = os.Path(event.getTypedPath.getPath.toAbsolutePath)
3945
lazy val relPath = p.relativeTo(elem.path)
4046
lazy val isHidden = relPath.segments.exists(_.startsWith("."))
41-
def isScalaFile = relPath.last.endsWith(".sc") || relPath.last.endsWith(".scala")
42-
def isJavaFile = relPath.last.endsWith(".java")
47+
48+
def isScalaFile = relPath.last.endsWith(".sc") || relPath.last.endsWith(".scala")
49+
50+
def isJavaFile = relPath.last.endsWith(".java")
51+
4352
newOrDeletedFile && !isHidden && (isScalaFile || isJavaFile)
4453
}
4554
val watcher0 = watcher.newWatcher()
@@ -57,11 +66,11 @@ final class BloopSession(
5766
object BloopSession {
5867

5968
def apply(
60-
inputs: ModuleInputs,
69+
inputs: Seq[ModuleInputs],
6170
remoteServer: BloopCompiler,
6271
bspServer: BspServer,
6372
watcher: Build.Watcher
64-
): BloopSession = new BloopSession(inputs, inputs.sourceHash(), remoteServer, bspServer, watcher)
73+
): BloopSession = new BloopSession(inputs, remoteServer, bspServer, watcher)
6574

6675
final class Reference {
6776
private val ref = new AtomicReference[BloopSession](null)

modules/build/src/main/scala/scala/build/bsp/Bsp.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import scala.build.input.{ModuleInputs, ScalaCliInvokeData}
77
import scala.concurrent.Future
88

99
trait Bsp {
10-
def run(initialInputs: ModuleInputs, initialBspOptions: BspReloadableOptions): Future[Unit]
10+
def run(initialInputs: Seq[ModuleInputs], initialBspOptions: BspReloadableOptions): Future[Unit]
1111
def shutdown(): Unit
1212
}
1313

1414
object Bsp {
1515
def create(
16-
argsToInputs: Seq[String] => Either[BuildException, ModuleInputs],
16+
argsToInputs: Seq[String] => Either[BuildException, Seq[ModuleInputs]],
1717
bspReloadableOptionsReference: BspReloadableOptions.Reference,
1818
threads: BspThreads,
1919
in: InputStream,

0 commit comments

Comments
 (0)