Skip to content

Commit c0c6b06

Browse files
committed
sbt launchIDE: launch even if there are compilation errors
...assuming that existing configuration files exist. Note that this won't work in the build of Dotty itself because `runCode` is overriden to run dotty-language-server, and this won't work if dotty-language-server's dependencies cannot be compiled.
1 parent 7a42360 commit c0c6b06

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ object DottyIDEPlugin extends AutoPlugin {
170170
override def requires: Plugins = plugins.JvmPlugin
171171
override def trigger = allRequirements
172172

173+
private val artifactFile = new File(".dotty-ide-artifact")
174+
private val configFile = new File(".dotty-ide.json")
175+
173176
def configureIDE = Command.command("configureIDE") { origState =>
174177
val (dottyVersion, projRefs, dottyState) = dottySetup(origState)
175178
val configs0 = runInAllIDEConfigurations(projectConfig, projRefs, dottyState).flatten
@@ -184,7 +187,7 @@ object DottyIDEPlugin extends AutoPlugin {
184187
val dlsVersion = dottyVersion
185188
.replace("-nonbootstrapped", "") // The language server is only published bootstrapped
186189
val dlsBinaryVersion = dlsVersion.split("\\.").take(2).mkString(".")
187-
val pwArtifact = new PrintWriter(".dotty-ide-artifact")
190+
val pwArtifact = new PrintWriter(artifactFile)
188191
try {
189192
pwArtifact.println(s"ch.epfl.lamp:dotty-language-server_${dlsBinaryVersion}:${dlsVersion}")
190193
} finally {
@@ -193,7 +196,7 @@ object DottyIDEPlugin extends AutoPlugin {
193196

194197
val mapper = new ObjectMapper
195198
mapper.writerWithDefaultPrettyPrinter()
196-
.writeValue(new File(".dotty-ide.json"), configs.toArray)
199+
.writeValue(configFile, configs.toArray)
197200

198201
origState
199202
}
@@ -205,6 +208,23 @@ object DottyIDEPlugin extends AutoPlugin {
205208
origState
206209
}
207210

211+
def launchIDE = Command.command("launchIDE") { state0 =>
212+
val state1 = try {
213+
Command.process("configureIDE", state0)
214+
} catch {
215+
case i: Incomplete =>
216+
if (artifactFile.exists && configFile.exists) {
217+
state0.log.error("IDE configuration failed, launching the IDE using the previous configuration")
218+
state0: State
219+
} else {
220+
state0.log.error("IDE configuration failed and no previous configuration found")
221+
state0.log.error("Please fix the compilation errors then run 'launchIDE' again")
222+
throw i
223+
}
224+
}
225+
Command.process("runCode", state1)
226+
}
227+
208228
private def projectConfigTask(config: Configuration): Initialize[Task[Option[ProjectConfig]]] = Def.taskDyn {
209229
if ((sources in config).value.isEmpty) Def.task { None }
210230
else Def.task {
@@ -240,7 +260,7 @@ object DottyIDEPlugin extends AutoPlugin {
240260
)
241261

242262
override def buildSettings: Seq[Setting[_]] = Seq(
243-
commands ++= Seq(configureIDE, compileForIDE),
263+
commands ++= Seq(configureIDE, compileForIDE, launchIDE),
244264

245265
excludeFromIDE := false,
246266

0 commit comments

Comments
 (0)