diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend index 2db997a53..ac601e9f6 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend @@ -57,7 +57,10 @@ class WorkspaceEditCapabilities { /** * The client supports resource changes * in `WorkspaceEdit`s. + * + * @deprecated Since LSP introduces resource operations, use {link #resourceOperations} */ + @Deprecated @Beta Boolean resourceChanges /** @@ -75,6 +78,7 @@ class WorkspaceEditCapabilities { new() { } + @Deprecated new(Boolean documentChanges) { this.documentChanges = documentChanges } @@ -685,12 +689,24 @@ class ColorProviderCapabilities extends DynamicRegistrationCapabilities { */ @JsonRpcData class RenameCapabilities extends DynamicRegistrationCapabilities { + + /** + * Client supports testing for validity of rename operations + * before execution. + */ + Boolean prepareSupport + new() { } new(Boolean dynamicRegistration) { super(dynamicRegistration) } + + new(Boolean prepareSupport, Boolean dynamicRegistration) { + super(dynamicRegistration) + this.prepareSupport = prepareSupport + } } /** @@ -1821,6 +1837,17 @@ class SaveOptions { } } +/** + * Rename options + */ +@JsonRpcData +class RenameOptions extends StaticRegistrationOptions { + /** + * Renames should be checked and tested before being executed. + */ + Boolean prepareProvider; +} + /** * Color provider Options */ @@ -2535,11 +2562,14 @@ class ReferenceParams extends TextDocumentPositionParams { @JsonRpcData class PrepareRenameResult { /** - * The capabilities the language server provides. + * The range of the string to rename */ @NonNull Range range + /* + * A placeholder text of the string content to be renamed. + */ @NonNull String placeholder @@ -2586,24 +2616,6 @@ class RenameParams { } } -/** - * Rename options - */ -@JsonRpcData -class RenameOptions { - /** - * Renames should be checked and tested before being executed. - */ - Boolean prepareProvider; - - new() { - } - - new(Boolean prepareProvider) { - this.prepareProvider = prepareProvider - } -} - @JsonRpcData class ServerCapabilities { /** @@ -3315,7 +3327,7 @@ class TextDocumentEdit { @JsonRpcData @JsonAdapter(ResourceOperationTypeAdapter) -class ResourceOperation { +abstract class ResourceOperation { @NonNull String kind; @@ -3506,9 +3518,12 @@ class DeleteFile extends ResourceOperation { * If both current and newUri has valid values this is considered to be a move operation. * If current has a valid value while newUri is null it is treated as a delete operation. * If current is null and newUri has a valid value a create operation is executed. + * + * @deprecated As LSP introduces resource operation, use the {@link ResourceOperation} instead. */ @JsonRpcData @Beta +@Deprecated class ResourceChange { /** @@ -3556,9 +3571,12 @@ class WorkspaceEdit { * rename, move, delete or content change. * These changes are applied in the order that they are supplied, * however clients may group the changes for optimization + * + * @deprecated Since LSP introduces resource operations, use the {@link #documentChanges} instead */ @Beta @JsonAdapter(ResourceChangeListAdapter) + @Deprecated List> resourceChanges new() { @@ -3573,16 +3591,6 @@ class WorkspaceEdit { new(List> documentChanges) { this.documentChanges = documentChanges } - - /** - * @deprecated According to the protocol documentation, it doesn't make sense to send both - * changes and documentChanges - */ - @Deprecated - new(Map> changes, List> documentChanges) { - this.changes = changes - this.documentChanges = documentChanges - } } /** diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java index 68d9474e9..5affbd7fe 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java @@ -28,6 +28,7 @@ import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; +@Deprecated public class DocumentChangeListAdapter implements TypeAdapterFactory { private static final TypeToken> ELEMENT_TYPE diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.java new file mode 100644 index 000000000..5f4e42328 --- /dev/null +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.java @@ -0,0 +1,45 @@ +/****************************************************************************** + * Copyright (c) 2018 Microsoft Corporation 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 Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + ******************************************************************************/ +package org.eclipse.lsp4j.adapters; + +import java.util.ArrayList; +import java.util.function.Predicate; + +import org.eclipse.lsp4j.PrepareRenameResult; +import org.eclipse.lsp4j.Range; +import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapter; +import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter; +import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter.PropertyChecker; +import org.eclipse.lsp4j.jsonrpc.messages.Either; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; + +public class PrepareRenameResponseAdapter implements TypeAdapterFactory { + + private static final TypeToken> ELEMENT_TYPE + = new TypeToken>() {}; + + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + Predicate leftChecker = new PropertyChecker("start"); + Predicate rightChecker = new PropertyChecker("range"); + TypeAdapter> elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, + leftChecker, rightChecker); + return (TypeAdapter) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter, + ArrayList::new); + } +} diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ResourceOperationTypeAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ResourceOperationTypeAdapter.java index 7901537f8..36e235dc0 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ResourceOperationTypeAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ResourceOperationTypeAdapter.java @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2018 TypeFox and others. + * Copyright (c) 2018 Microsoft Corporation 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 @@ -23,6 +23,8 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; @@ -44,13 +46,11 @@ public TypeAdapter create(Gson gson, TypeToken type) { private static class InnerResourceOperationTypeAdapter extends TypeAdapter { - TypeAdapter jsonElementAdapter; TypeAdapter createFileAdapter; TypeAdapter deleteFileAdapter; TypeAdapter renameFileAdapter; InnerResourceOperationTypeAdapter(TypeAdapterFactory factory, Gson gson) { - jsonElementAdapter = gson.getAdapter(JsonElement.class); createFileAdapter = gson.getDelegateAdapter(factory, TypeToken.get(CreateFile.class)); deleteFileAdapter = gson.getDelegateAdapter(factory, TypeToken.get(DeleteFile.class)); renameFileAdapter = gson.getDelegateAdapter(factory, TypeToken.get(RenameFile.class)); @@ -58,7 +58,6 @@ private static class InnerResourceOperationTypeAdapter extends TypeAdapter> foldingRange(FoldingRangeRequestPa * Since version 3.12.0 */ @JsonRequest + @ResponseJsonAdapter(PrepareRenameResponseAdapter.class) default CompletableFuture> prepareRename(TextDocumentPositionParams params) { throw new UnsupportedOperationException(); } - } diff --git a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/PrepareRenameResult.java b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/PrepareRenameResult.java index 1a0f7915d..417b21634 100644 --- a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/PrepareRenameResult.java +++ b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/PrepareRenameResult.java @@ -19,11 +19,14 @@ @SuppressWarnings("all") public class PrepareRenameResult { /** - * The capabilities the language server provides. + * The range of the string to rename */ @NonNull private Range range; + /** + * A placeholder text of the string content to be renamed. + */ @NonNull private String placeholder; @@ -36,7 +39,7 @@ public PrepareRenameResult(@NonNull final Range range, @NonNull final String pla } /** - * The capabilities the language server provides. + * The range of the string to rename */ @Pure @NonNull @@ -45,18 +48,24 @@ public Range getRange() { } /** - * The capabilities the language server provides. + * The range of the string to rename */ public void setRange(@NonNull final Range range) { this.range = range; } + /** + * A placeholder text of the string content to be renamed. + */ @Pure @NonNull public String getPlaceholder() { return this.placeholder; } + /** + * A placeholder text of the string content to be renamed. + */ public void setPlaceholder(@NonNull final String placeholder) { this.placeholder = placeholder; } diff --git a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameCapabilities.java b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameCapabilities.java index 90b041f78..55f621d72 100644 --- a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameCapabilities.java +++ b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameCapabilities.java @@ -20,6 +20,12 @@ */ @SuppressWarnings("all") public class RenameCapabilities extends DynamicRegistrationCapabilities { + /** + * Client supports testing for validity of rename operations + * before execution. + */ + private Boolean prepareSupport; + public RenameCapabilities() { } @@ -27,10 +33,33 @@ public RenameCapabilities(final Boolean dynamicRegistration) { super(dynamicRegistration); } + public RenameCapabilities(final Boolean prepareSupport, final Boolean dynamicRegistration) { + super(dynamicRegistration); + this.prepareSupport = prepareSupport; + } + + /** + * Client supports testing for validity of rename operations + * before execution. + */ + @Pure + public Boolean getPrepareSupport() { + return this.prepareSupport; + } + + /** + * Client supports testing for validity of rename operations + * before execution. + */ + public void setPrepareSupport(final Boolean prepareSupport) { + this.prepareSupport = prepareSupport; + } + @Override @Pure public String toString() { ToStringBuilder b = new ToStringBuilder(this); + b.add("prepareSupport", this.prepareSupport); b.add("dynamicRegistration", getDynamicRegistration()); return b.toString(); } @@ -46,12 +75,18 @@ public boolean equals(final Object obj) { return false; if (!super.equals(obj)) return false; + RenameCapabilities other = (RenameCapabilities) obj; + if (this.prepareSupport == null) { + if (other.prepareSupport != null) + return false; + } else if (!this.prepareSupport.equals(other.prepareSupport)) + return false; return true; } @Override @Pure public int hashCode() { - return super.hashCode(); + return 31 * super.hashCode() + ((this.prepareSupport== null) ? 0 : this.prepareSupport.hashCode()); } } diff --git a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameOptions.java b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameOptions.java index be05ce0c4..90122b519 100644 --- a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameOptions.java +++ b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/RenameOptions.java @@ -11,6 +11,7 @@ */ package org.eclipse.lsp4j; +import org.eclipse.lsp4j.StaticRegistrationOptions; import org.eclipse.xtext.xbase.lib.Pure; import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; @@ -18,19 +19,12 @@ * Rename options */ @SuppressWarnings("all") -public class RenameOptions { +public class RenameOptions extends StaticRegistrationOptions { /** * Renames should be checked and tested before being executed. */ private Boolean prepareProvider; - public RenameOptions() { - } - - public RenameOptions(final Boolean prepareProvider) { - this.prepareProvider = prepareProvider; - } - /** * Renames should be checked and tested before being executed. */ @@ -51,6 +45,8 @@ public void setPrepareProvider(final Boolean prepareProvider) { public String toString() { ToStringBuilder b = new ToStringBuilder(this); b.add("prepareProvider", this.prepareProvider); + b.add("id", getId()); + b.add("documentSelector", getDocumentSelector()); return b.toString(); } @@ -63,6 +59,8 @@ public boolean equals(final Object obj) { return false; if (getClass() != obj.getClass()) return false; + if (!super.equals(obj)) + return false; RenameOptions other = (RenameOptions) obj; if (this.prepareProvider == null) { if (other.prepareProvider != null) @@ -75,6 +73,6 @@ public boolean equals(final Object obj) { @Override @Pure public int hashCode() { - return 31 * 1 + ((this.prepareProvider== null) ? 0 : this.prepareProvider.hashCode()); + return 31 * super.hashCode() + ((this.prepareProvider== null) ? 0 : this.prepareProvider.hashCode()); } } diff --git a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceChange.java b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceChange.java index 584eaed49..6e3990486 100644 --- a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceChange.java +++ b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceChange.java @@ -21,8 +21,11 @@ * If both current and newUri has valid values this is considered to be a move operation. * If current has a valid value while newUri is null it is treated as a delete operation. * If current is null and newUri has a valid value a create operation is executed. + * + * @deprecated As LSP introduces resource operation, use the {@link ResourceOperation} instead. */ @Beta +@Deprecated @SuppressWarnings("all") public class ResourceChange { /** diff --git a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceOperation.java b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceOperation.java index df67528a8..c618095d2 100644 --- a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceOperation.java +++ b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ResourceOperation.java @@ -19,7 +19,7 @@ @JsonAdapter(ResourceOperationTypeAdapter.class) @SuppressWarnings("all") -public class ResourceOperation { +public abstract class ResourceOperation { @NonNull private String kind; diff --git a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEdit.java b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEdit.java index c873750ec..966adc76a 100644 --- a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEdit.java +++ b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEdit.java @@ -53,9 +53,12 @@ public class WorkspaceEdit { * rename, move, delete or content change. * These changes are applied in the order that they are supplied, * however clients may group the changes for optimization + * + * @deprecated Since LSP introduces resource operations, use the {@link #documentChanges} instead */ @Beta @JsonAdapter(ResourceChangeListAdapter.class) + @Deprecated private List> resourceChanges; public WorkspaceEdit() { @@ -71,16 +74,6 @@ public WorkspaceEdit(final List> doc this.documentChanges = documentChanges; } - /** - * @deprecated According to the protocol documentation, it doesn't make sense to send both - * changes and documentChanges - */ - @Deprecated - public WorkspaceEdit(final Map> changes, final List> documentChanges) { - this.changes = changes; - this.documentChanges = documentChanges; - } - /** * Holds changes to existing resources. */ @@ -121,8 +114,11 @@ public void setDocumentChanges(final List> getResourceChanges() { return this.resourceChanges; } @@ -133,7 +129,10 @@ public List> getResourceChanges() { * rename, move, delete or content change. * These changes are applied in the order that they are supplied, * however clients may group the changes for optimization + * + * @deprecated Since LSP introduces resource operations, use the {@link #documentChanges} instead */ + @Deprecated public void setResourceChanges(final List> resourceChanges) { this.resourceChanges = resourceChanges; } diff --git a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEditCapabilities.java b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEditCapabilities.java index c14a57eda..cd4c5924e 100644 --- a/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEditCapabilities.java +++ b/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/WorkspaceEditCapabilities.java @@ -31,7 +31,10 @@ public class WorkspaceEditCapabilities { /** * The client supports resource changes * in `WorkspaceEdit`s. + * + * @deprecated Since LSP introduces resource operations, use {link #resourceOperations} */ + @Deprecated @Beta private Boolean resourceChanges; @@ -50,6 +53,7 @@ public class WorkspaceEditCapabilities { public WorkspaceEditCapabilities() { } + @Deprecated public WorkspaceEditCapabilities(final Boolean documentChanges) { this.documentChanges = documentChanges; } @@ -72,8 +76,11 @@ public void setDocumentChanges(final Boolean documentChanges) { /** * The client supports resource changes * in `WorkspaceEdit`s. + * + * @deprecated Since LSP introduces resource operations, use {link #resourceOperations} */ @Pure + @Deprecated public Boolean getResourceChanges() { return this.resourceChanges; } @@ -81,7 +88,10 @@ public Boolean getResourceChanges() { /** * The client supports resource changes * in `WorkspaceEdit`s. + * + * @deprecated Since LSP introduces resource operations, use {link #resourceOperations} */ + @Deprecated public void setResourceChanges(final Boolean resourceChanges) { this.resourceChanges = resourceChanges; }