File tree 4 files changed +22
-0
lines changed
compiler/src/dotty/tools/dotc
sbt-bridge/src/dotty/tools/xsbt
4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,13 @@ package dotty.tools.dotc.reporting
2
2
3
3
import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
4
4
5
+ /** A representation of a code action / fix that can be used by tooling to
6
+ * apply a fix to their code.
7
+ *
8
+ * @param title The title of the fix, often showed to a user in their editor.
9
+ * @param description An optional description of the fix.
10
+ * @param patches The patches that this fix contains.
11
+ */
5
12
case class CodeAction (
6
13
title : String ,
7
14
description : java.util.Optional [String ],
Original file line number Diff line number Diff line change @@ -414,6 +414,9 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
414
414
*/
415
415
def showAlways = false
416
416
417
+ /** A list of actions attatched to this message to address the issue this
418
+ * message represents.
419
+ */
417
420
def actions (using Context ): java.util.List [CodeAction ] =
418
421
java.util.Collections .emptyList
419
422
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ object Rewrites {
20
20
def delta = replacement.length - (span.end - span.start)
21
21
}
22
22
23
+ /** A special type of Patch that instead of just a span, contains the
24
+ * full SourcePosition. This is useful when being used by
25
+ * [[dotty.tools.dotc.reporting.CodeAction ]] or if the patch doesn't
26
+ * belong to the same file that the actual issue it's addressing is in.
27
+ *
28
+ * @param srcPos The SourcePosition of the patch.
29
+ * @param replacement The Replacement that should go in that position.
30
+ */
23
31
case class ActionPatch (srcPos : SourcePosition , replacement : String )
24
32
25
33
private class Patches (source : SourceFile ) {
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ public List<xsbti.Action> actions() {
69
69
if (_actions .isEmpty ()) {
70
70
return java .util .Collections .emptyList ();
71
71
} else {
72
+ // Same as with diagnosticCode, we need to ensure we don't create the actual
73
+ // Action until we are here to ensure that when using an older version of sbt/zinc
74
+ // with the new versions of the compiler, this doesn't blow up because this is
75
+ // never getting called.
72
76
return _actions
73
77
.stream ()
74
78
.map (action -> new Action (action .title (), action .description (), toWorkspaceEdit (action .patches ())))
You can’t perform that action at this time.
0 commit comments