Skip to content

bump compiler-interface and capture the diagnosticCode #15565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ object Dependencies {
"com.vladsch.flexmark" % "flexmark-ext-yaml-front-matter" % flexmarkVersion,
)

val newCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.4.3"
val newCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.7.1"
val oldCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.3.5"
}
3 changes: 2 additions & 1 deletion sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ public void doReport(Diagnostic dia, Context ctx) {
StringBuilder rendered = new StringBuilder();
rendered.append(messageAndPos(dia, ctx));
Message message = dia.msg();
String diagnosticCode = String.valueOf(message.errorId().errorNumber());
boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx);
if (shouldExplain && !message.explanation().isEmpty()) {
rendered.append(explanation(message, ctx));
}

delegate.log(new Problem(position, message.msg(), severity, rendered.toString()));
delegate.log(new Problem(position, message.msg(), severity, rendered.toString(), diagnosticCode));
}

private static Severity severityOf(int level) {
Expand Down
23 changes: 23 additions & 0 deletions sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dotty.tools.xsbt;

import java.util.Optional;

final public class DiagnosticCode implements xsbti.DiagnosticCode {
private final String _code;
private final Optional<String> _explanation;

public DiagnosticCode(String code, Optional<String> explanation) {
super();
this._code = code;
this._explanation = explanation;
}

public String code() {
return _code;
}

public Optional<String> explanation() {
return _explanation;
}

}
15 changes: 13 additions & 2 deletions sbt-bridge/src/dotty/tools/xsbt/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ final public class Problem implements xsbti.Problem {
private final String _message;
private final Severity _severity;
private final Optional<String> _rendered;
private final String _diagnosticCode;

public Problem(Position position, String message, Severity severity, String rendered) {
public Problem(Position position, String message, Severity severity, String rendered, String diagnosticCode) {
super();
this._position = position;
this._message = message;
this._severity = severity;
this._rendered = Optional.of(rendered);
this._diagnosticCode = diagnosticCode;
}

public String category() {
Expand All @@ -38,8 +40,17 @@ public Optional<String> rendered() {
return _rendered;
}

public Optional<xsbti.DiagnosticCode> diagnosticCode() {
// NOTE: It's important for compatibility that we only construct a
// DiagnosticCode here to maintain compatibility with older versions of
// zinc while using this newer version of the compiler. If we would
// contstruct it earlier, you'd end up with ClassNotFoundExceptions for
// DiagnosticCode.
return Optional.of(new DiagnosticCode(_diagnosticCode, Optional.empty()));
}

@Override
public String toString() {
return "Problem(" + _position + ", " + _message + ", " + _severity + ", " + _rendered + ")";
return "Problem(" + _position + ", " + _message + ", " + _severity + ", " + _rendered + ", " + _diagnosticCode + ")";
}
}
5 changes: 5 additions & 0 deletions sbt-test/compilerReporter/simple/project/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ object Reporter {
assert(line.isPresent() == true)
assert(line.get() == 9)

val diagnosticCode = mainProblem.diagnosticCode()
assert(diagnosticCode.isPresent() == true)
val code = diagnosticCode.get()
assert(diagnosticCode.get().code() == "6")

val pointer = mainProblem.position().pointer()
assert(pointer.isPresent() == true)
assert(pointer.get() == 10)
Expand Down