Skip to content

Commit

Permalink
eclipse-lsp4jGH-317: Adjusted the textDocument/callHierarchy to the…
Browse files Browse the repository at this point in the history
… spec.

Closes eclipse-lsp4j#317.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
  • Loading branch information
Akos Kitta authored and vladdu committed Jan 26, 2021
1 parent f4fbb15 commit 5c17688
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 403 deletions.
66 changes: 14 additions & 52 deletions org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,6 @@ class TypeHierarchyCapabilities extends DynamicRegistrationCapabilities {

/**
* Capabilities specific to the {@code textDocument/callHierarchy}.
*
* <p>
* <b>Note:</b> the <a href=
* "https://github.com/Microsoft/vscode-languageserver-node/pull/420">{@code textDocument/callHierarchy}
* language feature</a> is not yet part of the official LSP specification.
*/
@Beta
@JsonRpcData
Expand Down Expand Up @@ -3048,11 +3043,6 @@ class ServerCapabilities {

/**
* The server provides Call Hierarchy support.
*
* <p>
* <b>Note:</b> the <a href=
* "https://github.com/Microsoft/vscode-languageserver-node/pull/420">{@code textDocument/callHierarchy}
* language feature</a> is not yet part of the official LSP specification.
*/
@Beta
Either<Boolean, StaticRegistrationOptions> callHierarchyProvider
Expand Down Expand Up @@ -4809,47 +4799,44 @@ class SemanticHighlightingInformation {
}

/**
* The parameters of a {@code textDocument/callHierarchy} request.
* Returns a collection of calls from one symbol to another.
*/
@Beta
@JsonRpcData
class CallHierarchyParams extends TextDocumentPositionParams {

/**
* The number of levels to resolve.
*/
int resolve

/**
* The direction of calls to resolve.
*/
@NonNull
CallHierarchyDirection direction

}

/**
* The parameters of a {@code callHierarchy/resolve} request.
* Each {@code CallHierarchyCall} object defines a call from one {@code CallHierarchySymbol} to another.
*/
@Beta
@JsonRpcData
class ResolveCallHierarchyItemParams {
class CallHierarchyCall {

/**
* Unresolved item.
* The source range of the reference. The range is a sub range of the {@link CallHierarchyCall#getFrom from} symbol range.
*/
@NonNull
CallHierarchyItem item
Range range

/**
* The number of levels to resolve.
* The symbol that contains the reference.
*/
int resolve
@NonNull
CallHierarchySymbol from

/**
* The direction of calls to resolve.
* The symbol that is referenced.
*/
@NonNull
CallHierarchyDirection direction
CallHierarchySymbol to

}

Expand All @@ -4858,7 +4845,7 @@ class ResolveCallHierarchyItemParams {
*/
@Beta
@JsonRpcData
class CallHierarchyItem {
class CallHierarchySymbol {

/**
* The name of the symbol targeted by the call hierarchy request.
Expand All @@ -4883,11 +4870,6 @@ class CallHierarchyItem {
@NonNull
String uri

/**
* {@code true} if the hierarchy item is deprecated. Otherwise, {@code false}. It is {@code false} by default.
*/
Boolean deprecated

/**
* The range enclosing this symbol not including leading/trailing whitespace but everything else
* like comments. This information is typically used to determine if the the clients cursor is
Expand All @@ -4898,29 +4880,9 @@ class CallHierarchyItem {

/**
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
* Must be contained by the the {@code range}.
* Must be contained by the the {@link CallHierarchySymbol#getRange range}.
*/
@NonNull
Range selectionRange

/**
* The actual locations of incoming (or outgoing) calls to (or from) a callable identified by this item.
*
* <b>Note</b>: undefined in root item.
*/
List<Location> callLocations

/**
* List of incoming (or outgoing) calls to (or from) a callable identified by this item.
*
* <b>Note</b>: if undefined, this item is unresolved.
*/
List<CallHierarchyItem> calls

/**
* Optional data to identify an item in a resolve request.
*/
@JsonAdapter(JsonElementTypeAdapter.Factory)
Object data

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.CallHierarchyItem;
import org.eclipse.lsp4j.CallHierarchyParams;
import org.eclipse.lsp4j.CallHierarchySymbol;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.CodeLens;
Expand Down Expand Up @@ -50,7 +50,6 @@
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.ReferenceParams;
import org.eclipse.lsp4j.RenameParams;
import org.eclipse.lsp4j.ResolveCallHierarchyItemParams;
import org.eclipse.lsp4j.ResolveTypeHierarchyItemParams;
import org.eclipse.lsp4j.SignatureHelp;
import org.eclipse.lsp4j.SymbolInformation;
Expand Down Expand Up @@ -467,37 +466,12 @@ default CompletableFuture<TypeHierarchyItem> resolveTypeHierarchy(ResolveTypeHie
}

/**
* Request to request the call hierarchy at a given text document position.
*
* The optional request's parameter defines the maximum number of levels to
* {@link CallHierarchyParams#getResolve() resolve} by this request. Unresolved
* items can be resolved in subsequent {@code callHierarchy/resolve} requests.
*
* <p>
* <b>Note:</b> the <a href=
* "https://github.com/Microsoft/vscode-languageserver-node/pull/420">{@code textDocument/callHierarchy}
* language feature</a> is not yet part of the official LSP specification.
* The {@code textDocument/callHierarchy} request is sent from the client to the server to request
* the call hierarchy for a symbol defined (or referenced) at the given text document position.
*/
@Beta
@JsonRequest
default CompletableFuture<CallHierarchyItem> callHierarchy(CallHierarchyParams params) {
throw new UnsupportedOperationException();
}

/**
* Request to resolve a call hierarchy item.
*
* The request's parameter is of type {@link ResolveCallHierarchyItemParams}.
* The response is of type {@link CallHierarchyItem}.
*
* <p>
* <b>Note:</b> the <a href=
* "https://github.com/Microsoft/vscode-languageserver-node/pull/420">{@code textDocument/callHierarchy}
* language feature</a> is not yet part of the official LSP specification.
*/
@Beta
@JsonRequest(value = "callHierarchy/resolve", useSegment = false)
default CompletableFuture<CallHierarchyItem> resolveCallHierarchy(ResolveCallHierarchyItemParams params) {
default CompletableFuture<CallHierarchySymbol> callHierarchy(CallHierarchyParams params) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* Copyright (c) 2016-2018 TypeFox 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;

import com.google.common.annotations.Beta;
import org.eclipse.lsp4j.CallHierarchySymbol;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

/**
* Each {@code CallHierarchyCall} object defines a call from one {@code CallHierarchySymbol} to another.
*/
@Beta
@SuppressWarnings("all")
public class CallHierarchyCall {
/**
* The source range of the reference. The range is a sub range of the {@link CallHierarchyCall#getFrom from} symbol range.
*/
@NonNull
private Range range;

/**
* The symbol that contains the reference.
*/
@NonNull
private CallHierarchySymbol from;

/**
* The symbol that is referenced.
*/
@NonNull
private CallHierarchySymbol to;

/**
* The source range of the reference. The range is a sub range of the {@link CallHierarchyCall#getFrom from} symbol range.
*/
@Pure
@NonNull
public Range getRange() {
return this.range;
}

/**
* The source range of the reference. The range is a sub range of the {@link CallHierarchyCall#getFrom from} symbol range.
*/
public void setRange(@NonNull final Range range) {
if (range == null) {
throw new IllegalArgumentException("Property must not be null: range");
}
this.range = range;
}

/**
* The symbol that contains the reference.
*/
@Pure
@NonNull
public CallHierarchySymbol getFrom() {
return this.from;
}

/**
* The symbol that contains the reference.
*/
public void setFrom(@NonNull final CallHierarchySymbol from) {
if (from == null) {
throw new IllegalArgumentException("Property must not be null: from");
}
this.from = from;
}

/**
* The symbol that is referenced.
*/
@Pure
@NonNull
public CallHierarchySymbol getTo() {
return this.to;
}

/**
* The symbol that is referenced.
*/
public void setTo(@NonNull final CallHierarchySymbol to) {
if (to == null) {
throw new IllegalArgumentException("Property must not be null: to");
}
this.to = to;
}

@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("range", this.range);
b.add("from", this.from);
b.add("to", this.to);
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;
CallHierarchyCall other = (CallHierarchyCall) obj;
if (this.range == null) {
if (other.range != null)
return false;
} else if (!this.range.equals(other.range))
return false;
if (this.from == null) {
if (other.from != null)
return false;
} else if (!this.from.equals(other.from))
return false;
if (this.to == null) {
if (other.to != null)
return false;
} else if (!this.to.equals(other.to))
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());
result = prime * result + ((this.from== null) ? 0 : this.from.hashCode());
return prime * result + ((this.to== null) ? 0 : this.to.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

/**
* Capabilities specific to the {@code textDocument/callHierarchy}.
*
* <p>
* <b>Note:</b> the <a href=
* "https://github.com/Microsoft/vscode-languageserver-node/pull/420">{@code textDocument/callHierarchy}
* language feature</a> is not yet part of the official LSP specification.
*/
@Beta
@SuppressWarnings("all")
Expand Down
Loading

0 comments on commit 5c17688

Please sign in to comment.