Skip to content

Commit f8cd3ba

Browse files
aherlihydwijnand
authored andcommitted
Skeleton :require
1 parent 482107b commit f8cd3ba

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ object Load {
5252
val command: String = ":load"
5353
}
5454

55+
/** `:require <path>` adds a jar to the classpath
56+
*/
57+
case class Require(path: String) extends Command
58+
object Require {
59+
val command: String = ":require"
60+
}
61+
5562
/** `:kind <type>` display the kind of a type. see also :help kind
5663
*/
5764
case class KindOf(expr: String) extends Command
@@ -147,6 +154,7 @@ object ParseResult {
147154
Imports.command -> (_ => Imports),
148155
KindOf.command -> (arg => KindOf(arg)),
149156
Load.command -> (arg => Load(arg)),
157+
Require.command -> (arg => Require(arg)),
150158
TypeOf.command -> (arg => TypeOf(arg)),
151159
DocOf.command -> (arg => DocOf(arg)),
152160
Settings.command -> (arg => Settings(arg)),

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

+12
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,18 @@ class ReplDriver(settings: Array[String],
510510
state
511511
}
512512

513+
case Require(path) =>
514+
val file = new JFile(path)
515+
if (file.exists) {
516+
// val contents = Using(scala.io.Source.fromFile(file, StandardCharsets.UTF_8.name))(_.mkString).get
517+
// run(contents)
518+
???
519+
}
520+
else {
521+
out.println(s"""Couldn't find file "${file.getCanonicalPath}"""")
522+
state
523+
}
524+
513525
case KindOf(expr) =>
514526
out.println(s"""The :kind command is not currently supported.""")
515527
state

compiler/test/dotty/tools/repl/TabcompleteTests.scala

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class TabcompleteTests extends ReplTest {
215215
":imports",
216216
":kind",
217217
":load",
218+
":require",
218219
":quit",
219220
":reset",
220221
":settings",

0 commit comments

Comments
 (0)