-
Notifications
You must be signed in to change notification settings - Fork 29
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
Support CodeAction resolve for Java code actions #299
Merged
angelozerr
merged 1 commit into
eclipse-lsp4mp:master
from
datho7561:171-codeaction-resolve-just-jdt
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...lipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/commons/CodeActionResolveData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4mp.commons; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.lsp4j.Range; | ||
|
||
/** | ||
* Represents additional data that is needed to resolve a code action. | ||
* | ||
* @author datho7561 | ||
*/ | ||
public class CodeActionResolveData { | ||
|
||
private String participantId; | ||
private String documentUri; | ||
|
||
private Range range; | ||
|
||
private Map<String, Object> extendedData; | ||
|
||
private boolean resourceOperationSupported; | ||
private boolean commandConfigurationUpdateSupported; | ||
|
||
/** | ||
* Make code action data will all fields nulled/false | ||
* | ||
* Needed for Gson | ||
*/ | ||
public CodeActionResolveData() { | ||
this(null, null, null, null, false, false); | ||
} | ||
|
||
public CodeActionResolveData(String documentUri, | ||
String participantId, | ||
Range range, | ||
Map<String, Object> extendedData, | ||
boolean resourceOperationSupported, | ||
boolean commandConfigurationUpdateSupported) { | ||
this.documentUri = documentUri; | ||
this.participantId = participantId; | ||
this.range = range; | ||
this.extendedData = extendedData; | ||
this.resourceOperationSupported = resourceOperationSupported; | ||
this.commandConfigurationUpdateSupported = commandConfigurationUpdateSupported; | ||
} | ||
|
||
/** | ||
* Returns the uri of the document that this code action applies to. | ||
* | ||
* @return the uri of the document that this code action applies to | ||
*/ | ||
public String getDocumentUri() { | ||
return this.documentUri; | ||
} | ||
|
||
/** | ||
* Returns the unique id of the IJavaCodeActionParticipant that can resolve the | ||
* text edits for this code action. | ||
* | ||
* @return the unique id of the IJavaCodeActionParticipant that can resolve the | ||
* text edits for this code action | ||
*/ | ||
public String getParticipantId() { | ||
return this.participantId; | ||
} | ||
|
||
/** | ||
* Returns the range for which this CodeAction is applicable for. | ||
* | ||
* @return the range for which this CodeAction is applicable for | ||
*/ | ||
public Range getRange() { | ||
return this.range; | ||
} | ||
|
||
/** | ||
* Returns the entry in the extended data for the given key | ||
* | ||
* @param key the key to get the entry for | ||
* @return the entry in the extended data for the given key | ||
*/ | ||
public Object getExtendedDataEntry(String key) { | ||
return extendedData.get(key); | ||
} | ||
|
||
/** | ||
* Returns true if the client supports resource operations and false otherwise. | ||
* | ||
* @return true if the client supports resource operations and false otherwise | ||
*/ | ||
public boolean isResourceOperationSupported() { | ||
return this.resourceOperationSupported; | ||
} | ||
|
||
/** | ||
* Returns true if the client implements a command that allows the language | ||
* server to update preferences, and false otherwise. | ||
* | ||
* @return true if the client implements a command that allows the language | ||
* server to update preferences, and false otherwise | ||
*/ | ||
public boolean isCommandConfigurationUpdateSupported() { | ||
return this.commandConfigurationUpdateSupported; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (!(other instanceof CodeActionResolveData)) { | ||
return false; | ||
} | ||
CodeActionResolveData that = (CodeActionResolveData) other; | ||
return Objects.equals(this.documentUri, that.documentUri) | ||
&& Objects.equals(this.participantId, that.participantId) | ||
&& Objects.equals(this.range, that.range) | ||
&& Objects.equals(this.extendedData, that.extendedData) | ||
&& Objects.equals(this.resourceOperationSupported, that.resourceOperationSupported) | ||
&& Objects.equals(this.commandConfigurationUpdateSupported, that.commandConfigurationUpdateSupported); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...g.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/commons/utils/JSONUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4mp.commons.utils; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler; | ||
import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonElement; | ||
|
||
/** | ||
* Utilities for working with JSON that has been converted to an Object using Gson. | ||
*/ | ||
public class JSONUtility { | ||
|
||
private JSONUtility() { | ||
} | ||
|
||
private static final Gson LSP4J_GSON = new MessageJsonHandler(new HashMap<>()).getGson(); | ||
|
||
private static final Gson EITHER_GSON = new GsonBuilder() // | ||
.registerTypeAdapterFactory(new EitherTypeAdapter.Factory()).create(); | ||
|
||
/** | ||
* Converts the given Object to the given class using lsp4j's GSON logic. | ||
* | ||
* @param <T> the class to convert the Object to | ||
* @param object the object to convert | ||
* @param clazz the class to convert the Object to | ||
* @return the given Object converted to the given class using lsp4j's GSON | ||
* logic | ||
*/ | ||
public static <T> T toModel(Object object, Class<T> clazz) { | ||
return toModel(getLsp4jGson(), object, clazz); | ||
} | ||
|
||
/** | ||
* Converts the given Object to the given class using the given GSON instance. | ||
* | ||
* @param <T> the class to convert the Object to | ||
* @param gson the gson instance to use to perform the conversion | ||
* @param object the object to convert | ||
* @param clazz the class to convert the Object to | ||
* @return the given Object converted to the given class using the given GSON | ||
* instance | ||
*/ | ||
public static <T> T toModel(Gson gson, Object object, Class<T> clazz) { | ||
if (object == null) { | ||
return null; | ||
} | ||
if (clazz == null) { | ||
throw new IllegalArgumentException("Class can not be null"); | ||
} | ||
if (object instanceof JsonElement) { | ||
return gson.fromJson((JsonElement) object, clazz); | ||
} | ||
if (clazz.isInstance(object)) { | ||
return clazz.cast(object); | ||
} | ||
// if nothing else works, try serializing and deserializing again | ||
return gson.fromJson(gson.toJson(object), clazz); | ||
} | ||
|
||
/** | ||
* Returns a Gson instance configured similarly to the instance lsp4j uses. | ||
* | ||
* @return a Gson instance configured similarly to the instance lsp4j uses | ||
*/ | ||
public static Gson getLsp4jGson() { | ||
return LSP4J_GSON; | ||
} | ||
|
||
/** | ||
* Returns a Gson instance with most of the default options, but with the | ||
* ability to parse {@code org.eclipse.lsp4j.Either}. | ||
* | ||
* @return a Gson instance with most of the default options, but with the | ||
* ability to parse {@code org.eclipse.lsp4j.Either} | ||
*/ | ||
public static Gson getEitherGson() { | ||
return EITHER_GSON; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't new, I just copied it over from microprofile.ls