@@ -124,19 +124,51 @@ object DottyIDEPlugin extends AutoPlugin {
124124 }
125125
126126 private val projectConfig = taskKey[Option [ProjectConfig ]](" " )
127- private val compileForIDE = taskKey[Unit ](" Compile all projects supported by the IDE" )
128- private val runCode = taskKey[Unit ](" " )
129127
130128 object autoImport {
131- val configureIDE = taskKey[Unit ](" Generate IDE config files " )
132- val launchIDE = taskKey[Unit ](" Run Visual Studio Code on this project" )
129+ val runCode = taskKey[Unit ](" Start VSCode, usually called from launchIDE " )
130+ val launchIDE = taskKey[Unit ](" Configure and run VSCode on this project" )
133131 }
134132
135133 import autoImport ._
136134
137135 override def requires : Plugins = plugins.JvmPlugin
138136 override def trigger = allRequirements
139137
138+ def configureIDE = Command .command(" configureIDE" ) { origState =>
139+ val (dottyVersion, projRefs, dottyState) = dottySetup(origState)
140+ val configs0 = runInAllConfigurations(projectConfig, projRefs, dottyState).flatten
141+
142+ // Drop configurations that do not define their own sources, but just
143+ // inherit their sources from some other configuration.
144+ val configs = distinctBy(configs0)(_.sourceDirectories.deep)
145+
146+ // Write the version of the Dotty Language Server to use in a file by itself.
147+ // This could be a field in the JSON config file, but that would require all
148+ // IDE plugins to parse JSON.
149+ val dlsVersion = dottyVersion
150+ .replace(" -nonbootstrapped" , " " ) // The language server is only published bootstrapped
151+ val dlsBinaryVersion = dlsVersion.split(" \\ ." ).take(2 ).mkString(" ." )
152+ val pwArtifact = new PrintWriter (" .dotty-ide-artifact" )
153+ try {
154+ pwArtifact.println(s " ch.epfl.lamp:dotty-language-server_ ${dlsBinaryVersion}: ${dlsVersion}" )
155+ } finally {
156+ pwArtifact.close()
157+ }
158+
159+ val mapper = new ObjectMapper
160+ mapper.writerWithDefaultPrettyPrinter()
161+ .writeValue(new File (" .dotty-ide.json" ), configs.toArray)
162+
163+ origState
164+ }
165+
166+ def compileForIDE = Command .command(" compileForIDE" ) { origState =>
167+ val (dottyVersion, projRefs, dottyState) = dottySetup(origState)
168+ runInAllConfigurations(compile, projRefs, dottyState)
169+
170+ origState
171+ }
140172
141173 override def projectSettings : Seq [Setting [_]] = Seq (
142174 // Use Def.derive so `projectConfig` is only defined in the configurations where the
@@ -169,43 +201,7 @@ object DottyIDEPlugin extends AutoPlugin {
169201 )
170202
171203 override def buildSettings : Seq [Setting [_]] = Seq (
172- configureIDE := Def .taskDyn {
173- val origState = state.value
174- Def .task {
175- val (dottyVersion, projRefs, dottyState) = dottySetup(origState)
176- val configs0 = runInAllConfigurations(projectConfig, projRefs, dottyState).flatten
177-
178- // Drop configurations that do not define their own sources, but just
179- // inherit their sources from some other configuration.
180- val configs = distinctBy(configs0)(_.sourceDirectories.deep)
181-
182- // Write the version of the Dotty Language Server to use in a file by itself.
183- // This could be a field in the JSON config file, but that would require all
184- // IDE plugins to parse JSON.
185- val dlsVersion = dottyVersion
186- .replace(" -nonbootstrapped" , " " ) // The language server is only published bootstrapped
187- val dlsBinaryVersion = dlsVersion.split(" \\ ." ).take(2 ).mkString(" ." )
188- val pwArtifact = new PrintWriter (" .dotty-ide-artifact" )
189- try {
190- pwArtifact.println(s " ch.epfl.lamp:dotty-language-server_ ${dlsBinaryVersion}: ${dlsVersion}" )
191- } finally {
192- pwArtifact.close()
193- }
194-
195- val mapper = new ObjectMapper
196- mapper.writerWithDefaultPrettyPrinter()
197- .writeValue(new File (" .dotty-ide.json" ), configs.toArray)
198- }
199- }.value,
200-
201- compileForIDE := Def .taskDyn {
202- val origState = state.value
203- Def .task {
204- val (dottyVersion, projRefs, dottyState) = dottySetup(origState)
205- runInAllConfigurations(compile, projRefs, dottyState)
206- ()
207- }
208- }.value,
204+ commands ++= Seq (configureIDE, compileForIDE),
209205
210206 runCode := {
211207 val exitCode = new ProcessBuilder (" code" , " --install-extension" , " lampepfl.dotty" )
@@ -218,8 +214,7 @@ object DottyIDEPlugin extends AutoPlugin {
218214 new ProcessBuilder (" code" , baseDirectory.value.getAbsolutePath)
219215 .inheritIO()
220216 .start()
221- },
222-
223- launchIDE := runCode.dependsOn(configureIDE).value
224- )
217+ }
218+
219+ ) ++ addCommandAlias(" launchIDE" , " ;configureIDE;runCode" )
225220}
0 commit comments