Skip to content

Commit 89b4ffa

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 dbfd37e commit 89b4ffa

File tree

3 files changed

+271
-0
lines changed

3 files changed

+271
-0
lines changed

protocol/src/main.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,19 @@ 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+
49+
export type CallHierarchyParams = callHierarchy.CallHierarchyParams;
50+
export type CallHierarchyCall = callHierarchy.CallHierarchyCall;
3951
}
4052

4153
export interface ProtocolConnection {
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
29+
_Server Capabilities_:
30+
31+
```ts
32+
CallHierarchyServerCapabilities {
33+
/**
34+
* The server provides Call Hierarchy support.
35+
*/
36+
callHierarchyProvider?: boolean | (TextDocumentRegistrationOptions & StaticRegistrationOptions);
37+
}
38+
```
39+
40+
##### Call Hierarchy Request
41+
42+
_Request_:
43+
44+
The `textDocument/callHierarchy` request is sent from the client to the server to request the call hierarchy for a symbol defined (or referenced) at the given text document position.
45+
46+
Returns a call hierarchy item for the requested call direction. ERROR
47+
48+
* method: ‘textDocument/callHierarchy'
49+
* params: `CallHierarchyParams` defined as follows:
50+
51+
```ts
52+
export interface CallHierarchyParams extends TextDocumentPositionParams {
53+
/**
54+
* The direction of calls to provide.
55+
*/
56+
direction: CallHierarchyDirection;
57+
}
58+
59+
export namespace CallHierarchyDirection {
60+
export const Incoming: 1 = 1;
61+
export const Outgoing: 2 = 2;
62+
}
63+
```
64+
65+
_Response_:
66+
67+
The server will send a collection of `CallHierarchyCall` objects, or `null` if no callable symbol is found at the given document position.
68+
69+
Each `CallHierarchyCall` object defines a call from one `CallHierarchySymbol` to another.
70+
71+
* result: `CallHierarchyCall[]` | `null`
72+
73+
```ts
74+
export interface CallHierarchyCall {
75+
76+
/**
77+
* The source range of the reference. The range is a sub range of the `from` symbol range.
78+
*/
79+
range: Range;
80+
81+
/**
82+
* The symbol that contains the reference.
83+
*/
84+
from: CallHierarchySymbol;
85+
86+
/**
87+
* The symbol that is referenced.
88+
*/
89+
to: CallHierarchySymbol;
90+
}
91+
92+
export interface CallHierarchySymbol {
93+
94+
/**
95+
* The name of the symbol targeted by the call hierarchy request.
96+
*/
97+
name: string;
98+
99+
/**
100+
* More detail for this symbol, e.g the signature of a function.
101+
*/
102+
detail?: string;
103+
104+
/**
105+
* The kind of this symbol.
106+
*/
107+
kind: SymbolKind;
108+
109+
/**
110+
* URI of the document containing the symbol.
111+
*/
112+
uri: string;
113+
114+
/**
115+
* The range enclosing this symbol not including leading/trailing whitespace but everything else
116+
* like comments. This information is typically used to determine if the the clients cursor is
117+
* inside the symbol to reveal in the symbol in the UI.
118+
*/
119+
range: Range;
120+
121+
/**
122+
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
123+
* Must be contained by the the `range`.
124+
*/
125+
selectionRange: Range;
126+
}
127+
```
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 { 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 provide 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 [CallHierarchyCall[]](#CallHierarchyCall) or a Thenable that resolves to such.
42+
*
43+
* Evaluates the symbol defined (or referenced) at the given position, and returns all incoming or outgoing calls to the symbol(s).
44+
*/
45+
export namespace CallHierarchyRequest {
46+
export const type = new RequestType<CallHierarchyParams, CallHierarchyCall[], void, TextDocumentRegistrationOptions>('textDocument/callHierarchy');
47+
export type HandlerSignature = RequestHandler<CallHierarchyParams, CallHierarchyCall[] | null, void>;
48+
}
49+
50+
/**
51+
* The parameter of a `textDocument/callHierarchy` request extends the `TextDocumentPositionParams` with the direction of calls to resolve.
52+
*/
53+
export interface CallHierarchyParams extends TextDocumentPositionParams {
54+
/**
55+
* The direction of calls to provide.
56+
*/
57+
direction: CallHierarchyDirection;
58+
}
59+
60+
/**
61+
* The direction of a call hierarchy request.
62+
*/
63+
export namespace CallHierarchyDirection {
64+
/**
65+
* The callers of a symbol.
66+
*/
67+
export const Incoming: 1 = 1;
68+
69+
/**
70+
* The callees of a symbol.
71+
*/
72+
export const Outgoing: 2 = 2;
73+
}
74+
75+
export type CallHierarchyDirection = 1 | 2;
76+
77+
/**
78+
* The result of a `textDocument/callHierarchy` request.
79+
*/
80+
export interface CallHierarchyCall {
81+
82+
/**
83+
* The source range of the reference. The range is a sub range of the `from` symbol range.
84+
*/
85+
range: Range;
86+
87+
/**
88+
* The symbol that contains the reference.
89+
*/
90+
from: CallHierarchySymbol;
91+
92+
/**
93+
* The symbol that is referenced.
94+
*/
95+
to: CallHierarchySymbol;
96+
}
97+
98+
export interface CallHierarchySymbol {
99+
100+
/**
101+
* The name of the symbol targeted by the call hierarchy request.
102+
*/
103+
name: string;
104+
105+
/**
106+
* More detail for this symbol, e.g the signature of a function.
107+
*/
108+
detail?: string;
109+
110+
/**
111+
* The kind of this symbol.
112+
*/
113+
kind: SymbolKind;
114+
115+
/**
116+
* URI of the document containing the symbol.
117+
*/
118+
uri: string;
119+
120+
/**
121+
* The range enclosing this symbol not including leading/trailing whitespace but everything else
122+
* like comments. This information is typically used to determine if the the clients cursor is
123+
* inside the symbol to reveal in the symbol in the UI.
124+
*/
125+
range: Range;
126+
127+
/**
128+
* The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
129+
* Must be contained by the the `range`.
130+
*/
131+
selectionRange: Range;
132+
}

0 commit comments

Comments
 (0)