Skip to content

Commit b6887d8

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 b6887d8

File tree

3 files changed

+310
-0
lines changed

3 files changed

+310
-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: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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?: 'incoming' | 'outgoing';
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` defined as follows:
66+
67+
```ts
68+
export interface CallHierarchyItem {
69+
/**
70+
* The name of the symbol targeted by the call hierarchy request.
71+
*/
72+
name: string;
73+
/**
74+
* More detail for this symbol, e.g the signature of a function.
75+
*/
76+
detail?: string;
77+
/**
78+
* The kind of this symbol.
79+
*/
80+
kind: SymbolKind;
81+
/**
82+
* URI of the document containing the symbol.
83+
*/
84+
uri: string;
85+
/**
86+
* The range enclosing this symbol not including leading/trailing whitespace but everything else
87+
* like comments. This information is typically used to determine if the the clients cursor is
88+
* inside the symbol to reveal in the symbol in the UI.
89+
*/
90+
range: Range;
91+
/**
92+
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
93+
* Must be contained by the the `range`.
94+
*/
95+
selectionRange: Range;
96+
97+
/**
98+
* The actual location of the call.
99+
*
100+
* Must be defined in resolved callers/callees.
101+
*/
102+
callLocation?: Location;
103+
104+
/**
105+
* List of incoming calls.
106+
*
107+
* *Note*: The items is _unresolved_ if `callers` and `callees` is undefined.
108+
*/
109+
callers?: CallHierarchyItem[];
110+
/**
111+
* List of outgoing calls.
112+
*
113+
* *Note*: The items is _unresolved_ if `callers` and `callees` is undefined.
114+
*/
115+
callees?: CallHierarchyItem[];
116+
/**
117+
* Optional data to identify an item in a resolve request.
118+
*/
119+
data?: any;
120+
}
121+
```
122+
123+
_Request_:
124+
125+
The `callHierarchy/resolve` request is sent from the client to the server to resolve a call hierarchy item.
126+
127+
Returns a resolved call hierarchy item for the requested call direction.
128+
129+
* method: callHierarchy/resolve'
130+
* params: `CallHierarchyParams` defined as follows:
131+
132+
```ts
133+
export interface ResolveCallHierarchyItemParams {
134+
item: CallHierarchyItem;
135+
resolve: number;
136+
direction: 'incoming' | 'outgoing';
137+
}
138+
```
139+
140+
_Response_:
141+
142+
The server will send a resolved `CallHierarchyItem` object.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
* Outgoing direction for callees.
72+
* The default is incoming for callers.
73+
*/
74+
direction?: 'incoming' | 'outgoing';
75+
}
76+
77+
/**
78+
* The parameters of a `callHierarchy/resolve` request.
79+
*/
80+
export interface ResolveCallHierarchyItemParams {
81+
/**
82+
* Unresolved item.
83+
*/
84+
item: CallHierarchyItem;
85+
/**
86+
* The number of levels to resolve.
87+
*/
88+
resolve: number;
89+
/**
90+
* Outgoing direction for callees.
91+
* The default is incoming for callers.
92+
*/
93+
direction: 'incoming' | 'outgoing';
94+
}
95+
96+
/**
97+
* The result of a `textDocument/callHierarchy` request.
98+
*/
99+
export interface CallHierarchyItem {
100+
/**
101+
* The name of the symbol targeted by the call hierarchy request.
102+
*/
103+
name: string;
104+
/**
105+
* More detail for this symbol, e.g the signature of a function.
106+
*/
107+
detail?: string;
108+
/**
109+
* The kind of this symbol.
110+
*/
111+
kind: SymbolKind;
112+
/**
113+
* URI of the document containing the symbol.
114+
*/
115+
uri: string;
116+
/**
117+
* The range enclosing this symbol not including leading/trailing whitespace but everything else
118+
* like comments. This information is typically used to determine if the the clients cursor is
119+
* inside the symbol to reveal in the symbol in the UI.
120+
*/
121+
range: Range;
122+
/**
123+
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
124+
* Must be contained by the the `range`.
125+
*/
126+
selectionRange: Range;
127+
128+
/**
129+
* The actual location of the call.
130+
*
131+
* **Must be defined** in resolved callers/callees.
132+
*/
133+
callLocation?: Location;
134+
135+
/**
136+
* List of incoming calls.
137+
*
138+
* *Note*: The items is _unresolved_ if `callers` and `callees` is undefined.
139+
*/
140+
callers?: CallHierarchyItem[];
141+
/**
142+
* List of outgoing calls.
143+
*
144+
* *Note*: The items is _unresolved_ if `callers` and `callees` is undefined.
145+
*/
146+
callees?: CallHierarchyItem[];
147+
/**
148+
* Optional data to identify an item in a resolve request.
149+
*/
150+
data?: any;
151+
}

0 commit comments

Comments
 (0)