Add Problem#rendered to customize how problems are shown

Dotty has its own logic for displaying problems with the proper file
path, position, and caret, but if we store this information in
Problem#message we end up with duplicated information in the output
since Zinc will prepend/append similar things (see
sbt.internal.inc.ProblemStringFormats). So far, we worked around this in
Dotty by using an empty position in the sbt bridge reporter, but this
means that crucial semantic information that could be used by a Build
Server Protocol implementation and other tools is lost. This commit
allows us to avoid by adding an optional `rendered` field to `Problem`:
when this field is set, its value controls what the user sees, otherwise
we fallback to the default behavior (the logic to do this will be added to
Zinc after this PR is merged and a new release of sbt-util is made).
This commit is contained in:
Guillaume Martres
2018-08-28 03:58:15 +09:00
parent e905b44a33
commit 15522a0cbe
6 changed files with 42 additions and 10 deletions
@@ -3,10 +3,20 @@
*/
package xsbti;
import java.util.Optional;
public interface Problem
{
String category();
Severity severity();
String message();
Position position();
}
// Default value to avoid breaking binary compatibility
/**
* If present, the string shown to the user when displaying this Problem.
* Otherwise, the Problem will be shown in an implementation-defined way
* based on the values of its other fields.
*/
default Optional<String> rendered() { return Optional.empty(); }
}