File tree Expand file tree Collapse file tree 4 files changed +22
-0
lines changed
compiler/src/dotty/tools/dotc
sbt-bridge/src/dotty/tools/xsbt Expand file tree Collapse file tree 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
22
33import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
44
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+ */
512case class CodeAction (
613 title : String ,
714 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 =>
414414 */
415415 def showAlways = false
416416
417+ /** A list of actions attatched to this message to address the issue this
418+ * message represents.
419+ */
417420 def actions (using Context ): java.util.List [CodeAction ] =
418421 java.util.Collections .emptyList
419422
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ object Rewrites {
2020 def delta = replacement.length - (span.end - span.start)
2121 }
2222
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+ */
2331 case class ActionPatch (srcPos : SourcePosition , replacement : String )
2432
2533 private class Patches (source : SourceFile ) {
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ public List<xsbti.Action> actions() {
6969 if (_actions .isEmpty ()) {
7070 return java .util .Collections .emptyList ();
7171 } 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.
7276 return _actions
7377 .stream ()
7478 .map (action -> new Action (action .title (), action .description (), toWorkspaceEdit (action .patches ())))
You can’t perform that action at this time.
0 commit comments