Skip to content

Commit 1632cb9

Browse files
committed
Implement ReplConsoleReporter in terms of the ReplDriver out PrintStream
Based on the implementation of ConsoleReporter. Sidesteps issues on Windows where the default console encoding may be something other than UTF8 (such as Cp437), which PrintStream is aware of, but apparently there is no API to query.
1 parent ca8147d commit 1632cb9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.repl
22

3-
import java.io.{BufferedWriter, File => JFile, OutputStreamWriter, PrintStream, PrintWriter}
3+
import java.io.{File => JFile, PrintStream}
44
import java.nio.charset.StandardCharsets
55

66
import dotty.tools.dotc.ast.Trees._
@@ -20,7 +20,7 @@ import dotty.tools.dotc.core.Symbols.{Symbol, defn}
2020
import dotty.tools.dotc.interfaces
2121
import dotty.tools.dotc.interactive.Completion
2222
import dotty.tools.dotc.printing.SyntaxHighlighting
23-
import dotty.tools.dotc.reporting.{ConsoleReporter, MessageRendering, StoreReporter}
23+
import dotty.tools.dotc.reporting.{AbstractReporter, MessageRendering, StoreReporter}
2424
import dotty.tools.dotc.reporting.{Message, Diagnostic}
2525
import dotty.tools.dotc.util.Spans.Span
2626
import dotty.tools.dotc.util.{SourceFile, SourcePosition}
@@ -426,10 +426,18 @@ class ReplDriver(settings: Array[String],
426426
}
427427

428428
/** Like ConsoleReporter, but without file paths or real -Xprompt'ing */
429-
private object ReplConsoleReporter extends ConsoleReporter(
430-
reader = null, // this short-circuits the -Xprompt display from waiting for an input
431-
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)), /* autoFlush = */ true), // write to out, not Console.err
432-
) {
429+
private object ReplConsoleReporter extends AbstractReporter {
430+
def printMessage(msg: String): Unit = out.println(msg)
431+
432+
def doReport(dia: Diagnostic)(using Context): Unit = {
433+
printMessage(messageAndPos(dia))
434+
435+
if Diagnostic.shouldExplain(dia) then
436+
printMessage(explanation(dia.msg))
437+
else if dia.msg.canExplain then
438+
printMessage("\nlonger explanation available when compiling with `-explain`")
439+
}
440+
433441
override def posFileStr(pos: SourcePosition) = "" // omit file paths
434442
}
435443

0 commit comments

Comments
 (0)