Skip to content

Commit

Permalink
eclipse-lsp4jGH-272: Updated the API to support type hierarchies.
Browse files Browse the repository at this point in the history
 - Added optional `uri` property to the `DocumentSymbol`.
 - Added methods for super- and subtype hierarchies.

Closes: eclipse-lsp4j#272

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Oct 9, 2018
1 parent a56e2cd commit 08d3bc1
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 4 deletions.
45 changes: 44 additions & 1 deletion org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ class FoldingRangeCapabilities extends DynamicRegistrationCapabilities {
/**
* Capabilities specific to {@code textDocument/semanticHighlighting}.
*/
@Beta
@JsonRpcData
class SemanticHighlightingCapabilities {
/**
Expand All @@ -735,6 +736,27 @@ class SemanticHighlightingCapabilities {
}
}

/**
* Capabilities specific to the {@code textDocument/superTypes} and {@code textDocument/subTypes} LS methods.
*/
@Beta
@JsonRpcData
class TypeHierarchyCapabilities {

/**
* The language client supports super- and subtype hierarchies.
*/
Boolean typeHierarchy

new() {
}

new(Boolean typeHierarchy) {
this.typeHierarchy = typeHierarchy
}

}

/**
* Text document specific client capabilities.
*/
Expand Down Expand Up @@ -849,7 +871,14 @@ class TextDocumentClientCapabilities {
/**
* Capabilities specific to {@code textDocument/semanticHighlighting}.
*/
@Beta
SemanticHighlightingCapabilities semanticHighlightingCapabilities

/**
* Capabilities specific to {@code textDocument/superTypes} and {@code textDocument/subTypes}.
*/
@Beta
TypeHierarchyCapabilities typeHierarchyCapabilities
}

/**
Expand Down Expand Up @@ -2678,7 +2707,13 @@ class ServerCapabilities {
/**
* Semantic highlighting server capabilities.
*/
SemanticHighlightingServerCapabilities semanticHighlighting;
SemanticHighlightingServerCapabilities semanticHighlighting

/**
* Server capability for calculating super- and subtype hierarchies.
* The LS supports the type hierarchy language feature, if this capability is set to {@code true}.
*/
Boolean typeHierarchy

/**
* Experimental server capabilities.
Expand Down Expand Up @@ -2892,6 +2927,14 @@ class DocumentSymbol {
@NonNull
Range selectionRange

/**
* The URI of the text document this symbol belongs to.
*
* <p> If not defined, it can be inferred from the context of the request. For example, when calling the {@code textDocument/documentSymbol}
* method, the {@code DocumentUri} (string) can be inferred from the request parameter: {@code DocumentSymbolParams.textDocument.uri}.
*/
String uri

/**
* More detail for this symbol, e.g the signature of a function. If not provided the
* name is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;

import com.google.common.annotations.Beta;

@JsonSegment("textDocument")
public interface TextDocumentService {

Expand Down Expand Up @@ -337,7 +339,7 @@ default CompletableFuture<DocumentLink> documentLinkResolve(DocumentLink params)
}

/**
* The document color request is sent from the client to the server to list all color refereces found in a given text
* The document color request is sent from the client to the server to list all color references found in a given text
* document. Along with the range, a color value in RGB is returned.
*
* Clients can use the result to decorate color references in an editor. For example:
Expand Down Expand Up @@ -374,5 +376,29 @@ default CompletableFuture<List<ColorPresentation>> colorPresentation(ColorPresen
default CompletableFuture<List<FoldingRange>> foldingRange(FoldingRangeRequestParams params) {
throw new UnsupportedOperationException();
}


/**
* The {@code textDocument/subTypes} request is sent from the client to the
* server to collect sub-type information for a type under the given
* {@link TextDocumentPositionParams text document position}. If no symbols can be
* found under the given position, returns with {@code null}.
*/
@Beta
@JsonRequest
default CompletableFuture<DocumentSymbol> subTypes(TextDocumentPositionParams params) {
throw new UnsupportedOperationException();
}

/**
* The {@code textDocument/superTypes} request is sent from the client to the
* server to collect super-type information for a type under the given
* {@link TextDocumentPositionParams text document position}. If no symbols can be
* found under the given position, returns with {@code null}.
*/
@Beta
@JsonRequest
default CompletableFuture<DocumentSymbol> superTypes(TextDocumentPositionParams params) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public class DocumentSymbol {
@NonNull
private Range selectionRange;

/**
* The URI of the text document this symbol belongs to.
*
* <p> If not defined, it can be inferred from the context of the request. For example, when calling the {@code textDocument/documentSymbol}
* method, the {@code DocumentUri} (string) can be inferred from the request parameter: {@code DocumentSymbolParams.textDocument.uri}.
*/
private String uri;

/**
* More detail for this symbol, e.g the signature of a function. If not provided the
* name is used.
Expand Down Expand Up @@ -165,6 +173,27 @@ public void setSelectionRange(@NonNull final Range selectionRange) {
this.selectionRange = selectionRange;
}

/**
* The URI of the text document this symbol belongs to.
*
* <p> If not defined, it can be inferred from the context of the request. For example, when calling the {@code textDocument/documentSymbol}
* method, the {@code DocumentUri} (string) can be inferred from the request parameter: {@code DocumentSymbolParams.textDocument.uri}.
*/
@Pure
public String getUri() {
return this.uri;
}

/**
* The URI of the text document this symbol belongs to.
*
* <p> If not defined, it can be inferred from the context of the request. For example, when calling the {@code textDocument/documentSymbol}
* method, the {@code DocumentUri} (string) can be inferred from the request parameter: {@code DocumentSymbolParams.textDocument.uri}.
*/
public void setUri(final String uri) {
this.uri = uri;
}

/**
* More detail for this symbol, e.g the signature of a function. If not provided the
* name is used.
Expand Down Expand Up @@ -220,6 +249,7 @@ public String toString() {
b.add("kind", this.kind);
b.add("range", this.range);
b.add("selectionRange", this.selectionRange);
b.add("uri", this.uri);
b.add("detail", this.detail);
b.add("deprecated", this.deprecated);
b.add("children", this.children);
Expand Down Expand Up @@ -256,6 +286,11 @@ public boolean equals(final Object obj) {
return false;
} else if (!this.selectionRange.equals(other.selectionRange))
return false;
if (this.uri == null) {
if (other.uri != null)
return false;
} else if (!this.uri.equals(other.uri))
return false;
if (this.detail == null) {
if (other.detail != null)
return false;
Expand Down Expand Up @@ -283,6 +318,7 @@ public int hashCode() {
result = prime * result + ((this.kind== null) ? 0 : this.kind.hashCode());
result = prime * result + ((this.range== null) ? 0 : this.range.hashCode());
result = prime * result + ((this.selectionRange== null) ? 0 : this.selectionRange.hashCode());
result = prime * result + ((this.uri== null) ? 0 : this.uri.hashCode());
result = prime * result + ((this.detail== null) ? 0 : this.detail.hashCode());
result = prime * result + ((this.deprecated== null) ? 0 : this.deprecated.hashCode());
return prime * result + ((this.children== null) ? 0 : this.children.hashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

/**
* Capabilities specific to {@code textDocument/semanticHighlighting}.
*/
@Beta
@SuppressWarnings("all")
public class SemanticHighlightingCapabilities {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public class ServerCapabilities {
*/
private SemanticHighlightingServerCapabilities semanticHighlighting;

/**
* Server capability for calculating super- and subtype hierarchies.
* The LS supports the type hierarchy language feature, if this capability is set to {@code true}.
*/
private Boolean typeHierarchy;

/**
* Experimental server capabilities.
*/
Expand Down Expand Up @@ -628,6 +634,23 @@ public void setSemanticHighlighting(final SemanticHighlightingServerCapabilities
this.semanticHighlighting = semanticHighlighting;
}

/**
* Server capability for calculating super- and subtype hierarchies.
* The LS supports the type hierarchy language feature, if this capability is set to {@code true}.
*/
@Pure
public Boolean getTypeHierarchy() {
return this.typeHierarchy;
}

/**
* Server capability for calculating super- and subtype hierarchies.
* The LS supports the type hierarchy language feature, if this capability is set to {@code true}.
*/
public void setTypeHierarchy(final Boolean typeHierarchy) {
this.typeHierarchy = typeHierarchy;
}

/**
* Experimental server capabilities.
*/
Expand Down Expand Up @@ -670,6 +693,7 @@ public String toString() {
b.add("executeCommandProvider", this.executeCommandProvider);
b.add("workspace", this.workspace);
b.add("semanticHighlighting", this.semanticHighlighting);
b.add("typeHierarchy", this.typeHierarchy);
b.add("experimental", this.experimental);
return b.toString();
}
Expand Down Expand Up @@ -799,6 +823,11 @@ public boolean equals(final Object obj) {
return false;
} else if (!this.semanticHighlighting.equals(other.semanticHighlighting))
return false;
if (this.typeHierarchy == null) {
if (other.typeHierarchy != null)
return false;
} else if (!this.typeHierarchy.equals(other.typeHierarchy))
return false;
if (this.experimental == null) {
if (other.experimental != null)
return false;
Expand Down Expand Up @@ -835,6 +864,7 @@ public int hashCode() {
result = prime * result + ((this.executeCommandProvider== null) ? 0 : this.executeCommandProvider.hashCode());
result = prime * result + ((this.workspace== null) ? 0 : this.workspace.hashCode());
result = prime * result + ((this.semanticHighlighting== null) ? 0 : this.semanticHighlighting.hashCode());
result = prime * result + ((this.typeHierarchy== null) ? 0 : this.typeHierarchy.hashCode());
return prime * result + ((this.experimental== null) ? 0 : this.experimental.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;
import org.eclipse.lsp4j.CodeActionCapabilities;
import org.eclipse.lsp4j.CodeLensCapabilities;
import org.eclipse.lsp4j.ColorProviderCapabilities;
Expand All @@ -32,6 +33,7 @@
import org.eclipse.lsp4j.SignatureHelpCapabilities;
import org.eclipse.lsp4j.SynchronizationCapabilities;
import org.eclipse.lsp4j.TypeDefinitionCapabilities;
import org.eclipse.lsp4j.TypeHierarchyCapabilities;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

Expand Down Expand Up @@ -149,8 +151,15 @@ public class TextDocumentClientCapabilities {
/**
* Capabilities specific to {@code textDocument/semanticHighlighting}.
*/
@Beta
private SemanticHighlightingCapabilities semanticHighlightingCapabilities;

/**
* Capabilities specific to {@code textDocument/superTypes} and {@code textDocument/subTypes}.
*/
@Beta
private TypeHierarchyCapabilities typeHierarchyCapabilities;

@Pure
public SynchronizationCapabilities getSynchronization() {
return this.synchronization;
Expand Down Expand Up @@ -478,6 +487,21 @@ public void setSemanticHighlightingCapabilities(final SemanticHighlightingCapabi
this.semanticHighlightingCapabilities = semanticHighlightingCapabilities;
}

/**
* Capabilities specific to {@code textDocument/superTypes} and {@code textDocument/subTypes}.
*/
@Pure
public TypeHierarchyCapabilities getTypeHierarchyCapabilities() {
return this.typeHierarchyCapabilities;
}

/**
* Capabilities specific to {@code textDocument/superTypes} and {@code textDocument/subTypes}.
*/
public void setTypeHierarchyCapabilities(final TypeHierarchyCapabilities typeHierarchyCapabilities) {
this.typeHierarchyCapabilities = typeHierarchyCapabilities;
}

@Override
@Pure
public String toString() {
Expand All @@ -503,6 +527,7 @@ public String toString() {
b.add("publishDiagnostics", this.publishDiagnostics);
b.add("foldingRange", this.foldingRange);
b.add("semanticHighlightingCapabilities", this.semanticHighlightingCapabilities);
b.add("typeHierarchyCapabilities", this.typeHierarchyCapabilities);
return b.toString();
}

Expand Down Expand Up @@ -621,6 +646,11 @@ public boolean equals(final Object obj) {
return false;
} else if (!this.semanticHighlightingCapabilities.equals(other.semanticHighlightingCapabilities))
return false;
if (this.typeHierarchyCapabilities == null) {
if (other.typeHierarchyCapabilities != null)
return false;
} else if (!this.typeHierarchyCapabilities.equals(other.typeHierarchyCapabilities))
return false;
return true;
}

Expand Down Expand Up @@ -649,6 +679,7 @@ public int hashCode() {
result = prime * result + ((this.rename== null) ? 0 : this.rename.hashCode());
result = prime * result + ((this.publishDiagnostics== null) ? 0 : this.publishDiagnostics.hashCode());
result = prime * result + ((this.foldingRange== null) ? 0 : this.foldingRange.hashCode());
return prime * result + ((this.semanticHighlightingCapabilities== null) ? 0 : this.semanticHighlightingCapabilities.hashCode());
result = prime * result + ((this.semanticHighlightingCapabilities== null) ? 0 : this.semanticHighlightingCapabilities.hashCode());
return prime * result + ((this.typeHierarchyCapabilities== null) ? 0 : this.typeHierarchyCapabilities.hashCode());
}
}
Loading

0 comments on commit 08d3bc1

Please sign in to comment.