Skip to content

Commit

Permalink
Add DiagnosticRelatedInformation to compiler's interface
Browse files Browse the repository at this point in the history
  • Loading branch information
prolativ committed Jan 13, 2023
1 parent c4d63cc commit 54639f2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.interfaces.Diagnostic.{ERROR, INFO, WARNING}
import dotty.tools.dotc.util.SourcePosition

import java.util.Optional
import java.util.{Collections, Optional, List => JList}
import scala.util.chaining._
import core.Decorators.toMessage

Expand Down Expand Up @@ -100,6 +100,8 @@ class Diagnostic(
if (pos.exists && pos.source.exists) Optional.of(pos) else Optional.empty()
override def message: String =
msg.message.replaceAll("\u001B\\[[;\\d]*m", "")
override def diagnosticRelatedInformation: JList[interfaces.DiagnosticRelatedInformation] =
Collections.emptyList()

override def toString: String = s"$getClass at $pos: $message"
override def getMessage(): String = message
Expand Down
4 changes: 4 additions & 0 deletions interfaces/src/dotty/tools/dotc/interfaces/Diagnostic.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools.dotc.interfaces;

import java.util.Optional;
import java.util.List;

/** A diagnostic is a message emitted during the compilation process.
*
Expand All @@ -23,4 +24,7 @@ public interface Diagnostic {
/** @return The position in a source file of the code that caused this diagnostic
* to be emitted. */
Optional<SourcePosition> position();

/** @return A list of additional messages together with their code positions */
List<DiagnosticRelatedInformation> diagnosticRelatedInformation();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dotty.tools.dotc.interfaces;

public interface DiagnosticRelatedInformation {
SourcePosition position();
String message();
}
3 changes: 2 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ object Build {
settings(commonJavaSettings).
settings(commonMiMaSettings).
settings(
versionScheme := Some("semver-spec")
versionScheme := Some("semver-spec"),
mimaBinaryIssueFilters ++= MiMaFilters.Interfaces
)

/** Find an artifact with the given `name` in `classpath` */
Expand Down
4 changes: 4 additions & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ object MiMaFilters {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.caps.unsafeUnbox"),
)
val TastyCore: Seq[ProblemFilter] = Seq()
val Interfaces: Seq[ProblemFilter] = Seq(
ProblemFilters.exclude[MissingClassProblem]("dotty.tools.dotc.interfaces.DiagnosticRelatedInformation"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("dotty.tools.dotc.interfaces.Diagnostic.diagnosticRelatedInformation")
)
}
4 changes: 3 additions & 1 deletion tests/pos-with-compiler-cc/dotc/reporting/Diagnostic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.interfaces.Diagnostic.{ERROR, INFO, WARNING}
import dotty.tools.dotc.util.SourcePosition

import java.util.Optional
import java.util.{Collections, Optional, List => JList}
import scala.util.chaining._
import core.Decorators.toMessage
import language.experimental.pureFunctions
Expand Down Expand Up @@ -101,6 +101,8 @@ class Diagnostic(
if (pos.exists && pos.source.exists) Optional.of(pos) else Optional.empty()
override def message: String =
msg.message.replaceAll("\u001B\\[[;\\d]*m", "")
override def diagnosticRelatedInformation: JList[interfaces.DiagnosticRelatedInformation] =
Collections.emptyList()

override def toString: String = s"$getClass at $pos: $message"
override def getMessage(): String = message
Expand Down

0 comments on commit 54639f2

Please sign in to comment.