Skip to content

Commit cfa358b

Browse files
committed
Implement :settings in the REPL
1 parent e3586bf commit cfa358b

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object MacroClassLoader {
2323
private def makeMacroClassLoader(using Context): ClassLoader = trace("new macro class loader") {
2424
val entries = ClassPath.expandPath(ctx.settings.classpath.value, expandStar=true)
2525
val urls = entries.map(cp => java.nio.file.Paths.get(cp).toUri.toURL).toArray
26-
val out = ctx.settings.outputDir.value.jpath.toUri.toURL // to find classes in case of suspended compilation
27-
new java.net.URLClassLoader(urls :+ out, getClass.getClassLoader)
26+
val out = Option(ctx.settings.outputDir.value.toURL) // to find classes in case of suspended compilation
27+
new java.net.URLClassLoader(urls ++ out.toList, getClass.getClassLoader)
2828
}
2929
}

compiler/src/dotty/tools/repl/ParseResult.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ case object Imports extends Command {
8080
val command: String = ":imports"
8181
}
8282

83+
case class Settings(arg: String) extends Command
84+
object Settings {
85+
val command: String = ":settings"
86+
}
87+
8388
/** Reset the session to the initial state from when the repl program was
8489
* started
8590
*/
@@ -128,7 +133,8 @@ object ParseResult {
128133
Imports.command -> (_ => Imports),
129134
Load.command -> (arg => Load(arg)),
130135
TypeOf.command -> (arg => TypeOf(arg)),
131-
DocOf.command -> (arg => DocOf(arg))
136+
DocOf.command -> (arg => DocOf(arg)),
137+
Settings.command -> (arg => Settings(arg)),
132138
)
133139

134140
def apply(source: SourceFile)(implicit state: State): ParseResult = {

compiler/src/dotty/tools/repl/ReplDriver.scala

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets
55

66
import dotty.tools.dotc.ast.Trees._
77
import dotty.tools.dotc.ast.{tpd, untpd}
8+
import dotty.tools.dotc.config.CommandLineParser.tokenize
89
import dotty.tools.dotc.config.Properties.{javaVersion, javaVmName, simpleVersionString}
910
import dotty.tools.dotc.core.Contexts._
1011
import dotty.tools.dotc.core.Phases.{unfusedPhases, typerPhase}
@@ -414,6 +415,20 @@ class ReplDriver(settings: Array[String],
414415
}
415416
state
416417

418+
case Settings(arg) => arg match
419+
case "" =>
420+
given ctx: Context = state.context
421+
for (s <- ctx.settings.userSetSettings(ctx.settingsState).sortBy(_.name))
422+
out.println(s"${s.name} = ${if s.value == "" then "\"\"" else s.value}")
423+
state
424+
case _ =>
425+
setup(tokenize(arg).toArray, rootCtx) match
426+
case Some((files, ictx)) =>
427+
ictx.base.initialize()(using ictx)
428+
rootCtx = ictx
429+
case _ =>
430+
state.copy(context = rootCtx)
431+
417432
case Quit =>
418433
// end of the world!
419434
state
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
scala> def f(thread: Thread) = thread.stop()
2+
there were 1 deprecation warning(s); re-run with -deprecation for details
3+
def f(thread: Thread): Unit
4+
5+
scala>:settings -deprecation
6+
7+
scala> def f(thread: Thread) = thread.stop()
8+
1 warning found
9+
-- Deprecation Warning: --------------------------------------------------------
10+
1 | def f(thread: Thread) = thread.stop()
11+
| ^^^^^^^^^^^
12+
|method stop in class Thread is deprecated since : see corresponding Javadoc for more information.
13+
def f(thread: Thread): Unit
14+
15+
scala>

0 commit comments

Comments
 (0)