Skip to content

Commit 3a6c368

Browse files
committed
docs: add in a few docs in the newly added classes
1 parent 1424f9b commit 3a6c368

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

compiler/src/dotty/tools/dotc/reporting/CodeAction.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ package dotty.tools.dotc.reporting
22

33
import 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+
*/
512
case class CodeAction(
613
title: String,
714
description: java.util.Optional[String],

compiler/src/dotty/tools/dotc/reporting/Message.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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) {

sbt-bridge/src/dotty/tools/xsbt/Problem.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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())))

0 commit comments

Comments
 (0)