Skip to content

Commit af528a1

Browse files
authored
Merge pull request #3255 from dotty-staging/exclude-from-ide
sbt-dotty: Add a setting to exclude a configuration from the Dotty IDE, and exclude the optimized projects from the Dotty build
2 parents c50c164 + 1c6c5c6 commit af528a1

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

project/Build.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,15 @@ object Build {
228228

229229

230230
// Bootstrap with -optimise
231-
lazy val commonOptimisedSettings = commonBootstrappedSettings ++ Seq(scalacOptions ++= Seq("-optimise"))
231+
lazy val commonOptimisedSettings = commonBootstrappedSettings ++ Seq(
232+
scalacOptions ++= Seq("-optimise"),
233+
234+
// The *-bootstrapped and *-optimised projects contain the same sources, so
235+
// we only need to import one set in the IDE. We prefer to import the
236+
// non-optimized projects because optimize is slower to compile and we do
237+
// not trust its output yet.
238+
excludeFromIDE := true
239+
)
232240

233241
lazy val commonBenchmarkSettings = Seq(
234242
mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench"), // custom main for jmh:run

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import scala.collection.mutable.ListBuffer
1515
import DottyPlugin.autoImport._
1616

1717
object DottyIDEPlugin extends AutoPlugin {
18+
object autoImport {
19+
val excludeFromIDE = settingKey[Boolean]("If true, do not import this project or configuration in the Dotty IDE")
20+
21+
val codeCommand = taskKey[Seq[String]]("Command to start VSCode")
22+
val runCode = taskKey[Unit]("Start VSCode, usually called from launchIDE")
23+
val launchIDE = taskKey[Unit]("Configure and run VSCode on this project")
24+
}
25+
26+
import autoImport._
27+
1828
// Adapted from scala-reflect
1929
private def distinctBy[A, B](xs: Seq[A])(f: A => B): Seq[A] = {
2030
val buf = new mutable.ListBuffer[A]
@@ -111,14 +121,20 @@ object DottyIDEPlugin extends AutoPlugin {
111121
}
112122
}
113123

114-
/** Run task `key` in all configurations in all projects in `projRefs`, using state `state` */
115-
private def runInAllConfigurations[T](key: TaskKey[T], projRefs: Seq[ProjectRef], state: State): Seq[T] = {
124+
/** Run task `key` in all configurations in all projects in `projRefs`, using state `state`,
125+
* configurations where `excludeFromIDE` is `true` are skipped. */
126+
private def runInAllIDEConfigurations[T](key: TaskKey[T], projRefs: Seq[ProjectRef], state: State): Seq[T] = {
116127
val structure = Project.structure(state)
117128
val settings = structure.data
118129
val joinedTask = projRefs.flatMap { projRef =>
119130
val project = Project.getProjectForReference(projRef, structure).get
120131
project.configurations.flatMap { config =>
121-
key.in(projRef, config).get(settings)
132+
excludeFromIDE.in(projRef, config).get(settings) match {
133+
case Some(true) =>
134+
None // skip this configuration
135+
case _ =>
136+
key.in(projRef, config).get(settings)
137+
}
122138
}
123139
}.join
124140

@@ -151,20 +167,12 @@ object DottyIDEPlugin extends AutoPlugin {
151167

152168
private val projectConfig = taskKey[Option[ProjectConfig]]("")
153169

154-
object autoImport {
155-
val codeCommand = taskKey[Seq[String]]("Command to start VSCode")
156-
val runCode = taskKey[Unit]("Start VSCode, usually called from launchIDE")
157-
val launchIDE = taskKey[Unit]("Configure and run VSCode on this project")
158-
}
159-
160-
import autoImport._
161-
162170
override def requires: Plugins = plugins.JvmPlugin
163171
override def trigger = allRequirements
164172

165173
def configureIDE = Command.command("configureIDE") { origState =>
166174
val (dottyVersion, projRefs, dottyState) = dottySetup(origState)
167-
val configs0 = runInAllConfigurations(projectConfig, projRefs, dottyState).flatten
175+
val configs0 = runInAllIDEConfigurations(projectConfig, projRefs, dottyState).flatten
168176

169177
// Drop configurations that do not define their own sources, but just
170178
// inherit their sources from some other configuration.
@@ -192,7 +200,7 @@ object DottyIDEPlugin extends AutoPlugin {
192200

193201
def compileForIDE = Command.command("compileForIDE") { origState =>
194202
val (dottyVersion, projRefs, dottyState) = dottySetup(origState)
195-
runInAllConfigurations(compile, projRefs, dottyState)
203+
runInAllIDEConfigurations(compile, projRefs, dottyState)
196204

197205
origState
198206
}
@@ -234,6 +242,8 @@ object DottyIDEPlugin extends AutoPlugin {
234242
override def buildSettings: Seq[Setting[_]] = Seq(
235243
commands ++= Seq(configureIDE, compileForIDE),
236244

245+
excludeFromIDE := false,
246+
237247
codeCommand := {
238248
Seq("code", "-n")
239249
},

0 commit comments

Comments
 (0)