Skip to content

Commit

Permalink
Diagnostics#actions
Browse files Browse the repository at this point in the history
**Problem**
We want to pass along code actions via Diagnostics,
even though this idea seems to have been shot down already in LSP
microsoft/language-server-protocol 581.

**Solution**
This defines additional `actions` field to `Diagnostics`, mirroring
sbt/sbt#7242.
  • Loading branch information
eed3si9n committed May 21, 2023
1 parent c9c1306 commit 32c8f79
Show file tree
Hide file tree
Showing 11 changed files with 394 additions and 3 deletions.
29 changes: 29 additions & 0 deletions bsp4j/src/main/java/ch/epfl/scala/bsp4j/Protocol.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,34 @@ class DiagnosticRelatedInformation {
}
}

@JsonRpcData
class CodeAction {
@NonNull String title
String description
WorkspaceEdit edit
new(@NonNull String title) {
this.title = title
}
}

@JsonRpcData
class WorkspaceEdit {
List<TextEdit> changes
new(List<TextEdit> changes) {
this.changes = changes
}
}

@JsonRpcData
class TextEdit {
@NonNull Range range
@NonNull String newText
new(@NonNull Range range, @NonNull String newText) {
this.range = range
this.newText = newText
}
}

@JsonRpcData
class Diagnostic {
@NonNull Range range
Expand All @@ -254,6 +282,7 @@ class Diagnostic {
List<DiagnosticRelatedInformation> relatedInformation
String dataKind
@JsonAdapter(JsonElementTypeAdapter.Factory) Object data
List<CodeAction> actions
new(@NonNull Range range, @NonNull String message) {
this.range = range
this.message = message
Expand Down
96 changes: 96 additions & 0 deletions bsp4j/src/main/xtend-gen/ch/epfl/scala/bsp4j/CodeAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package ch.epfl.scala.bsp4j;

import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.util.Preconditions;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

@SuppressWarnings("all")
public class CodeAction {
@NonNull
private String title;

private String description;

private WorkspaceEdit edit;

public CodeAction(@NonNull final String title) {
this.title = title;
}

@Pure
@NonNull
public String getTitle() {
return this.title;
}

public void setTitle(@NonNull final String title) {
this.title = Preconditions.checkNotNull(title, "title");
}

@Pure
public String getDescription() {
return this.description;
}

public void setDescription(final String description) {
this.description = description;
}

@Pure
public WorkspaceEdit getEdit() {
return this.edit;
}

public void setEdit(final WorkspaceEdit edit) {
this.edit = edit;
}

@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("title", this.title);
b.add("description", this.description);
b.add("edit", this.edit);
return b.toString();
}

@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CodeAction other = (CodeAction) obj;
if (this.title == null) {
if (other.title != null)
return false;
} else if (!this.title.equals(other.title))
return false;
if (this.description == null) {
if (other.description != null)
return false;
} else if (!this.description.equals(other.description))
return false;
if (this.edit == null) {
if (other.edit != null)
return false;
} else if (!this.edit.equals(other.edit))
return false;
return true;
}

@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.title== null) ? 0 : this.title.hashCode());
result = prime * result + ((this.description== null) ? 0 : this.description.hashCode());
return prime * result + ((this.edit== null) ? 0 : this.edit.hashCode());
}
}
20 changes: 19 additions & 1 deletion bsp4j/src/main/xtend-gen/ch/epfl/scala/bsp4j/Diagnostic.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Diagnostic {
@JsonAdapter(JsonElementTypeAdapter.Factory.class)
private Object data;

private List<CodeAction> actions;

public Diagnostic(@NonNull final Range range, @NonNull final String message) {
this.range = range;
this.message = message;
Expand Down Expand Up @@ -108,6 +110,15 @@ public void setData(final Object data) {
this.data = data;
}

@Pure
public List<CodeAction> getActions() {
return this.actions;
}

public void setActions(final List<CodeAction> actions) {
this.actions = actions;
}

@Override
@Pure
public String toString() {
Expand All @@ -120,6 +131,7 @@ public String toString() {
b.add("relatedInformation", this.relatedInformation);
b.add("dataKind", this.dataKind);
b.add("data", this.data);
b.add("actions", this.actions);
return b.toString();
}

Expand Down Expand Up @@ -173,6 +185,11 @@ public boolean equals(final Object obj) {
return false;
} else if (!this.data.equals(other.data))
return false;
if (this.actions == null) {
if (other.actions != null)
return false;
} else if (!this.actions.equals(other.actions))
return false;
return true;
}

Expand All @@ -188,6 +205,7 @@ public int hashCode() {
result = prime * result + ((this.message== null) ? 0 : this.message.hashCode());
result = prime * result + ((this.relatedInformation== null) ? 0 : this.relatedInformation.hashCode());
result = prime * result + ((this.dataKind== null) ? 0 : this.dataKind.hashCode());
return prime * result + ((this.data== null) ? 0 : this.data.hashCode());
result = prime * result + ((this.data== null) ? 0 : this.data.hashCode());
return prime * result + ((this.actions== null) ? 0 : this.actions.hashCode());
}
}
81 changes: 81 additions & 0 deletions bsp4j/src/main/xtend-gen/ch/epfl/scala/bsp4j/TextEdit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ch.epfl.scala.bsp4j;

import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.util.Preconditions;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

@SuppressWarnings("all")
public class TextEdit {
@NonNull
private Range range;

@NonNull
private String newText;

public TextEdit(@NonNull final Range range, @NonNull final String newText) {
this.range = range;
this.newText = newText;
}

@Pure
@NonNull
public Range getRange() {
return this.range;
}

public void setRange(@NonNull final Range range) {
this.range = Preconditions.checkNotNull(range, "range");
}

@Pure
@NonNull
public String getNewText() {
return this.newText;
}

public void setNewText(@NonNull final String newText) {
this.newText = Preconditions.checkNotNull(newText, "newText");
}

@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("range", this.range);
b.add("newText", this.newText);
return b.toString();
}

@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TextEdit other = (TextEdit) obj;
if (this.range == null) {
if (other.range != null)
return false;
} else if (!this.range.equals(other.range))
return false;
if (this.newText == null) {
if (other.newText != null)
return false;
} else if (!this.newText.equals(other.newText))
return false;
return true;
}

@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.range== null) ? 0 : this.range.hashCode());
return prime * result + ((this.newText== null) ? 0 : this.newText.hashCode());
}
}
55 changes: 55 additions & 0 deletions bsp4j/src/main/xtend-gen/ch/epfl/scala/bsp4j/WorkspaceEdit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ch.epfl.scala.bsp4j;

import java.util.List;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

@SuppressWarnings("all")
public class WorkspaceEdit {
private List<TextEdit> changes;

public WorkspaceEdit(final List<TextEdit> changes) {
this.changes = changes;
}

@Pure
public List<TextEdit> getChanges() {
return this.changes;
}

public void setChanges(final List<TextEdit> changes) {
this.changes = changes;
}

@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("changes", this.changes);
return b.toString();
}

@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
WorkspaceEdit other = (WorkspaceEdit) obj;
if (this.changes == null) {
if (other.changes != null)
return false;
} else if (!this.changes.equals(other.changes))
return false;
return true;
}

@Override
@Pure
public int hashCode() {
return 31 * 1 + ((this.changes== null) ? 0 : this.changes.hashCode());
}
}
33 changes: 32 additions & 1 deletion bsp4s/src/main/scala/ch/epfl/scala/bsp/Bsp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,36 @@ object DiagnosticRelatedInformation {
JsonCodecMaker.makeWithRequiredCollectionFields
}

final case class CodeAction(
title: String,
description: Option[String],
edit: Option[WorkspaceEdit]
)

object CodeAction {
implicit val codec: JsonValueCodec[CodeAction] =
JsonCodecMaker.makeWithRequiredCollectionFields
}

final case class WorkspaceEdit(
changes: Option[List[TextEdit]]
)

object WorkspaceEdit {
implicit val codec: JsonValueCodec[WorkspaceEdit] =
JsonCodecMaker.makeWithRequiredCollectionFields
}

final case class TextEdit(
range: Range,
newText: String
)

object TextEdit {
implicit val codec: JsonValueCodec[TextEdit] =
JsonCodecMaker.makeWithRequiredCollectionFields
}

final case class Diagnostic(
range: Range,
severity: Option[DiagnosticSeverity],
Expand All @@ -368,7 +398,8 @@ final case class Diagnostic(
message: String,
relatedInformation: Option[List[DiagnosticRelatedInformation]],
dataKind: Option[String],
data: Option[RawJson]
data: Option[RawJson],
actions: Option[List[CodeAction]]
)

object Diagnostic {
Expand Down
Loading

0 comments on commit 32c8f79

Please sign in to comment.