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
Closes: eclipse-lsp4j#272

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Jan 23, 2019
1 parent 1a5507d commit 3e60964
Show file tree
Hide file tree
Showing 9 changed files with 1,017 additions and 3 deletions.
176 changes: 175 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 @@ -752,6 +752,7 @@ class FoldingRangeCapabilities extends DynamicRegistrationCapabilities {
/**
* Capabilities specific to {@code textDocument/semanticHighlighting}.
*/
@Beta
@JsonRpcData
class SemanticHighlightingCapabilities {
/**
Expand All @@ -767,6 +768,28 @@ class SemanticHighlightingCapabilities {
}
}

/**
* Capabilities specific to the {@code textDocument/typeHierarchy} and the {@code typeHierarchy/resolve}
* language server 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 @@ -881,7 +904,14 @@ class TextDocumentClientCapabilities {
/**
* Capabilities specific to {@code textDocument/semanticHighlighting}.
*/
@Beta
SemanticHighlightingCapabilities semanticHighlightingCapabilities

/**
* Capabilities specific to {@code textDocument/typeHierarchy}.
*/
@Beta
TypeHierarchyCapabilities typeHierarchyCapabilities
}

/**
Expand Down Expand Up @@ -1982,6 +2012,71 @@ class DocumentRangeFormattingParams extends DocumentFormattingParams {
}
}

/**
* The type hierarchy request is sent from the client resolve a {@link TypeHierarchyItem type hierarchy item} for
* a give cursor location in the text document. The request would also allow to specify if the item should be resolved
* and whether sub- or supertypes are to be resolved.
*/
@JsonRpcData
class TypeHierarchyParams extends TextDocumentPositionParams {

/**
* The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. It defaults to {@code 0}.
*/
int resolve

/**
* The direction of the type hierarchy resolution. If not defined, defaults to {@code children}.
*
* <p>
* The followings are the legal values:
* <ul>
* <li>{@code children},</li>
* <li>{@code parents}, and</li>
* <li>{@code both}.</li>
* </ul>
* </p>
*/
String direction
}

/**
* Request to resolve an unresolved {@link TypeHierarchyItem type hierarchy item} which is indicated if the
* {@link TypeHierarchyItem#getParents parents} or the {@link TypeHierarchyItem#getChildren children} is not
* defined. If resolved and no {@code parents} or {@code children} are available then an empty list is returned.
*/
@JsonRpcData
class ResolveTypeHierarchyItemParams {

/**
* The hierarchy item to resolve.
*/
@NonNull
TypeHierarchyItem item

/**
* The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level.
*/
@NonNull
Integer resolve

/**
* The direction of the type hierarchy resolution.
*
* <p>
* The followings are the legal values:
* <ul>
* <li>{@code children},</li>
* <li>{@code parents}, and</li>
* <li>{@code both}.</li>
* </ul>
* </p>
*/
@NonNull
String direction

}

/**
* The document symbol request is sent from the client to the server to list all symbols found in a given text document.
*/
Expand Down Expand Up @@ -2743,7 +2838,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 @@ -2922,6 +3023,79 @@ class SignatureInformation {
}
}

/**
* Representation of an item that carries type information (such as class, interface, enumeration, etc) with additional parentage details.
*/
@JsonRpcData
class TypeHierarchyItem {

/**
* The human readable name of the hierarchy item.
*/
@NonNull
String name

/**
* Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method.
*/
String detail

/**
* The kind of the hierarchy item. For instance, class or interface.
*/
@NonNull
SymbolKind kind

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

/**
* The URI of the text document where this type hierarchy item belongs to.
*/
@NonNull
String uri

/**
* The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else
* like comments. This information is typically used to determine if the the clients cursor is inside the type
* hierarchy item to reveal in the symbol in the UI.
*
* @see TypeHierarchyItem#selectionRange
*/
@NonNull
Range range

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

/**
* If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does not have any
* direct parents. If not defined, the parents have not been resolved yet.
*/
List<TypeHierarchyItem> parents

/**
* If this type hierarchy item is resolved, it contains the direct children of the current item.
* Could be empty if the item does not have any descendants. If not defined, the children have not been resolved.
*/
List<TypeHierarchyItem> children

/**
* An optional data field can be used to identify a type hierarchy item in a resolve request.
*/
@JsonAdapter(JsonElementTypeAdapter.Factory)
Object data

}

/**
* Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be
* hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.eclipse.lsp4j.TextDocumentRegistrationOptions;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.TypeHierarchyItem;
import org.eclipse.lsp4j.TypeHierarchyParams;
import org.eclipse.lsp4j.WillSaveTextDocumentParams;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.adapters.CodeActionResponseAdapter;
Expand All @@ -63,6 +65,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 @@ -353,7 +357,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 @@ -402,4 +406,32 @@ default CompletableFuture<List<FoldingRange>> foldingRange(FoldingRangeRequestPa
default CompletableFuture<Either<Range, PrepareRenameResult>> prepareRename(TextDocumentPositionParams params) {
throw new UnsupportedOperationException();
}

/**
* The {@code textDocument/typeHierarchy} request is sent from the client to the
* server to retrieve a {@link TypeHierarchyItem type hierarchy item} based on
* the {@link TypeHierarchyParams cursor position in the text document}. This
* request would also allow to specify if the item should be resolved and
* whether sub- or supertypes are to be resolved. If no type hierarchy item can
* be found under the given text document position, resolves to {@code null}.
*/
@Beta
@JsonRequest
default CompletableFuture<TypeHierarchyItem> typeHierarchy(TypeHierarchyParams params) {
throw new UnsupportedOperationException();
}

/**
* The {@code typeHierarchy/resolve} request is sent from the client to the
* server to resolve an unresolved {@link TypeHierarchyItem type hierarchy
* item}. A type hierarchy item is unresolved if the if the
* {@link TypeHierarchyItem#getParents parents} or the
* {@link TypeHierarchyItem#getChildren children} is not defined.
*/
@Beta
@JsonRequest(value="typeHierarchy/resolve", useSegment = false)
default CompletableFuture<TypeHierarchyItem> resolveTypeHierarchy(TypeHierarchyParams params) {
throw new UnsupportedOperationException();
}

}
Loading

0 comments on commit 3e60964

Please sign in to comment.