Skip to content

Commit c56fb53

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

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

src/LanguageServerProtocol.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ module Server =
230230
"textDocument/prepareCallHierarchy", requestHandling(fun s p -> s.TextDocumentPrepareCallHierarchy(p))
231231
"callHierarchy/incomingCalls", requestHandling(fun s p -> s.CallHierarchyIncomingCalls(p))
232232
"callHierarchy/outgoingCalls", requestHandling(fun s p -> s.CallHierarchyOutgoingCalls(p))
233+
"textDocument/prepareTypeHierarchy", requestHandling(fun s p -> s.TextDocumentPrepareTypeHierarchy(p))
234+
"typeHierarchy/supertypes", requestHandling(fun s p -> s.TypeHierarchySupertypes(p))
235+
"typeHierarchy/subtypes", requestHandling(fun s p -> s.TypeHierarchySubtypes(p))
233236
"textDocument/semanticTokens/full", requestHandling (fun s p -> s.TextDocumentSemanticTokensFull(p))
234237
"textDocument/semanticTokens/full/delta", requestHandling (fun s p -> s.TextDocumentSemanticTokensFullDelta(p))
235238
"textDocument/semanticTokens/range", requestHandling (fun s p -> s.TextDocumentSemanticTokensRange(p))

src/Server.fs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ type ILspServer =
327327
/// registers for the `textDocument/prepareCallHierarchy` request.
328328
abstract member CallHierarchyOutgoingCalls: CallHierarchyOutgoingCallsParams -> AsyncLspResult<CallHierarchyOutgoingCall [] option>
329329

330+
/// The type hierarchy request is sent from the client to the server to return a type hierarchy for the
331+
/// language element of given text document positions. Will return `null` if the server couldn't infer a
332+
/// valid type from the position. The type hierarchy requests are executed in two steps:
333+
/// 1. first a type hierarchy item is prepared for the given text document position.
334+
/// 2. for a type hierarchy item the supertype or subtype type hierarchy items are resolved.
335+
abstract member TextDocumentPrepareTypeHierarchy: TypeHierarchyPrepareParams -> AsyncLspResult<TypeHierarchyItem [] option>
336+
337+
/// The request is sent from the client to the server to resolve the supertype for a given type hierarchy
338+
/// item. Will return `null` is the serve couldn't infer a valid type from `item` in the params. The request
339+
/// doesn't defines its own client and server capabilities. It is only issued if a server registers for the
340+
/// `textDocument/prepareTypeHierarchy` request.
341+
abstract member TypeHierarchySupertypes: TypeHierarchySupertypesParams -> AsyncLspResult<TypeHierarchyItem [] option>
342+
343+
/// The request is sent from the client to the server to resolve the supertype for a given type hierarchy
344+
/// item. Will return `null` is the serve couldn't infer a valid type from `item` in the params. The request
345+
/// doesn't defines its own client and server capabilities. It is only issued if a server registers for the
346+
/// `textDocument/prepareTypeHierarchy` request.
347+
abstract member TypeHierarchySubtypes: TypeHierarchySubtypesParams -> AsyncLspResult<TypeHierarchyItem [] option>
348+
330349
[<AbstractClass>]
331350
type LspServer() =
332351
abstract member Dispose: unit -> unit
@@ -706,6 +725,28 @@ type LspServer() =
706725
abstract member CallHierarchyOutgoingCalls: CallHierarchyOutgoingCallsParams -> AsyncLspResult<CallHierarchyOutgoingCall [] option>
707726
default __.CallHierarchyOutgoingCalls(_) = notImplemented
708727

728+
/// The type hierarchy request is sent from the client to the server to return a type hierarchy for the
729+
/// language element of given text document positions. Will return `null` if the server couldn't infer a
730+
/// valid type from the position. The type hierarchy requests are executed in two steps:
731+
/// 1. first a type hierarchy item is prepared for the given text document position.
732+
/// 2. for a type hierarchy item the supertype or subtype type hierarchy items are resolved.
733+
abstract member TextDocumentPrepareTypeHierarchy: TypeHierarchyPrepareParams -> AsyncLspResult<TypeHierarchyItem [] option>
734+
default __.TextDocumentPrepareTypeHierarchy(_) = notImplemented
735+
736+
/// The request is sent from the client to the server to resolve the supertype for a given type hierarchy
737+
/// item. Will return `null` is the serve couldn't infer a valid type from `item` in the params. The request
738+
/// doesn't defines its own client and server capabilities. It is only issued if a server registers for the
739+
/// `textDocument/prepareTypeHierarchy` request.
740+
abstract member TypeHierarchySupertypes: TypeHierarchySupertypesParams -> AsyncLspResult<TypeHierarchyItem [] option>
741+
default __.TypeHierarchySupertypes(_) = notImplemented
742+
743+
/// The request is sent from the client to the server to resolve the supertype for a given type hierarchy
744+
/// item. Will return `null` is the serve couldn't infer a valid type from `item` in the params. The request
745+
/// doesn't defines its own client and server capabilities. It is only issued if a server registers for the
746+
/// `textDocument/prepareTypeHierarchy` request.
747+
abstract member TypeHierarchySubtypes: TypeHierarchySubtypesParams -> AsyncLspResult<TypeHierarchyItem [] option>
748+
default __.TypeHierarchySubtypes(_) = notImplemented
749+
709750
interface ILspServer with
710751
member this.Dispose() = this.Dispose()
711752
member this.Initialize(p: InitializeParams) = this.Initialize(p)
@@ -773,3 +814,7 @@ type LspServer() =
773814
member this.TextDocumentPrepareCallHierarchy(p: CallHierarchyPrepareParams) = this.TextDocumentPrepareCallHierarchy(p)
774815
member this.CallHierarchyIncomingCalls(p: CallHierarchyIncomingCallsParams) = this.CallHierarchyIncomingCalls(p)
775816
member this.CallHierarchyOutgoingCalls(p: CallHierarchyOutgoingCallsParams) = this.CallHierarchyOutgoingCalls(p)
817+
818+
member this.TextDocumentPrepareTypeHierarchy(p: TypeHierarchyPrepareParams) = this.TextDocumentPrepareTypeHierarchy(p)
819+
member this.TypeHierarchySupertypes(p: TypeHierarchySupertypesParams) = this.TypeHierarchySupertypes(p)
820+
member this.TypeHierarchySubtypes(p: TypeHierarchySubtypesParams) = this.TypeHierarchySubtypes(p)

src/Types.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@ type TextDocumentClientCapabilities =
836836
/// @since 3.16.0
837837
SemanticTokens: SemanticTokensClientCapabilities option
838838

839+
/// Capabilities specific to the various type hierarchy requests.
840+
///
841+
/// @since 3.17.0
842+
TypeHierarchy: DynamicCapabilities option
843+
839844
/// Capabilities specific to the `textDocument/inlayHint` request.
840845
///
841846
/// @since 3.17.0
@@ -1185,6 +1190,8 @@ type ServerCapabilities =
11851190

11861191
SemanticTokensProvider: SemanticTokensOptions option
11871192

1193+
TypeHierarchyProvider: bool option
1194+
11881195
InlayHintProvider: InlayHintOptions option
11891196

11901197
InlineValueProvider: InlineValueOptions option
@@ -1218,6 +1225,7 @@ type ServerCapabilities =
12181225
SelectionRangeProvider = None
12191226
CallHierarchyProvider = None
12201227
SemanticTokensProvider = None
1228+
TypeHierarchyProvider = None
12211229
InlayHintProvider = None
12221230
InlineValueProvider = None
12231231
Workspace = None }
@@ -2264,6 +2272,18 @@ type CallHierarchyOutgoingCall =
22642272
/// request.
22652273
FromRanges: Range[] }
22662274

2275+
type TypeHierarchyPrepareParams =
2276+
{ TextDocument: TextDocumentIdentifier
2277+
2278+
/// The position at which this request was sent.
2279+
Position: Position }
2280+
2281+
type TypeHierarchyItem = HierarchyItem
2282+
2283+
type TypeHierarchySupertypesParams = { Item: TypeHierarchyItem }
2284+
2285+
type TypeHierarchySubtypesParams = { Item: TypeHierarchyItem }
2286+
22672287
type SemanticTokensParams = { TextDocument: TextDocumentIdentifier }
22682288

22692289
type SemanticTokensDeltaParams =

tests/Benchmarks.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ type MultipleTypesBenchmarks() =
464464
Formats = [| TokenFormat.Relative |]
465465
OverlappingTokenSupport = Some false
466466
MultilineTokenSupport = Some true }
467+
TypeHierarchy = Some { DynamicRegistration = None }
467468
InlayHint =
468469
Some
469470
{ DynamicRegistration = Some true

0 commit comments

Comments
 (0)