11package dotty .tools .xsbt ;
22
3+ import java .util .List ;
34import java .util .Optional ;
5+ import static java .util .stream .Collectors .toList ;
6+
7+ import dotty .tools .dotc .reporting .CodeAction ;
8+ import dotty .tools .dotc .rewrites .Rewrites .ActionPatch ;
9+ import dotty .tools .dotc .util .SourcePosition ;
10+
411import xsbti .Position ;
512import xsbti .Severity ;
613
@@ -10,14 +17,16 @@ final public class Problem implements xsbti.Problem {
1017 private final Severity _severity ;
1118 private final Optional <String > _rendered ;
1219 private final String _diagnosticCode ;
20+ private final List <CodeAction > _actions ;
1321
14- public Problem (Position position , String message , Severity severity , String rendered , String diagnosticCode ) {
22+ public Problem (Position position , String message , Severity severity , String rendered , String diagnosticCode , List < CodeAction > actions ) {
1523 super ();
1624 this ._position = position ;
1725 this ._message = message ;
1826 this ._severity = severity ;
1927 this ._rendered = Optional .of (rendered );
2028 this ._diagnosticCode = diagnosticCode ;
29+ this ._actions = actions ;
2130 }
2231
2332 public String category () {
@@ -56,6 +65,34 @@ public Optional<xsbti.DiagnosticCode> diagnosticCode() {
5665 }
5766 }
5867
68+ public List <xsbti .Action > actions () {
69+ if (_actions .isEmpty ()) {
70+ return java .util .Collections .emptyList ();
71+ } else {
72+ return _actions
73+ .stream ()
74+ .map (action -> new Action (action .title (), action .description (), toWorkspaceEdit (action .patches ())))
75+ .collect (toList ());
76+ }
77+ }
78+
79+ private static WorkspaceEdit toWorkspaceEdit (List <ActionPatch > patches ) {
80+ return new WorkspaceEdit (
81+ patches
82+ .stream ()
83+ .map (patch -> new TextEdit (positionOf (patch .srcPos ()), patch .replacement ()))
84+ .collect (toList ())
85+ );
86+ }
87+
88+ private static Position positionOf (SourcePosition pos ) {
89+ if (pos .exists ()){
90+ return new PositionBridge (pos , pos .source ());
91+ } else {
92+ return PositionBridge .noPosition ;
93+ }
94+ }
95+
5996 @ Override
6097 public String toString () {
6198 return "Problem(" + _position + ", " + _message + ", " + _severity + ", " + _rendered + ", " + _diagnosticCode + ")" ;
0 commit comments