Skip to content

Commit 321131a

Browse files
committed
Skeleton :require
1 parent 285cd40 commit 321131a

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
@@ -505,6 +505,18 @@ class ReplDriver(settings: Array[String],
505505
state
506506
}
507507

508+
case Require(path) =>
509+
val file = new JFile(path)
510+
if (file.exists) {
511+
// val contents = Using(scala.io.Source.fromFile(file, StandardCharsets.UTF_8.name))(_.mkString).get
512+
// run(contents)
513+
???
514+
}
515+
else {
516+
out.println(s"""Couldn't find file "${file.getCanonicalPath}"""")
517+
state
518+
}
519+
508520
case TypeOf(expr) =>
509521
expr match {
510522
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)