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