@@ -7,12 +7,11 @@ import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
7
7
import com .google .gson .GsonBuilder
8
8
9
9
import java .nio .charset .{Charset , StandardCharsets }
10
-
11
10
import scala .build .EitherCps .{either , value }
12
11
import scala .build .*
13
12
import scala .build .bsp .IdeInputs
14
13
import scala .build .errors .{BuildException , WorkspaceError }
15
- import scala .build .input .{ModuleInputs , OnDisk , Virtual , WorkspaceOrigin }
14
+ import scala .build .input .{InputsComposer , ModuleInputs , OnDisk , Virtual , WorkspaceOrigin }
16
15
import scala .build .internal .Constants
17
16
import scala .build .internals .EnvVar
18
17
import scala .build .options .{BuildOptions , Scope }
@@ -68,12 +67,12 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
68
67
69
68
override def runCommand (options : SetupIdeOptions , args : RemainingArgs , logger : Logger ): Unit = {
70
69
val buildOptions = buildOptionsOrExit(options)
71
- val inputs = options.shared.inputs (args.all).orExit(logger)
72
- CurrentParams .workspaceOpt = Some (inputs .workspace)
70
+ val moduleInputs = options.shared.composeInputs (args.all).orExit(logger)
71
+ CurrentParams .workspaceOpt = Some (moduleInputs.head .workspace)
73
72
74
73
val bspPath = writeBspConfiguration(
75
74
options,
76
- inputs ,
75
+ moduleInputs ,
77
76
buildOptions,
78
77
previousCommandName = None ,
79
78
args = args.all
@@ -92,7 +91,7 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
92
91
): Unit =
93
92
writeBspConfiguration(
94
93
SetupIdeOptions (shared = options),
95
- inputs,
94
+ Seq ( inputs) ,
96
95
buildOptions,
97
96
previousCommandName,
98
97
args
@@ -106,13 +105,13 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
106
105
107
106
private def writeBspConfiguration (
108
107
options : SetupIdeOptions ,
109
- inputs : ModuleInputs ,
108
+ moduleInputs : Seq [ ModuleInputs ] ,
110
109
buildOptions : BuildOptions ,
111
110
previousCommandName : Option [String ],
112
111
args : Seq [String ]
113
112
): Either [BuildException , Option [os.Path ]] = either {
114
113
115
- val virtualInputs = inputs. elements.collect {
114
+ val virtualInputs = moduleInputs.flatMap(_. elements) .collect {
116
115
case v : Virtual => v
117
116
}
118
117
if (virtualInputs.nonEmpty)
@@ -125,23 +124,24 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
125
124
val logger = options.shared.logger
126
125
127
126
if (buildOptions.classPathOptions.allExtraDependencies.toSeq.nonEmpty)
128
- value(downloadDeps(
129
- inputs,
130
- buildOptions,
131
- logger
132
- ))
133
-
134
- val (bspName, bspJsonDestination) = bspDetails(inputs.workspace, options.bspFile)
135
- val scalaCliBspJsonDestination =
136
- inputs.workspace / Constants .workspaceDirName / " ide-options-v2.json"
137
- val scalaCliBspLauncherOptsJsonDestination =
138
- inputs.workspace / Constants .workspaceDirName / " ide-launcher-options.json"
139
- val scalaCliBspInputsJsonDestination =
140
- inputs.workspace / Constants .workspaceDirName / " ide-inputs.json"
141
- val scalaCliBspEnvsJsonDestination =
142
- inputs.workspace / Constants .workspaceDirName / " ide-envs.json"
143
-
144
- val inputArgs = inputs.elements.collect { case d : OnDisk => d.path.toString }
127
+ for (module <- moduleInputs) do value(downloadDeps(module, buildOptions, logger))
128
+
129
+ val workspace = moduleInputs.head.workspace
130
+
131
+ val (bspName, bspJsonDestination) = bspDetails(workspace, options.bspFile)
132
+ val scalaCliBspJsonDestination = workspace / Constants .workspaceDirName / " ide-options-v2.json"
133
+ val scalaCliBspLauncherOptsJsonDestination = workspace / Constants .workspaceDirName / " ide-launcher-options.json"
134
+ val scalaCliBspInputsJsonDestination = workspace / Constants .workspaceDirName / " ide-inputs.json"
135
+ val scalaCliBspEnvsJsonDestination = workspace / Constants .workspaceDirName / " ide-envs.json"
136
+
137
+ // FIXME single modules can also be defined with module config toml file
138
+ val inputArgs = if moduleInputs.size > 1 then
139
+ InputsComposer .findModuleConfig(args, Os .pwd)
140
+ .orExit(logger)
141
+ .fold(args)(p => Seq (p.toString))
142
+ else
143
+ moduleInputs.head.elements
144
+ .collect { case d : OnDisk => d.path.toString }
145
145
146
146
val ideInputs = IdeInputs (
147
147
options.shared.validateInputArgs(args)
@@ -189,7 +189,7 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
189
189
val envsForBsp = sys.env.filter((key, _) => EnvVar .allBsp.map(_.name).contains(key))
190
190
val scalaCliBspEnvsJson = writeToArray(envsForBsp)
191
191
192
- if (inputs .workspaceOrigin.contains(WorkspaceOrigin .HomeDir ))
192
+ if (moduleInputs.head .workspaceOrigin.contains(WorkspaceOrigin .HomeDir ))
193
193
value(Left (new WorkspaceError (
194
194
s """ $baseRunnerName can not determine where to write its BSP configuration.
195
195
|Set an explicit BSP directory path via `--bsp-directory`.
0 commit comments