@@ -10,12 +10,19 @@ import org.eclipse.lsp4j.jsonrpc.messages.ResponseError
10
10
import java .io .{InputStream , OutputStream }
11
11
import java .util .UUID
12
12
import java .util .concurrent .{CompletableFuture , Executor }
13
+
13
14
import scala .build .EitherCps .{either , value }
14
15
import scala .build .*
15
16
import scala .build .bsp .buildtargets .{ManagesBuildTargets , ProjectName }
16
17
import 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 }
19
26
import scala .build .internal .Constants
20
27
import scala .build .options .{BuildOptions , Scope }
21
28
import scala .collection .mutable .ListBuffer
@@ -38,12 +45,12 @@ import scala.util.{Failure, Success}
38
45
* the output stream of bytes
39
46
*/
40
47
final 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 ]
47
54
)(using ScalaCliInvokeData ) extends Bsp {
48
55
49
56
import BspImpl .{
@@ -92,142 +99,18 @@ final class BspImpl(
92
99
currentBloopSession : BloopSession ,
93
100
reloadableOptions : BspReloadableOptions ,
94
101
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()
231
114
232
115
private def buildE (
233
116
currentBloopSession : BloopSession ,
@@ -236,7 +119,7 @@ final class BspImpl(
236
119
): Either [(BuildException , ProjectName ), Unit ] = {
237
120
def doBuildOnce (
238
121
moduleInputs : Module ,
239
- data : PreBuildData ,
122
+ data : ComposeBuild . PreBuildData ,
240
123
scope : Scope
241
124
): Either [(BuildException , ProjectName ), Build ] =
242
125
Build .buildOnce(
@@ -254,7 +137,7 @@ final class BspImpl(
254
137
either[(BuildException , ProjectName )] {
255
138
val preBuild = value(prepareBuild(currentBloopSession, reloadableOptions))
256
139
for (preBuildModule <- preBuild.prebuildModules) do {
257
- val moduleInputs = preBuildModule.inputs
140
+ val moduleInputs = preBuildModule.module
258
141
// TODO notify only specific build target
259
142
if (
260
143
notifyChanges && (preBuildModule.mainScope.buildChanged || preBuildModule.testScope.buildChanged)
@@ -327,22 +210,7 @@ final class BspImpl(
327
210
executor
328
211
)
329
212
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 {
346
214
case Left ((ex, projectName)) =>
347
215
val taskId = new b.TaskId (UUID .randomUUID().toString)
348
216
@@ -379,14 +247,13 @@ final class BspImpl(
379
247
new b.CompileResult (b.StatusCode .ERROR )
380
248
)
381
249
case Right (params) =>
382
- println(params)
383
250
for (targetId <- currentBloopSession.bspServer.targetIds)
384
251
actualLocalClient.resetBuildExceptionDiagnostics(targetId)
385
252
386
253
for {
387
254
preBuildModule <- params.prebuildModules
388
255
targetId <- currentBloopSession.bspServer
389
- .targetProjectIdOpt(preBuildModule.inputs .projectName)
256
+ .targetProjectIdOpt(preBuildModule.module .projectName)
390
257
.toSeq
391
258
} do
392
259
actualLocalClient.reportDiagnosticsForFiles(
@@ -396,7 +263,7 @@ final class BspImpl(
396
263
)
397
264
398
265
doCompile().thenCompose { res =>
399
- def doPostProcess (inputs : Module , data : PreBuildData , scope : Scope ): Unit =
266
+ def doPostProcess (inputs : Module , data : ComposeBuild . PreBuildData , scope : Scope ): Unit =
400
267
for (sv <- data.project.scalaCompiler.map(_.scalaVersion))
401
268
Build .postProcess(
402
269
data.generatedSources,
@@ -413,7 +280,7 @@ final class BspImpl(
413
280
CompletableFuture .supplyAsync(
414
281
() => {
415
282
for (preBuildModule <- params.prebuildModules) do {
416
- val moduleInputs = preBuildModule.inputs
283
+ val moduleInputs = preBuildModule.module
417
284
doPostProcess(moduleInputs, preBuildModule.mainScope, Scope .Main )
418
285
doPostProcess(moduleInputs, preBuildModule.testScope, Scope .Test )
419
286
}
@@ -451,9 +318,9 @@ final class BspImpl(
451
318
* a new [[BloopSession ]]
452
319
*/
453
320
private def newBloopSession (
454
- inputs : Inputs ,
455
- reloadableOptions : BspReloadableOptions ,
456
- presetIntelliJ : Boolean = false
321
+ inputs : Inputs ,
322
+ reloadableOptions : BspReloadableOptions ,
323
+ presetIntelliJ : Boolean = false
457
324
): BloopSession = {
458
325
val logger = reloadableOptions.logger
459
326
val buildOptions = reloadableOptions.buildOptions
@@ -504,8 +371,8 @@ final class BspImpl(
504
371
* change on subsequent workspace/reload requests)
505
372
*/
506
373
override def run (
507
- initialInputs : Inputs ,
508
- initialBspOptions : BspReloadableOptions
374
+ initialInputs : Inputs ,
375
+ initialBspOptions : BspReloadableOptions
509
376
): Future [Unit ] = {
510
377
val logger = initialBspOptions.logger
511
378
val verbosity = initialBspOptions.verbosity
@@ -607,10 +474,10 @@ final class BspImpl(
607
474
* a future containing a valid workspace/reload response
608
475
*/
609
476
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
614
481
): CompletableFuture [AnyRef ] = {
615
482
val previousTargetIds = currentBloopSession.bspServer.targetIds
616
483
val wasIntelliJ = currentBloopSession.bspServer.isIntelliJ
0 commit comments