Skip to content

Commit 17aa294

Browse files
committed
Skeleton :require
1 parent 64e7aa7 commit 17aa294

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
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
/** To find out the type of an expression you may simply do:
5663
*
5764
* ```
@@ -139,6 +146,7 @@ object ParseResult {
139146
Reset.command -> (arg => Reset(arg)),
140147
Imports.command -> (_ => Imports),
141148
Load.command -> (arg => Load(arg)),
149+
Require.command -> (arg => Require(arg)),
142150
TypeOf.command -> (arg => TypeOf(arg)),
143151
DocOf.command -> (arg => DocOf(arg)),
144152
Settings.command -> (arg => Settings(arg)),

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

Lines changed: 12 additions & 0 deletions
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 TypeOf(expr) =>
514526
expr match {
515527
case "" => out.println(s":type <expression>")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class TabcompleteTests extends ReplTest {
214214
":help",
215215
":imports",
216216
":load",
217+
":require",
217218
":quit",
218219
":reset",
219220
":settings",

0 commit comments

Comments
 (0)