Skip to content

Commit 38831b7

Browse files
committed
.
1 parent 4d1139c commit 38831b7

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package dotty.tools.repl
44
// To test, run bin/scala
55
object Main {
66
def main(args: Array[String]): Unit =
7-
new ReplDriver(args).tryRunning
7+
new ReplDriver(args, extraPredef = ReplDriver.pprintImport).tryRunning
88
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
5353
else str.substring(0, str.offsetByCodePoints(0, maxPrintCharacters - 1))
5454

5555
/** Return a String representation of a value we got from `classLoader()`. */
56-
private[repl] def replStringOf(sym: Symbol, value: Object)(using Context): String =
57-
dotty.shaded.pprint.PPrinter.BlackWhite.apply(value, height = 50, width = 100).plainText
56+
private[repl] def replStringOf(sym: Symbol, value: Object)(using Context): String = {
57+
// pretty-print things with 100 cols 50 rows by default,
58+
dotty.shaded.pprint.PPrinter.BlackWhite.apply(value, width = 100, height = 50).plainText
59+
}
5860

5961
/** Load the value of the symbol using reflection.
6062
*

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ case class State(objectIndex: Int,
7777
/** Main REPL instance, orchestrating input, compilation and presentation */
7878
class ReplDriver(settings: Array[String],
7979
out: PrintStream = Console.out,
80-
classLoader: Option[ClassLoader] = None) extends Driver:
80+
classLoader: Option[ClassLoader] = None,
81+
extraPredef: String = "") extends Driver:
8182

8283
/** Overridden to `false` in order to not have to give sources on the
8384
* commandline
@@ -122,10 +123,9 @@ class ReplDriver(settings: Array[String],
122123
final def initialState: State =
123124
val emptyState = State(0, 0, Map.empty, Set.empty, false, rootCtx)
124125
val initScript = rootCtx.settings.replInitScript.value(using rootCtx)
125-
val pprintImport = "import dotty.shaded.pprint.pprintln"
126126
val combinedScript = initScript.trim() match
127-
case "" => pprintImport
128-
case script => s"$pprintImport\n$script"
127+
case "" => extraPredef
128+
case script => s"$extraPredef\n$script"
129129
run(combinedScript)(using emptyState)
130130

131131
/** Reset state of repl to the initial state
@@ -640,3 +640,5 @@ class ReplDriver(settings: Array[String],
640640
case _ => ReplConsoleReporter.doReport(dia)(using state.context)
641641

642642
end ReplDriver
643+
object ReplDriver:
644+
def pprintImport = "import dotty.shaded.pprint.pprintln\n"

language-server/src/dotty/tools/languageserver/worksheet/ReplProcess.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dotty.tools.repl.ReplDriver
44

55
object ReplProcess {
66
def main(args: Array[String]): Unit = {
7-
val driver = new ReplDriver(args)
7+
val driver = new ReplDriver(args, extraPredef = ReplDriver.pprintImport)
88
val in = new InputStreamConsumer(System.in)
99
var state = driver.initialState
1010

sbt-bridge/src/xsbt/ConsoleInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void run(
4040
completeArgsList.add(classpathString);
4141
String[] completeArgs = completeArgsList.toArray(args);
4242

43-
ReplDriver driver = new ReplDriver(completeArgs, System.out, Some.apply(loader));
43+
ReplDriver driver = new ReplDriver(completeArgs, System.out, Some.apply(loader), ReplDriver.pprintImport());
4444

4545
State state = driver.initialState();
4646
assert bindNames.length == bindValues.length;

0 commit comments

Comments
 (0)