Skip to content

Commit ca78873

Browse files
committed
Proposing a protocol extension for call hierarchy.
Adds the `textDocument/callHierarchy` request sent from the client to the server to request the call hierarchy for a symbol at the given text document position. LSP issue: language-server-protocol#468 Signed-off-by: Alex Tugarev <[email protected]>
1 parent 1631753 commit ca78873

File tree

3 files changed

+337
-0
lines changed

3 files changed

+337
-0
lines changed

protocol/src/main.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,24 @@ export * from './protocol';
3535

3636
export { FoldingRangeParams as FoldingRangeRequestParam } from './protocol'; // for backward compatibility
3737

38+
import * as callHierarchy from './protocol.callHierarchy.proposed';
39+
3840
export namespace Proposed {
41+
export type CallHierarchyClientCapabilities = callHierarchy.CallHierarchyClientCapabilities;
42+
export type CallHierarchyServerCapabilities = callHierarchy.CallHierarchyServerCapabilities;
43+
44+
export namespace CallHierarchyRequest {
45+
export const type = callHierarchy.CallHierarchyRequest.type;
46+
export type HandlerSignature = callHierarchy.CallHierarchyRequest.HandlerSignature;
47+
}
48+
export namespace CallHierarchyResolveRequest {
49+
export const type = callHierarchy.CallHierarchyResolveRequest.type;
50+
export type HandlerSignature = callHierarchy.CallHierarchyResolveRequest.HandlerSignature;
51+
}
52+
53+
export type CallHierarchyParams = callHierarchy.CallHierarchyParams;
54+
export type ResolveCallHierarchyItemParams = callHierarchy.ResolveCallHierarchyItemParams;
55+
export type CallHierarchyItem = callHierarchy.CallHierarchyItem;
3956
}
4057

4158
export interface ProtocolConnection {
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
2+
#### Call Hierarchy
3+
4+
The LSP provides retrieving the call hierachy information with the following request.
5+
6+
_Client Capabilities_:
7+
8+
```ts
9+
CallHierarchyClientCapabilities {
10+
/**
11+
* The text document client capabilities
12+
*/
13+
textDocument?: {
14+
/**
15+
* Capabilities specific to the `textDocument/callHierarchy`
16+
*/
17+
callHierarchy?: {
18+
/**
19+
* Whether implementation supports dynamic registration. If this is set to `true`
20+
* the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
21+
* return value for the corresponding server capability as well.
22+
*/
23+
dynamicRegistration?: boolean;
24+
};
25+
}
26+
```
27+
28+
_Server Capabilities_:
29+
30+
```ts
31+
CallHierarchyServerCapabilities {
32+
/**
33+
* The server provides Call Hierarchy support.
34+
*/
35+
callHierarchyProvider?: boolean | (TextDocumentRegistrationOptions & StaticRegistrationOptions);
36+
}
37+
```
38+
39+
##### Call Hierarchy Request
40+
41+
_Request_:
42+
43+
The `textDocument/callHierarchy` request is sent from the client to the server to request the call hierarchy for a symbol at the given text document position.
44+
45+
Returns a call hierarchy item for the requested call direction.
46+
47+
* method: ‘textDocument/callHierarchy'
48+
* params: `CallHierarchyParams` defined as follows:
49+
50+
```ts
51+
export interface CallHierarchyParams extends TextDocumentPositionParams {
52+
resolve?: number;
53+
direction?: CallHierarchyDirection;
54+
}
55+
```
56+
57+
_Response_:
58+
59+
The server will send a `CallHierarchyItem` object containing the information about the targeted symbol. The item will be undefined, if no such symbol is found.
60+
61+
The item is _unresolved_ if the lists of callers and callees are undefined. Unresolved items can be resolved via `callHierarchy/resolve` requests.
62+
63+
The resolved item includes callers or callees again of type `CallHierarchyItem`. The caller/callee object provide the actual location of the call (`CallHierarchyItem.callLocation`).
64+
65+
* result: `CallHierarchyItem` | `null` defined as follows:
66+
67+
```ts
68+
export interface CallHierarchyItem {
69+
70+
/**
71+
* The name of the symbol targeted by the call hierarchy request.
72+
*/
73+
name: string;
74+
75+
/**
76+
* More detail for this symbol, e.g the signature of a function.
77+
*/
78+
detail?: string;
79+
80+
/**
81+
* The kind of this symbol.
82+
*/
83+
kind: SymbolKind;
84+
85+
/**
86+
* `true` if the hierarchy item is deprecated. Otherwise, `false`. It is `false` by default.
87+
*/
88+
deprecated?: boolean;
89+
90+
/**
91+
* URI of the document containing the symbol.
92+
*/
93+
uri: string;
94+
95+
/**
96+
* The range enclosing this symbol not including leading/trailing whitespace but everything else
97+
* like comments. This information is typically used to determine if the the clients cursor is
98+
* inside the symbol to reveal in the symbol in the UI.
99+
*/
100+
range: Range;
101+
102+
/**
103+
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
104+
* Must be contained by the the `range`.
105+
*/
106+
selectionRange: Range;
107+
108+
/**
109+
* The actual locations of incoming (or outgoing) calls to (or from) a callable identified by this item.
110+
*
111+
* *Note*: undefined in root item.
112+
*/
113+
callLocations?: Location[];
114+
115+
/**
116+
* List of incoming (or outgoing) calls to (or from) a callable identified by this item.
117+
*
118+
* *Note*: if undefined, this item is unresolved.
119+
*/
120+
calls?: CallHierarchyItem[];
121+
122+
/**
123+
* Optional data to identify an item in a resolve request.
124+
*/
125+
data?: any;
126+
}
127+
```
128+
129+
_Request_:
130+
131+
The `callHierarchy/resolve` request is sent from the client to the server to resolve a call hierarchy item.
132+
133+
Returns a resolved call hierarchy item for the requested call direction.
134+
135+
* method: callHierarchy/resolve'
136+
* params: `CallHierarchyParams` defined as follows:
137+
138+
```ts
139+
export interface ResolveCallHierarchyItemParams {
140+
item: CallHierarchyItem;
141+
resolve: number;
142+
direction: CallHierarchyDirection;
143+
}
144+
```
145+
146+
_Response_:
147+
148+
The server will send a resolved `CallHierarchyItem` object.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) TypeFox and others. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
'use strict';
6+
7+
import { RequestType, RequestHandler } from 'vscode-jsonrpc';
8+
import { Location, SymbolKind, Range } from 'vscode-languageserver-types';
9+
import { TextDocumentRegistrationOptions, StaticRegistrationOptions, TextDocumentPositionParams } from './protocol';
10+
11+
export interface CallHierarchyClientCapabilities {
12+
/**
13+
* The text document client capabilities
14+
*/
15+
textDocument?: {
16+
/**
17+
* Capabilities specific to the `textDocument/callHierarchy`
18+
*/
19+
callHierarchy?: {
20+
/**
21+
* Whether implementation supports dynamic registration. If this is set to `true`
22+
* the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
23+
* return value for the corresponding server capability as well.
24+
*/
25+
dynamicRegistration?: boolean;
26+
};
27+
}
28+
}
29+
30+
export interface CallHierarchyServerCapabilities {
31+
/**
32+
* The server provides Call Hierarchy support.
33+
*/
34+
callHierarchyProvider?: boolean | (TextDocumentRegistrationOptions & StaticRegistrationOptions);
35+
}
36+
37+
/**
38+
* Request to request the call hierarchy at a given text document position.
39+
*
40+
* The request's parameter is of type [CallHierarchyParams](#CallHierarchyParams). The response
41+
* is of type [CallHierarchyItem](#CallHierarchyItem) or a Thenable that resolves to such.
42+
*
43+
* The optional request's parameter defines the maximum number of levels to [resolve](#CallHierarchyParams.resolve) by this request.
44+
* Unresolved items can be resolved in subsequent `callHierarchy/resolve` requests.
45+
*/
46+
export namespace CallHierarchyRequest {
47+
export const type = new RequestType<CallHierarchyParams, CallHierarchyItem, void, TextDocumentRegistrationOptions>('textDocument/callHierarchy');
48+
export type HandlerSignature = RequestHandler<CallHierarchyParams, CallHierarchyItem | null, void>;
49+
}
50+
51+
/**
52+
* Request to resolve a call hierarchy item.
53+
*
54+
* The request's parameter is of type [ResolveCallHierarchyItemParams](#ResolveCallHierarchyItemParams). The response
55+
* is of type [CallHierarchyItem](#CallHierarchyItem) or a Thenable that resolves to such.
56+
*/
57+
export namespace CallHierarchyResolveRequest {
58+
export const type = new RequestType<ResolveCallHierarchyItemParams, CallHierarchyItem, void, void>('callHierarchy/resolve');
59+
export type HandlerSignature = RequestHandler<ResolveCallHierarchyItemParams, CallHierarchyItem | null, void>;
60+
}
61+
62+
/**
63+
* The parameters of a `textDocument/callHierarchy` request.
64+
*/
65+
export interface CallHierarchyParams extends TextDocumentPositionParams {
66+
/**
67+
* The number of levels to resolve.
68+
*/
69+
resolve?: number;
70+
/**
71+
* The direction of calls to resolve.
72+
*/
73+
direction?: CallHierarchyDirection;
74+
}
75+
76+
/**
77+
* The parameters of a `callHierarchy/resolve` request.
78+
*/
79+
export interface ResolveCallHierarchyItemParams {
80+
/**
81+
* Unresolved item.
82+
*/
83+
item: CallHierarchyItem;
84+
/**
85+
* The number of levels to resolve.
86+
*/
87+
resolve: number;
88+
/**
89+
* The direction of calls to resolve.
90+
*/
91+
direction: CallHierarchyDirection;
92+
}
93+
94+
/**
95+
* The direction of a call hierarchy.
96+
*/
97+
export namespace CallHierarchyDirection {
98+
/**
99+
* The callers of a symbol.
100+
*/
101+
export const Incoming: 1 = 1;
102+
103+
/**
104+
* The callees of a symbol.
105+
*/
106+
export const Outgoing: 2 = 2;
107+
}
108+
109+
export type CallHierarchyDirection = 1 | 2;
110+
111+
/**
112+
* The result of a `textDocument/callHierarchy` request.
113+
*/
114+
export interface CallHierarchyItem {
115+
116+
/**
117+
* The name of the symbol targeted by the call hierarchy request.
118+
*/
119+
name: string;
120+
121+
/**
122+
* More detail for this symbol, e.g the signature of a function.
123+
*/
124+
detail?: string;
125+
126+
/**
127+
* The kind of this symbol.
128+
*/
129+
kind: SymbolKind;
130+
131+
/**
132+
* `true` if the hierarchy item is deprecated. Otherwise, `false`. It is `false` by default.
133+
*/
134+
deprecated?: boolean;
135+
136+
/**
137+
* URI of the document containing the symbol.
138+
*/
139+
uri: string;
140+
141+
/**
142+
* The range enclosing this symbol not including leading/trailing whitespace but everything else
143+
* like comments. This information is typically used to determine if the the clients cursor is
144+
* inside the symbol to reveal in the symbol in the UI.
145+
*/
146+
range: Range;
147+
148+
/**
149+
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
150+
* Must be contained by the the `range`.
151+
*/
152+
selectionRange: Range;
153+
154+
/**
155+
* The actual locations of incoming (or outgoing) calls to (or from) a callable identified by this item.
156+
*
157+
* *Note*: undefined in root item.
158+
*/
159+
callLocations?: Location[];
160+
161+
/**
162+
* List of incoming (or outgoing) calls to (or from) a callable identified by this item.
163+
*
164+
* *Note*: if undefined, this item is unresolved.
165+
*/
166+
calls?: CallHierarchyItem[];
167+
168+
/**
169+
* Optional data to identify an item in a resolve request.
170+
*/
171+
data?: any;
172+
}

0 commit comments

Comments
 (0)