Merge pull request #7242 from ckipp01/action

feat: add in `actions()` to `Problem`
This commit is contained in:
eugene yokota 2023-05-12 00:03:49 -04:00 committed by GitHub
commit cf6fac7692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,32 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package xsbti;
import java.util.Optional;
/**
* An Action is very miminal representation of a `CodeAction` in the LSP protocol.
*
* <p>However it only focuses on the actual title, description, and edit, leaving it up to the
* language server to communicate with the client and put together a proper codeAction in accordance
* to client capabilities.
*
* @see <a href=
* "https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeAction">`CodeAction`</a>
*/
public interface Action {
/** Title of the action that will be shown to the user client side. */
String title();
/** Optional description that may be shown to the user client side to explain the action. */
Optional<String> description();
/** The actual edit contained in the action. */
WorkspaceEdit edit();
}

View File

@ -0,0 +1,21 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package xsbti;
import java.net.URI;
import java.util.List;
/** A collection of TextEdits that belong to a given URI. */
public interface FileChanges {
/** The URI that the edits belong to. */
URI uri();
/** The edits belonging to the URI. */
List<TextEdit> edits();
}

View File

@ -54,4 +54,29 @@ public interface Problem {
default List<DiagnosticRelatedInformation> diagnosticRelatedInformation() {
return Collections.emptyList();
}
/**
* Actions (aka quick fixes) that are able to either fix or address the issue that is causing this
* Problem.
*
* <p>For example given the following code:
*
* <pre>
* trait Example:
* def foo(): Unit
* def bar(): Unit
*
* class MyExample extends Example
* </pre>
*
* You could expect this to have multiple actions attatched:
*
* <ul>
* <li>An option to implement a stub method for `foo()` and `bar()`
* <li>An option to make `MyExample` abstract
* </ul>
*/
default List<Action> actions() {
return Collections.emptyList();
}
}

View File

@ -0,0 +1,25 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package xsbti;
/**
* A representation of the `TextEdit` found in the LSP protocol.
*
* <p>NOTE: That instead of a `Range` we use the internal [[xsbti.Position]].
*
* @see <a
* href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textEdit">`TextEdit`</a>
*/
public interface TextEdit {
/** The position this edit will be applied to. */
Position position();
/** The next text that will be inserted into the given [[TextEdit.position]]. */
String newText();
}

View File

@ -0,0 +1,27 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package xsbti;
import java.net.URI;
import java.util.List;
/**
* A minimal representatin of the `WorkspaceEdit` found in the LSP protocol.
*
* <p>However it only supports the minimal `changes` to ensure the fixes will work with all clients.
*
* <p>NOTE: In the future this may be expanded to handle resource operations via `documentChanges`.
*
* @see <a href=
* "https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceEdit">`WorkspaceEdit`</a>
*/
public interface WorkspaceEdit {
/** List of [[xsbti.FileChanges]] that belong to this WorkspaceEdit. */
List<FileChanges> changes();
}