Skip to content

Commit

Permalink
messageAndPos takes Diagnostic parameter (refactoring only)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Aug 16, 2021
1 parent ccb8d28 commit 7de0d09
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/ConsoleReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class ConsoleReporter(
def doReport(dia: Diagnostic)(using Context): Unit = {
dia match
case dia: Error =>
printMessage(messageAndPos(dia.msg, dia.pos, diagnosticLevel(dia)))
printMessage(messageAndPos(dia))
if (ctx.settings.Xprompt.value) Reporter.displayPrompt(reader, writer)
case dia =>
printMessage(messageAndPos(dia.msg, dia.pos, diagnosticLevel(dia)))
printMessage(messageAndPos(dia))

if shouldExplain(dia) then
printMessage(explanation(dia.msg))
Expand Down
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ trait MessageRendering {
}

/** The whole message rendered from `msg` */
def messageAndPos(msg: Message, pos: SourcePosition, diagnosticLevel: String)(using Context): String = {
def messageAndPos(dia: Diagnostic)(using Context): String = {
import dia._
val levelString = diagnosticLevel(dia)
val sb = mutable.StringBuilder()
val posString = posStr(pos, diagnosticLevel, msg)
val posString = posStr(pos, levelString, msg)
if (posString.nonEmpty) sb.append(posString).append(EOL)
if (pos.exists) {
val pos1 = pos.nonInlined
if (pos1.exists && pos1.source.file.exists) {
val (srcBefore, srcAfter, offset) = sourceLines(pos1, diagnosticLevel)
val marker = columnMarker(pos1, offset, diagnosticLevel)
val (srcBefore, srcAfter, offset) = sourceLines(pos1, levelString)
val marker = columnMarker(pos1, offset, levelString)
val err = errorMsg(pos1, msg.message, offset)
sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1)) ::: srcAfter).mkString(EOL))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
/** Formats errors using the `messageRenderer` */
def formatError(dia: Diagnostic)(implicit state: State): Diagnostic =
new Diagnostic(
messageRenderer.messageAndPos(dia.msg, dia.pos, messageRenderer.diagnosticLevel(dia))(using state.context),
messageRenderer.messageAndPos(dia)(using state.context),
dia.pos,
dia.level
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M

/** Prints the message with the given position indication. */
def printMessageAndPos(dia: Diagnostic, extra: String)(using Context): Unit = {
val msg = messageAndPos(dia.msg, dia.pos, diagnosticLevel(dia))
val msg = messageAndPos(dia)
val extraInfo = inlineInfo(dia.pos)

if (dia.level >= logLevel) {
Expand Down
4 changes: 2 additions & 2 deletions sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public void doReport(Diagnostic dia, Context ctx) {
Severity severity = severityOf(dia.level());
Position position = positionOf(dia.pos().nonInlined());

Message message = dia.msg();
StringBuilder rendered = new StringBuilder();
rendered.append(messageAndPos(message, dia.pos(), diagnosticLevel(dia), ctx));
rendered.append(messageAndPos(dia, ctx));
Message message = dia.msg();
boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx);
if (shouldExplain && !message.explanation().isEmpty()) {
rendered.append(explanation(message, ctx));
Expand Down

0 comments on commit 7de0d09

Please sign in to comment.