@@ -10,12 +10,19 @@ import org.eclipse.lsp4j.jsonrpc.messages.ResponseError
1010import java .io .{InputStream , OutputStream }
1111import java .util .UUID
1212import java .util .concurrent .{CompletableFuture , Executor }
13+
1314import scala .build .EitherCps .{either , value }
1415import scala .build .*
1516import scala .build .bsp .buildtargets .{ManagesBuildTargets , ProjectName }
1617import scala .build .compiler .BloopCompiler
17- import scala .build .compose .Inputs
18- import scala .build .errors .{BuildException , CompositeBuildException , Diagnostic , ParsingInputsException }
18+ import scala .build .compose .{ComposeBuild , Inputs }
19+ import scala .build .errors .{
20+ BuildException ,
21+ CompositeBuildException ,
22+ Diagnostic ,
23+ ParsingInputsException
24+ }
25+ import scala .build .input .{Module , ScalaCliInvokeData }
1926import scala .build .internal .Constants
2027import scala .build .options .{BuildOptions , Scope }
2128import scala .collection .mutable .ListBuffer
@@ -38,12 +45,12 @@ import scala.util.{Failure, Success}
3845 * the output stream of bytes
3946 */
4047final class BspImpl (
41- argsToInputs : Seq [String ] => Either [BuildException , Inputs ],
42- bspReloadableOptionsReference : BspReloadableOptions .Reference ,
43- threads : BspThreads ,
44- in : InputStream ,
45- out : OutputStream ,
46- actionableDiagnostics : Option [Boolean ]
48+ argsToInputs : Seq [String ] => Either [BuildException , Inputs ],
49+ bspReloadableOptionsReference : BspReloadableOptions .Reference ,
50+ threads : BspThreads ,
51+ in : InputStream ,
52+ out : OutputStream ,
53+ actionableDiagnostics : Option [Boolean ]
4754)(using ScalaCliInvokeData ) extends Bsp {
4855
4956 import BspImpl .{
@@ -92,142 +99,18 @@ final class BspImpl(
9299 currentBloopSession : BloopSession ,
93100 reloadableOptions : BspReloadableOptions ,
94101 maybeRecoverOnError : ProjectName => BuildException => Option [BuildException ] = _ => e => Some (e)
95- ): Either [(BuildException , ProjectName ), PreBuildProject ] =
96- either[(BuildException , ProjectName )] {
97- val logger = reloadableOptions.logger
98- val buildOptions = reloadableOptions.buildOptions
99- val verbosity = reloadableOptions.verbosity
100- logger.log(" Preparing build" )
101-
102- val persistentLogger = new PersistentDiagnosticLogger (logger)
103- val bspServer = currentBloopSession.bspServer
104-
105- val prebuildModules = for (module <- currentBloopSession.inputs.modulesBuildOrder) yield {
106- val mainProjectName = module.projectName
107- val testProjectName = module.scopeProjectName(Scope .Test )
108-
109- // allInputs contains elements from using directives
110- val (crossSources, allInputs) = value {
111- CrossSources .forModuleInputs(
112- inputs = module,
113- preprocessors = Sources .defaultPreprocessors(
114- buildOptions.archiveCache,
115- buildOptions.internal.javaClassNameVersionOpt,
116- () => buildOptions.javaHome().value.javaCommand
117- ),
118- logger = persistentLogger,
119- suppressWarningOptions = buildOptions.suppressWarningOptions,
120- exclude = buildOptions.internal.exclude,
121- maybeRecoverOnError = maybeRecoverOnError(mainProjectName)
122- ).left.map(_ -> mainProjectName)
123- }
124-
125- val sharedOptions = crossSources.sharedOptions(buildOptions)
126-
127- if (verbosity >= 3 )
128- pprint.err.log(crossSources)
129-
130- val scopedSources =
131- value(crossSources.scopedSources(buildOptions).left.map(_ -> mainProjectName))
132-
133- if (verbosity >= 3 )
134- pprint.err.log(scopedSources)
135-
136- val sourcesMain = value {
137- scopedSources.sources(Scope .Main , sharedOptions, allInputs.workspace, persistentLogger)
138- .left.map(_ -> mainProjectName)
139- }
140-
141- val sourcesTest = value {
142- scopedSources.sources(Scope .Test , sharedOptions, allInputs.workspace, persistentLogger)
143- .left.map(_ -> testProjectName)
144- }
145-
146- if (verbosity >= 3 )
147- pprint.err.log(sourcesMain)
148-
149- val options0Main = sourcesMain.buildOptions
150- val options0Test = sourcesTest.buildOptions.orElse(options0Main)
151-
152- val generatedSourcesMain =
153- sourcesMain.generateSources(allInputs.generatedSrcRoot(Scope .Main ))
154- val generatedSourcesTest =
155- sourcesTest.generateSources(allInputs.generatedSrcRoot(Scope .Test ))
156-
157- bspServer.setExtraDependencySources(options0Main.classPathOptions.extraSourceJars)
158- bspServer.setExtraTestDependencySources(options0Test.classPathOptions.extraSourceJars)
159- bspServer.setGeneratedSources(mainProjectName, generatedSourcesMain)
160- bspServer.setGeneratedSources(testProjectName, generatedSourcesTest)
161-
162- val (classesDir0Main, scalaParamsMain, artifactsMain, projectMain, buildChangedMain) =
163- value {
164- val res = Build .prepareBuild(
165- allInputs,
166- sourcesMain,
167- generatedSourcesMain,
168- options0Main,
169- None ,
170- Scope .Main ,
171- currentBloopSession.remoteServer,
172- persistentLogger,
173- localClient,
174- maybeRecoverOnError(mainProjectName)
175- )
176- res.left.map(_ -> mainProjectName)
177- }
178-
179- val (classesDir0Test, scalaParamsTest, artifactsTest, projectTest, buildChangedTest) =
180- value {
181- val res = Build .prepareBuild(
182- allInputs,
183- sourcesTest,
184- generatedSourcesTest,
185- options0Test,
186- None ,
187- Scope .Test ,
188- currentBloopSession.remoteServer,
189- persistentLogger,
190- localClient,
191- maybeRecoverOnError(testProjectName)
192- )
193- res.left.map(_ -> testProjectName)
194- }
195-
196- localClient.setGeneratedSources(mainProjectName, generatedSourcesMain)
197- localClient.setGeneratedSources(testProjectName, generatedSourcesTest)
198-
199- val mainScope = PreBuildData (
200- sourcesMain,
201- options0Main,
202- classesDir0Main,
203- scalaParamsMain,
204- artifactsMain,
205- projectMain,
206- generatedSourcesMain,
207- buildChangedMain
208- )
209-
210- val testScope = PreBuildData (
211- sourcesTest,
212- options0Test,
213- classesDir0Test,
214- scalaParamsTest,
215- artifactsTest,
216- projectTest,
217- generatedSourcesTest,
218- buildChangedTest
219- )
220-
221- if (actionableDiagnostics.getOrElse(true )) {
222- val projectOptions = options0Test.orElse(options0Main)
223- projectOptions.logActionableDiagnostics(persistentLogger)
224- }
225-
226- PreBuildModule (module, mainScope, testScope, persistentLogger.diagnostics)
227- }
228-
229- PreBuildProject (prebuildModules)
230- }
102+ ): Either [(BuildException , ProjectName ), ComposeBuild .PreBuildProject ] =
103+ ComposeBuild (
104+ buildOptions = reloadableOptions.buildOptions,
105+ inputs = currentBloopSession.inputs,
106+ logger = reloadableOptions.logger,
107+ compiler = currentBloopSession.remoteServer,
108+ buildClient = localClient,
109+ bspServer = Some (currentBloopSession.bspServer),
110+ actionableDiagnostics = actionableDiagnostics,
111+ verbosity = reloadableOptions.verbosity,
112+ maybeRecoverOnError = maybeRecoverOnError
113+ ).prepareBuild()
231114
232115 private def buildE (
233116 currentBloopSession : BloopSession ,
@@ -236,7 +119,7 @@ final class BspImpl(
236119 ): Either [(BuildException , ProjectName ), Unit ] = {
237120 def doBuildOnce (
238121 moduleInputs : Module ,
239- data : PreBuildData ,
122+ data : ComposeBuild . PreBuildData ,
240123 scope : Scope
241124 ): Either [(BuildException , ProjectName ), Build ] =
242125 Build .buildOnce(
@@ -254,7 +137,7 @@ final class BspImpl(
254137 either[(BuildException , ProjectName )] {
255138 val preBuild = value(prepareBuild(currentBloopSession, reloadableOptions))
256139 for (preBuildModule <- preBuild.prebuildModules) do {
257- val moduleInputs = preBuildModule.inputs
140+ val moduleInputs = preBuildModule.module
258141 // TODO notify only specific build target
259142 if (
260143 notifyChanges && (preBuildModule.mainScope.buildChanged || preBuildModule.testScope.buildChanged)
@@ -327,22 +210,7 @@ final class BspImpl(
327210 executor
328211 )
329212
330- preBuild.thenCompose { x =>
331- Thread .sleep(1000 )
332- x.foreach{ r =>
333- r.prebuildModules.foreach{ m =>
334- pprint.err.log(m.mainScope.project.projectName)
335- m.mainScope.sources.paths.foreach(path => pprint.err.log(os.read(path._1)))
336- m.mainScope.project.classPath.foreach(p => pprint.err.log(p.toString))
337- }
338- r.prebuildModules.foreach { m =>
339- pprint.err.log(m.testScope.project.projectName)
340- m.testScope.sources.paths.foreach(path => pprint.err.log(os.read(path._1)))
341- m.testScope.project.classPath.foreach(p => pprint.err.log(p.toString))
342- }
343- }
344- CompletableFuture .supplyAsync(() => x, executor)
345- }.thenCompose {
213+ preBuild.thenCompose {
346214 case Left ((ex, projectName)) =>
347215 val taskId = new b.TaskId (UUID .randomUUID().toString)
348216
@@ -379,14 +247,13 @@ final class BspImpl(
379247 new b.CompileResult (b.StatusCode .ERROR )
380248 )
381249 case Right (params) =>
382- println(params)
383250 for (targetId <- currentBloopSession.bspServer.targetIds)
384251 actualLocalClient.resetBuildExceptionDiagnostics(targetId)
385252
386253 for {
387254 preBuildModule <- params.prebuildModules
388255 targetId <- currentBloopSession.bspServer
389- .targetProjectIdOpt(preBuildModule.inputs .projectName)
256+ .targetProjectIdOpt(preBuildModule.module .projectName)
390257 .toSeq
391258 } do
392259 actualLocalClient.reportDiagnosticsForFiles(
@@ -396,7 +263,7 @@ final class BspImpl(
396263 )
397264
398265 doCompile().thenCompose { res =>
399- def doPostProcess (inputs : Module , data : PreBuildData , scope : Scope ): Unit =
266+ def doPostProcess (inputs : Module , data : ComposeBuild . PreBuildData , scope : Scope ): Unit =
400267 for (sv <- data.project.scalaCompiler.map(_.scalaVersion))
401268 Build .postProcess(
402269 data.generatedSources,
@@ -413,7 +280,7 @@ final class BspImpl(
413280 CompletableFuture .supplyAsync(
414281 () => {
415282 for (preBuildModule <- params.prebuildModules) do {
416- val moduleInputs = preBuildModule.inputs
283+ val moduleInputs = preBuildModule.module
417284 doPostProcess(moduleInputs, preBuildModule.mainScope, Scope .Main )
418285 doPostProcess(moduleInputs, preBuildModule.testScope, Scope .Test )
419286 }
@@ -451,9 +318,9 @@ final class BspImpl(
451318 * a new [[BloopSession ]]
452319 */
453320 private def newBloopSession (
454- inputs : Inputs ,
455- reloadableOptions : BspReloadableOptions ,
456- presetIntelliJ : Boolean = false
321+ inputs : Inputs ,
322+ reloadableOptions : BspReloadableOptions ,
323+ presetIntelliJ : Boolean = false
457324 ): BloopSession = {
458325 val logger = reloadableOptions.logger
459326 val buildOptions = reloadableOptions.buildOptions
@@ -504,8 +371,8 @@ final class BspImpl(
504371 * change on subsequent workspace/reload requests)
505372 */
506373 override def run (
507- initialInputs : Inputs ,
508- initialBspOptions : BspReloadableOptions
374+ initialInputs : Inputs ,
375+ initialBspOptions : BspReloadableOptions
509376 ): Future [Unit ] = {
510377 val logger = initialBspOptions.logger
511378 val verbosity = initialBspOptions.verbosity
@@ -607,10 +474,10 @@ final class BspImpl(
607474 * a future containing a valid workspace/reload response
608475 */
609476 private def reloadBsp (
610- currentBloopSession : BloopSession ,
611- previousInputs : Inputs ,
612- newInputs : Inputs ,
613- reloadableOptions : BspReloadableOptions
477+ currentBloopSession : BloopSession ,
478+ previousInputs : Inputs ,
479+ newInputs : Inputs ,
480+ reloadableOptions : BspReloadableOptions
614481 ): CompletableFuture [AnyRef ] = {
615482 val previousTargetIds = currentBloopSession.bspServer.targetIds
616483 val wasIntelliJ = currentBloopSession.bspServer.isIntelliJ
0 commit comments