Skip to content

Commit dd92c85

Browse files
authored
Attach explanation message to diagnostic message (#16787)
When the `-explain` flag was turned on, an explanation message wasn't displayed in the Metals and Scala CLI. This was because both of these tools only print the message from the [Problem.message](https://github.com/lampepfl/dotty/blob/c0a7d128671d063a2b566abdaa08fe7fa83c2d06/sbt-bridge/src/dotty/tools/xsbt/Problem.java#L17) field. To resolve this issue, I attached the explanation content to the `Problem.message` field, which will now be displayed in the Metals and Scala CLI. This PR addresses a [issue](VirtusLab/scala-cli#1285) from `scala-cli`.
2 parents f5e6985 + 18a8a09 commit dd92c85

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ public void doReport(Diagnostic dia, Context ctx) {
3939
StringBuilder rendered = new StringBuilder();
4040
rendered.append(messageAndPos(dia, ctx));
4141
Message message = dia.msg();
42+
StringBuilder messageBuilder = new StringBuilder();
43+
messageBuilder.append(message.message());
4244
String diagnosticCode = String.valueOf(message.errorId().errorNumber());
4345
boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx);
4446
if (shouldExplain && !message.explanation().isEmpty()) {
4547
rendered.append(explanation(message, ctx));
48+
messageBuilder.append(System.lineSeparator()).append(explanation(message, ctx));
4649
}
4750

48-
delegate.log(new Problem(position, message.message(), severity, rendered.toString(), diagnosticCode));
51+
delegate.log(new Problem(position, messageBuilder.toString(), severity, rendered.toString(), diagnosticCode));
4952
}
5053

5154
private static Severity severityOf(int level) {

0 commit comments

Comments
 (0)