Skip to content

Commit

Permalink
docs: add in a few docs in the newly added classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ckipp01 committed Jul 6, 2023
1 parent 1424f9b commit 3a6c368
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/CodeAction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package dotty.tools.dotc.reporting

import dotty.tools.dotc.rewrites.Rewrites.ActionPatch

/** A representation of a code action / fix that can be used by tooling to
* apply a fix to their code.
*
* @param title The title of the fix, often showed to a user in their editor.
* @param description An optional description of the fix.
* @param patches The patches that this fix contains.
*/
case class CodeAction(
title: String,
description: java.util.Optional[String],
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
*/
def showAlways = false

/** A list of actions attatched to this message to address the issue this
* message represents.
*/
def actions(using Context): java.util.List[CodeAction] =
java.util.Collections.emptyList

Expand Down
8 changes: 8 additions & 0 deletions compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ object Rewrites {
def delta = replacement.length - (span.end - span.start)
}

/** A special type of Patch that instead of just a span, contains the
* full SourcePosition. This is useful when being used by
* [[dotty.tools.dotc.reporting.CodeAction]] or if the patch doesn't
* belong to the same file that the actual issue it's addressing is in.
*
* @param srcPos The SourcePosition of the patch.
* @param replacement The Replacement that should go in that position.
*/
case class ActionPatch(srcPos: SourcePosition, replacement: String)

private class Patches(source: SourceFile) {
Expand Down
4 changes: 4 additions & 0 deletions sbt-bridge/src/dotty/tools/xsbt/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public List<xsbti.Action> actions() {
if (_actions.isEmpty()) {
return java.util.Collections.emptyList();
} else {
// Same as with diagnosticCode, we need to ensure we don't create the actual
// Action until we are here to ensure that when using an older version of sbt/zinc
// with the new versions of the compiler, this doesn't blow up because this is
// never getting called.
return _actions
.stream()
.map(action -> new Action(action.title(), action.description(), toWorkspaceEdit(action.patches())))
Expand Down

0 comments on commit 3a6c368

Please sign in to comment.