From 4ce0e5268a205e5e5e2055ef581197681b7a01c7 Mon Sep 17 00:00:00 2001 From: Gorkem Ercan Date: Fri, 4 May 2018 22:49:01 -0400 Subject: [PATCH] Proposal for type hierarchy add new textDocument/subTypes and textDocument/superTypes requests. Introduces SymbolNode. --- protocol/protocol.typeHierarchy.proposed.md | 77 +++++++++++++++++++ .../src/protocol.typeHierarchy.proposed.ts | 65 ++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 protocol/protocol.typeHierarchy.proposed.md create mode 100644 protocol/src/protocol.typeHierarchy.proposed.ts diff --git a/protocol/protocol.typeHierarchy.proposed.md b/protocol/protocol.typeHierarchy.proposed.md new file mode 100644 index 000000000..8254a9c5f --- /dev/null +++ b/protocol/protocol.typeHierarchy.proposed.md @@ -0,0 +1,77 @@ + +#### Type Hierarchy + +Many language support inheritance and LSP provides retrieving the hierarchy information with the following requests. + + +The `textDocument/subTypes` request is sent from the client to the server to resolve resolve the subtypes of a symbol at a given text document position. Returns the direct subtypes in no particular order. + +_Client Capabilities_: + +```ts + TextDocumentClientCapabilities { + /** + * Capabilities specific to the `textDocument/subTypes` + * and `textDocument/superTypes + */ + typeHierarchy?: { + /** + * Whether implementation supports dynamic registration. + */ + dynamicRegistration?: boolean; + }; +``` + +_Server Capabilities_: +```ts +ServerCapabilities{ + /** + * The server provides type hierarchy information + */ + typeHierarchyProvider?: boolean +} +``` + +```ts +/** + * Represents hierarchical information about programming constructs like variables, classes, + * interfaces etc. + */ +export interface SymbolNode extends SymbolInformation { + /** + * Immediate descendants of this node + */ + descendants? : SymbolNode[] + /** + * true if this node has children. hasChildren can be + * true even when the descendants are empty. In that case + * the clients should do a call to retrieve the descendants. + */ + hasChildren: boolean +} +``` + +_Request_: + +method: ‘textDocument/subTypes’ +params: TextDocumentPositionParams + +_Response_ + +* result: `SymbolNode[] | null` +* error: code and message set in case an exception happens during the 'textDocument/subTypes' request + + + +The `textDocument/superTypes` request is sent from the client to the server to resolve resolve the supertypes of a symbol at a given text document position. Returns all the supertypes in bottom-up order. + +_Request_: + +method: ‘textDocument/superTypes’ +params: TextDocumentPositionParams + +_Response_ + +* result: `SymbolNode[] | null` +* error: code and message set in case an exception happens during the 'textDocument/superTypes' request + diff --git a/protocol/src/protocol.typeHierarchy.proposed.ts b/protocol/src/protocol.typeHierarchy.proposed.ts new file mode 100644 index 000000000..83216b9f1 --- /dev/null +++ b/protocol/src/protocol.typeHierarchy.proposed.ts @@ -0,0 +1,65 @@ +/* -------------------------------------------------------------------------------------------- + * Copyright (c) Red Hat Inc and others . All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * ------------------------------------------------------------------------------------------ */ +'use strict'; + +import { RequestType } from 'vscode-jsonrpc'; +import {SymbolInformation} from 'vscode-languageserver-types'; +import {TextDocumentPositionParams, TextDocumentRegistrationOptions} from './protocol' + +export interface TypeHierarchyClientCapabilities { + /** + * The text document client capabilities + */ + textDocument?: { + /** + * Capabilities specific to the `textDocument/subTypes` and `textDocument/superTypes` + */ + typeHierarchy?: { + /** + * Whether implementation supports dynamic registration. + */ + dynamicRegistration?: boolean; + }; + } +} + +export interface TypeHierarchyServerCapabilities { + /** + * The server provides type hierarchy information + */ + typeHierarchyProvider?: boolean +} + +/** + * + */ +export namespace SubTypesRequest { + export const type = new RequestType('textDocument/subTypes'); +} + +/** + * + */ +export namespace SuperTypesRequest { + export const type = new RequestType('textDocument/superTypes'); +} + + +/** + * Represents hierarchical information about programming constructs like variables, classes, + * interfaces etc. + */ +export interface SymbolNode extends SymbolInformation { + /** + * Immediate descendants of this node + */ + descendants? : SymbolNode[] + /** + * true if this node has children. hasChildren can be + * true even when the descendants are empty. In that case + * the clients should do a call to retrieve the descendants. + */ + hasChildren: boolean +}