Skip to content

Commit

Permalink
Address review feedback.
Browse files Browse the repository at this point in the history
Signed-off-by: Yaohai Zheng <[email protected]>
  • Loading branch information
yaohaizh committed Oct 30, 2018
1 parent 954371c commit 43a0e07
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 61 deletions.
68 changes: 38 additions & 30 deletions org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -75,6 +78,7 @@ class WorkspaceEditCapabilities {
new() {
}

@Deprecated
new(Boolean documentChanges) {
this.documentChanges = documentChanges
}
Expand Down Expand Up @@ -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
}
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -3315,7 +3327,7 @@ class TextDocumentEdit {

@JsonRpcData
@JsonAdapter(ResourceOperationTypeAdapter)
class ResourceOperation {
abstract class ResourceOperation {

@NonNull
String kind;
Expand Down Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -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<Either<ResourceChange, TextDocumentEdit>> resourceChanges

new() {
Expand All @@ -3573,16 +3591,6 @@ class WorkspaceEdit {
new(List<Either<TextDocumentEdit, ResourceOperation>> documentChanges) {
this.documentChanges = documentChanges
}

/**
* @deprecated According to the protocol documentation, it doesn't make sense to send both
* changes and documentChanges
*/
@Deprecated
new(Map<String, List<TextEdit>> changes, List<Either<TextDocumentEdit, ResourceOperation>> documentChanges) {
this.changes = changes
this.documentChanges = documentChanges
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Either<TextDocumentEdit, ResourceOperation>> ELEMENT_TYPE
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Either<Range, PrepareRenameResult>> ELEMENT_TYPE
= new TypeToken<Either<Range, PrepareRenameResult>>() {};

@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Predicate<JsonElement> leftChecker = new PropertyChecker("start");
Predicate<JsonElement> rightChecker = new PropertyChecker("range");
TypeAdapter<Either<Range, PrepareRenameResult>> elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE,
leftChecker, rightChecker);
return (TypeAdapter<T>) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter,
ArrayList::new);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -44,21 +46,18 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {

private static class InnerResourceOperationTypeAdapter extends TypeAdapter<ResourceOperation> {

TypeAdapter<JsonElement> jsonElementAdapter;
TypeAdapter<CreateFile> createFileAdapter;
TypeAdapter<DeleteFile> deleteFileAdapter;
TypeAdapter<RenameFile> 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));
}

@Override
public void write(JsonWriter out, ResourceOperation value) throws IOException {

if (value.getClass().isAssignableFrom(CreateFile.class)) {
createFileAdapter.write(out, (CreateFile) value);
} else if (value.getClass().isAssignableFrom(DeleteFile.class)) {
Expand All @@ -70,7 +69,7 @@ public void write(JsonWriter out, ResourceOperation value) throws IOException {

@Override
public ResourceOperation read(JsonReader in) throws IOException {
JsonObject objectJson = jsonElementAdapter.read(in).getAsJsonObject();
JsonObject objectJson = new JsonParser().parse(in).getAsJsonObject();
JsonElement value = objectJson.get("kind");
if (value != null && value.isJsonPrimitive()) {
String kindValue = value.getAsString();
Expand All @@ -84,7 +83,8 @@ public ResourceOperation read(JsonReader in) throws IOException {
}
}

return null;
throw new JsonParseException(
"The ResourceOperation object either has null \"kind\" value or the \"kind\" value is not valid.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.adapters.CodeActionResponseAdapter;
import org.eclipse.lsp4j.adapters.DocumentSymbolResponseAdapter;
import org.eclipse.lsp4j.adapters.PrepareRenameResponseAdapter;
import org.eclipse.lsp4j.jsonrpc.json.ResponseJsonAdapter;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
Expand Down Expand Up @@ -384,8 +385,8 @@ default CompletableFuture<List<FoldingRange>> foldingRange(FoldingRangeRequestPa
* Since version 3.12.0
*/
@JsonRequest
@ResponseJsonAdapter(PrepareRenameResponseAdapter.class)
default CompletableFuture<Either<Range, PrepareRenameResult>> prepareRename(TextDocumentPositionParams params) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit 43a0e07

Please sign in to comment.