Skip to content

Commit d3a0cc6

Browse files
committed
Make new REPL work with sbt bridge
1 parent 65a91e3 commit d3a0cc6

File tree

5 files changed

+26
-50
lines changed

5 files changed

+26
-50
lines changed

project/Build.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,13 @@ object Build {
517517
"com.novocode" % "junit-interface" % "0.11" % "test",
518518
"org.scala-lang" % "scala-library" % scalacVersion % "test"),
519519

520+
// Repl subproject shouldn't be distributed on its own yet, so the
521+
// sources need to be included in the dotty compiler to be available to
522+
// the sbt bridge
523+
unmanagedSourceDirectories in Compile += baseDirectory.value / ".." / "repl" / "src",
524+
unmanagedSourceDirectories in Test += baseDirectory.value / ".." / "repl" / "test",
525+
unmanagedResourceDirectories in Test += baseDirectory.value / ".." / "repl" / "test-resources",
526+
520527
// enable improved incremental compilation algorithm
521528
incOptions := incOptions.value.withNameHashing(true),
522529

repl/src/dotty/tools/repl/Rendering.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import dotc.core.StdNames.str
2020
* `ReplDriver#resetToInitial` is called, the accompanying instance of
2121
* `Rendering` is no longer valid.
2222
*/
23-
private[repl] class Rendering(compiler: ReplCompiler) {
24-
25-
private var currentClassLoader: Option[ClassLoader] = None
23+
private[repl] class Rendering(compiler: ReplCompiler,
24+
private var currentClassLoader: Option[ClassLoader] = None) {
2625

2726
private def classLoader()(implicit ctx: Context) =
2827
currentClassLoader.getOrElse {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ case class Completions(cursor: Int,
7777
details: List[String])
7878

7979
/** Main REPL instance, orchestrating input, compilation and presentation */
80-
class ReplDriver(settings: Array[String], protected val out: PrintStream = System.out) extends Driver {
80+
class ReplDriver(settings: Array[String],
81+
protected val out: PrintStream = System.out,
82+
protected val classLoader: Option[ClassLoader] = None) extends Driver {
8183

8284
/** Overridden to `false` in order to not have to give sources on the
8385
* commandline
@@ -110,7 +112,7 @@ class ReplDriver(settings: Array[String], protected val out: PrintStream = Syste
110112
new PlainDirectory(new Directory(new JFile(rootCtx.settings.d.value(rootCtx))))
111113
}
112114
compiler = new ReplCompiler(outDir)
113-
rendering = new Rendering(compiler)
115+
rendering = new Rendering(compiler, classLoader)
114116
}
115117

116118
protected[this] var rootCtx: Context = _
@@ -197,9 +199,9 @@ class ReplDriver(settings: Array[String], protected val out: PrintStream = Syste
197199

198200
/** Compile `parsed` trees and evolve `state` in accordance */
199201
protected[this] final def compile(parsed: Parsed)(implicit state: State): State = {
200-
import dotc.ast.Trees._
201-
import dotc.ast.untpd._
202-
def extractNewestWrapper(tree: untpd.Tree): Name = tree match {
202+
import dotc.ast.Trees.PackageDef
203+
import untpd.{ PackageDef => _, _ }
204+
def extractNewestWrapper(tree: Tree): Name = tree match {
203205
case PackageDef(_, (obj: ModuleDef) :: Nil) => obj.name.moduleClassName
204206
case _ => nme.NO_NAME
205207
}

repl/src/dotty/tools/repl/terminal/filters/ReadlineFilters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ object ReadlineFilters {
161161
allAfterCursor.splitAt(
162162
nextNewlineIndex
163163
) match {
164-
case (Vector(), Vector('\n', allAfterNewline@ _*)) =>
164+
case (Vector(), ('\n' +: allAfterNewline)) =>
165165
// if there's only a newline after cursor on line, cut it
166166
append(Vector('\n'))
167167
(allBeforeCursor ++ allAfterNewline, c)

sbt-bridge/src/xsbt/ConsoleInterface.scala

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ package xsbt
66
import xsbti.Logger
77

88
import dotty.tools.dotc.core.Contexts.Context
9-
// TODO: decide what to do with sbt REPL interface
10-
// import dotty.tools.dotc.repl.REPL
11-
// import dotty.tools.dotc.repl.REPL.Config
9+
import dotty.tools.repl.ReplDriver
1210

1311
class ConsoleInterface {
1412
def commandArguments(
@@ -28,43 +26,13 @@ class ConsoleInterface {
2826
bindValues: Array[Any],
2927
log: Logger
3028
): Unit = {
31-
//val completeArgs =
32-
// args :+
33-
// "-bootclasspath" :+ bootClasspathString :+
34-
// "-classpath" :+ classpathString
35-
36-
//println("Starting dotty interpreter...")
37-
//val repl = ConsoleInterface.customRepl(
38-
// initialCommands :: Nil,
39-
// cleanupCommands :: Nil,
40-
// bindNames zip bindValues,
41-
// loader
42-
//)
43-
//repl.process(completeArgs)
29+
val completeArgs =
30+
args ++ {
31+
if (bootClasspathString.isEmpty) Array.empty[String]
32+
else Array("-bootclasspath", bootClasspathString)
33+
} ++
34+
Array("-classpath", classpathString)
35+
36+
new ReplDriver(completeArgs, classLoader = Some(loader)).runUntilQuit()
4437
}
4538
}
46-
47-
object ConsoleInterface {
48-
//def customConfig(
49-
// initCmds: List[String],
50-
// cleanupCmds: List[String],
51-
// boundVals: Array[(String, Any)],
52-
// loader: ClassLoader
53-
//) = new Config {
54-
// override val initialCommands: List[String] = initCmds
55-
// override val cleanupCommands: List[String] = cleanupCmds
56-
// override val boundValues: Array[(String, Any)] = boundVals
57-
// override val classLoader: Option[ClassLoader] = Option(loader)
58-
//}
59-
60-
//def customRepl(cfg: Config): REPL = new REPL {
61-
// override lazy val config = cfg
62-
//}
63-
64-
//def customRepl(
65-
// initCmds: List[String],
66-
// cleanupCmds: List[String],
67-
// boundVals: Array[(String, Any)],
68-
// loader: ClassLoader
69-
//): REPL = customRepl(customConfig(initCmds, cleanupCmds, boundVals, loader))
70-
}

0 commit comments

Comments
 (0)