Skip to content

Commit 322d858

Browse files
tcx4c70baronfel
authored andcommitted
add call hierarchy from LSP 3.16
Signed-off-by: Adam Tao <[email protected]>
1 parent 6753231 commit 322d858

File tree

5 files changed

+130
-2
lines changed

5 files changed

+130
-2
lines changed

src/LanguageServerProtocol.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ module Server =
227227
"textDocument/documentSymbol", requestHandling (fun s p -> s.TextDocumentDocumentSymbol(p))
228228
"textDocument/foldingRange", requestHandling (fun s p -> s.TextDocumentFoldingRange(p))
229229
"textDocument/selectionRange", requestHandling (fun s p -> s.TextDocumentSelectionRange(p))
230+
"textDocument/prepareCallHierarchy", requestHandling(fun s p -> s.TextDocumentPrepareCallHierarchy(p))
231+
"callHierarchy/incomingCalls", requestHandling(fun s p -> s.CallHierarchyIncomingCalls(p))
232+
"callHierarchy/outgoingCalls", requestHandling(fun s p -> s.CallHierarchyOutgoingCalls(p))
230233
"textDocument/semanticTokens/full", requestHandling (fun s p -> s.TextDocumentSemanticTokensFull(p))
231234
"textDocument/semanticTokens/full/delta", requestHandling (fun s p -> s.TextDocumentSemanticTokensFullDelta(p))
232235
"textDocument/semanticTokens/range", requestHandling (fun s p -> s.TextDocumentSemanticTokensRange(p))

src/Server.fs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,23 @@ type ILspServer =
310310
/// that may be rendered in the editor at the end of lines.
311311
abstract member TextDocumentInlineValue: InlineValueParams -> AsyncLspResult<InlineValue [] option>
312312

313+
/// The call hierarchy request is sent from the client to the server to return a call hierarchy for the
314+
/// language element of given text document positions. The call hierarchy requests are executed in two
315+
/// steps:
316+
/// 1. first a call hierarchy item is resolved for the given text document position
317+
/// 2. for a call hierarchy item the incoming or outgoing call hierarchy items are resolved.
318+
abstract member TextDocumentPrepareCallHierarchy: CallHierarchyPrepareParams -> AsyncLspResult<CallHierarchyItem [] option>
319+
320+
/// The request is sent from the client to the server to resolve incoming calls for a given call hierarchy
321+
/// item. The request doesn't define its own client and server capabilities. It is only issued if a server
322+
/// registers for the `textDocument/prepareCallHierarchy` request.
323+
abstract member CallHierarchyIncomingCalls: CallHierarchyIncomingCallsParams -> AsyncLspResult<CallHierarchyIncomingCall [] option>
324+
325+
/// The request is sent from the client to the server to resolve outgoing calls for a given call hierarchy
326+
/// item. The request doesn't define its own client and server capabilities. It is only issued if a server
327+
/// registers for the `textDocument/prepareCallHierarchy` request.
328+
abstract member CallHierarchyOutgoingCalls: CallHierarchyOutgoingCallsParams -> AsyncLspResult<CallHierarchyOutgoingCall [] option>
329+
313330
[<AbstractClass>]
314331
type LspServer() =
315332
abstract member Dispose: unit -> unit
@@ -669,6 +686,26 @@ type LspServer() =
669686
abstract member TextDocumentInlineValue: InlineValueParams -> AsyncLspResult<InlineValue [] option>
670687
default __.TextDocumentInlineValue(_) = notImplemented
671688

689+
/// The call hierarchy request is sent from the client to the server to return a call hierarchy for the
690+
/// language element of given text document positions. The call hierarchy requests are executed in two
691+
/// steps:
692+
/// 1. first a call hierarchy item is resolved for the given text document position
693+
/// 2. for a call hierarchy item the incoming or outgoing call hierarchy items are resolved.
694+
abstract member TextDocumentPrepareCallHierarchy: CallHierarchyPrepareParams -> AsyncLspResult<CallHierarchyItem [] option>
695+
default __.TextDocumentPrepareCallHierarchy(_) = notImplemented
696+
697+
/// The request is sent from the client to the server to resolve incoming calls for a given call hierarchy
698+
/// item. The request doesn't define its own client and server capabilities. It is only issued if a server
699+
/// registers for the `textDocument/prepareCallHierarchy` request.
700+
abstract member CallHierarchyIncomingCalls: CallHierarchyIncomingCallsParams -> AsyncLspResult<CallHierarchyIncomingCall [] option>
701+
default __.CallHierarchyIncomingCalls(_) = notImplemented
702+
703+
/// The request is sent from the client to the server to resolve outgoing calls for a given call hierarchy
704+
/// item. The request doesn't define its own client and server capabilities. It is only issued if a server
705+
/// registers for the `textDocument/prepareCallHierarchy` request.
706+
abstract member CallHierarchyOutgoingCalls: CallHierarchyOutgoingCallsParams -> AsyncLspResult<CallHierarchyOutgoingCall [] option>
707+
default __.CallHierarchyOutgoingCalls(_) = notImplemented
708+
672709
interface ILspServer with
673710
member this.Dispose() = this.Dispose()
674711
member this.Initialize(p: InitializeParams) = this.Initialize(p)
@@ -731,4 +768,8 @@ type LspServer() =
731768
member this.TextDocumentInlayHint(p: InlayHintParams) = this.TextDocumentInlayHint(p)
732769
member this.InlayHintResolve(p: InlayHint) = this.InlayHintResolve(p)
733770
member this.WorkDoneProgessCancel(token) = this.WorkDoneProgessCancel(token)
734-
member this.TextDocumentInlineValue(p: InlineValueParams) = this.TextDocumentInlineValue(p)
771+
member this.TextDocumentInlineValue(p: InlineValueParams) = this.TextDocumentInlineValue(p)
772+
773+
member this.TextDocumentPrepareCallHierarchy(p: CallHierarchyPrepareParams) = this.TextDocumentPrepareCallHierarchy(p)
774+
member this.CallHierarchyIncomingCalls(p: CallHierarchyIncomingCallsParams) = this.CallHierarchyIncomingCalls(p)
775+
member this.CallHierarchyOutgoingCalls(p: CallHierarchyOutgoingCallsParams) = this.CallHierarchyOutgoingCalls(p)

src/Types.fs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ type SymbolKind =
162162
| Operator = 25
163163
| TypeParameter = 26
164164

165+
type SymbolTag =
166+
| Deprecated = 1
167+
165168
/// Represents information about programming constructs like variables, classes,
166169
/// interfaces etc.
167170
type SymbolInformation =
@@ -824,6 +827,11 @@ type TextDocumentClientCapabilities =
824827
/// Capabilities for the `textDocument/selectionRange`
825828
SelectionRange: DynamicCapabilities option
826829

830+
/// Capabilities specific to the various call hierarchy requests.
831+
///
832+
/// @since 3.16.0
833+
CallHierarchy: DynamicCapabilities option
834+
827835
/// Capabilities specific to the various semantic token requests.
828836
/// @since 3.16.0
829837
SemanticTokens: SemanticTokensClientCapabilities option
@@ -1173,6 +1181,8 @@ type ServerCapabilities =
11731181

11741182
SelectionRangeProvider: bool option
11751183

1184+
CallHierarchyProvider: bool option
1185+
11761186
SemanticTokensProvider: SemanticTokensOptions option
11771187

11781188
InlayHintProvider: InlayHintOptions option
@@ -1206,6 +1216,7 @@ type ServerCapabilities =
12061216
Experimental = None
12071217
FoldingRangeProvider = None
12081218
SelectionRangeProvider = None
1219+
CallHierarchyProvider = None
12091220
SemanticTokensProvider = None
12101221
InlayHintProvider = None
12111222
InlineValueProvider = None
@@ -2196,6 +2207,63 @@ type SelectionRange =
21962207
/// The parent selection range containing this range. Therefore `parent.range` must contain `this.range`.
21972208
Parent: SelectionRange option }
21982209

2210+
type CallHierarchyPrepareParams =
2211+
{ TextDocument: TextDocumentIdentifier
2212+
2213+
/// The position at which this request was sent.
2214+
Position: Position }
2215+
2216+
type HierarchyItem =
2217+
{ /// The name of this item.
2218+
Name: string
2219+
2220+
/// The kind of this item.
2221+
Kind: SymbolKind
2222+
2223+
/// Tags for this item.
2224+
Tags: SymbolTag [] option
2225+
2226+
/// More detail for this item, e.g., the signature of a function.
2227+
Detail: string option
2228+
2229+
/// The resource identifier of this item.
2230+
Uri: DocumentUri
2231+
2232+
/// The range enclosing this symbol not including leading/trailing
2233+
/// whitespace but everything else, e.g., comments and code.
2234+
Range: Range
2235+
2236+
/// The range that should be selected and revealed when this symbol is being
2237+
/// picked, e.g., the name of a function. Must be contained by the [`range`].
2238+
SelectionRange: Range
2239+
2240+
/// A data entry field that is preserved between a call hierarchy prepare
2241+
/// and incoming calls or outgoing calls requests.
2242+
Data: JToken option }
2243+
2244+
type CallHierarchyItem = HierarchyItem
2245+
2246+
type CallHierarchyIncomingCallsParams = { Item: CallHierarchyItem }
2247+
2248+
type CallHierarchyIncomingCall =
2249+
{ /// The item that makes the call.
2250+
From: CallHierarchyItem
2251+
2252+
/// The ranges at which the calls appear. This is relative to the caller
2253+
/// denoted by [`this.From`].
2254+
FromRanges: Range [] }
2255+
2256+
type CallHierarchyOutgoingCallsParams = { Item: CallHierarchyItem }
2257+
2258+
type CallHierarchyOutgoingCall =
2259+
{ /// The item that is called
2260+
To: CallHierarchyItem
2261+
2262+
/// The range at which this item is called. This is the range relative to
2263+
/// the caller, e.g., the item passed to `callHierarchy/outgoingCalls`
2264+
/// request.
2265+
FromRanges: Range[] }
2266+
21992267
type SemanticTokensParams = { TextDocument: TextDocumentIdentifier }
22002268

22012269
type SemanticTokensDeltaParams =

tests/Benchmarks.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ type MultipleTypesBenchmarks() =
450450
LineFoldingOnly = Some true
451451
RangeLimit = None }
452452
SelectionRange = Some { DynamicRegistration = None }
453+
CallHierarchy = Some { DynamicRegistration = None }
453454
SemanticTokens =
454455
Some
455456
{ DynamicRegistration = Some false

tests/Tests.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,22 @@ let private serializationTests =
858858

859859
testThereAndBackAgain theInlineValue ]
860860

861-
861+
testList
862+
(nameof HierarchyItem)
863+
[
864+
testCase "can roundtrip HierarchyItem with all fields (simple)"
865+
<| fun _ ->
866+
let item: HierarchyItem =
867+
{ Name = "test"
868+
Kind = SymbolKind.Function
869+
Tags = None
870+
Detail = None
871+
Uri = "..."
872+
Range = mkRange' (1, 2) (3, 4)
873+
SelectionRange = mkRange' (1, 2) (1, 4)
874+
Data = None }
875+
testThereAndBackAgain item
876+
]
862877
Shotgun.tests ]
863878

864879
[<Tests>]

0 commit comments

Comments
 (0)