Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add in actions() to Problem #7242

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions internal/util-interface/src/main/java/xsbti/Action.java
Original file line number Diff line number Diff line change
@@ -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();
}
21 changes: 21 additions & 0 deletions internal/util-interface/src/main/java/xsbti/FileChanges.java
Original file line number Diff line number Diff line change
@@ -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();
eed3si9n marked this conversation as resolved.
Show resolved Hide resolved

/** The edits belonging to the URI. */
List<TextEdit> edits();
}
25 changes: 25 additions & 0 deletions internal/util-interface/src/main/java/xsbti/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,29 @@ default Optional<DiagnosticCode> diagnosticCode() {
default List<DiagnosticRelatedInformation> diagnosticRelatedInforamation() {
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();
}
}
25 changes: 25 additions & 0 deletions internal/util-interface/src/main/java/xsbti/TextEdit.java
Original file line number Diff line number Diff line change
@@ -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();
eed3si9n marked this conversation as resolved.
Show resolved Hide resolved

/** The next text that will be inserted into the given [[TextEdit.position]]. */
String newText();
}
27 changes: 27 additions & 0 deletions internal/util-interface/src/main/java/xsbti/WorkspaceEdit.java
Original file line number Diff line number Diff line change
@@ -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();
}