Skip to content

Commit

Permalink
support for textDocument/prepareTypeHierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Nov 30, 2023
1 parent 31ad303 commit c6ff09f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe
| textDocument/onTypeFormatting ||
| textDocument/prepareCallHierarchy ||
| textDocument/prepareRename ||
| textDocument/prepareTypeHierarchy | - |
| textDocument/prepareTypeHierarchy | |
| textDocument/publishDiagnostics ||
| textDocument/rangeFormatting ||
| textDocument/references ||
Expand Down
2 changes: 2 additions & 0 deletions Sources/LSPClient/Client.JSONRPCServerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public actor JSONRPCServerConnection: ServerConnection {
return try await session.response(to: method, params: params)
case .prepareRename(let params, _):
return try await session.response(to: method, params: params)
case .prepareTypeHierarchy(let params, _):
return try await session.response(to: method, params: params)
case .rename(let params, _):
return try await session.response(to: method, params: params)
case .inlayHint(let params, _):
Expand Down
4 changes: 4 additions & 0 deletions Sources/LSPClient/Client.ServerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public extension ServerConnection {
try await sendRequest(.prepareRename(params, ClientRequest.NullHandler))
}

func prepareTypeHeirarchy(params: TypeHierarchyPrepareParams) async throws -> PrepareTypeHeirarchyResponse {
try await sendRequest(.prepareTypeHierarchy(params, ClientRequest.NullHandler))
}

func rename(params: RenameParams) async throws -> RenameResponse {
try await sendRequest(.rename(params, ClientRequest.NullHandler))
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/LSPServer/Server.JSONRPCClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public actor JSONRPCClientConnection : ClientConnection {
yield(id: id, request: ClientRequest.prepareCallHierarchy(try decodeRequestParams(data), makeHandler(handler)))
case .textDocumentPrepareRename:
yield(id: id, request: ClientRequest.prepareRename(try decodeRequestParams(data), makeHandler(handler)))
case .textDocumentPrepareTypeHierarchy:
yield(id: id, request: ClientRequest.prepareTypeHierarchy(try decodeRequestParams(data), makeHandler(handler)))
case .textDocumentRename:
yield(id: id, request: ClientRequest.rename(try decodeRequestParams(data), makeHandler(handler)))
case .textDocumentInlayHint:
Expand Down
4 changes: 4 additions & 0 deletions Sources/LSPServer/Server.RequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public protocol RequestHandler : ErrorHandler {
func linkedEditingRange(id: JSONId, params: LinkedEditingRangeParams) async -> Result<LinkedEditingRangeResponse, AnyJSONRPCResponseError>
func prepareCallHierarchy(id: JSONId, params: CallHierarchyPrepareParams) async -> Result<CallHierarchyPrepareResponse, AnyJSONRPCResponseError>
func prepareRename(id: JSONId, params: PrepareRenameParams) async -> Result<PrepareRenameResponse, AnyJSONRPCResponseError>
func prepareTypeHeirarchy(id: JSONId, params: TypeHierarchyPrepareParams) async -> Result<PrepareTypeHeirarchyResponse, AnyJSONRPCResponseError>
func rename(id: JSONId, params: RenameParams) async -> Result<RenameResponse, AnyJSONRPCResponseError>
func documentLink(id: JSONId, params: DocumentLinkParams) async -> Result<DocumentLinkResponse, AnyJSONRPCResponseError>
func documentLinkResolve(id: JSONId, params: DocumentLink) async -> Result<DocumentLink, AnyJSONRPCResponseError>
Expand Down Expand Up @@ -125,6 +126,8 @@ public extension RequestHandler {
await handler(await prepareCallHierarchy(id: id, params: params))
case let .prepareRename(params, handler):
await handler(await prepareRename(id: id, params: params))
case let .prepareTypeHierarchy(params, handler):
await handler(await prepareTypeHeirarchy(id: id, params: params))
case let .rename(params, handler):
await handler(await rename(id: id, params: params))
case let .inlayHint(params, handler):
Expand Down Expand Up @@ -203,6 +206,7 @@ public extension RequestHandler {
func linkedEditingRange(id: JSONId, params: LinkedEditingRangeParams) async -> Result<LinkedEditingRangeResponse, AnyJSONRPCResponseError> { .failure(NotImplementedError) }
func prepareCallHierarchy(id: JSONId, params: CallHierarchyPrepareParams) async -> Result<CallHierarchyPrepareResponse, AnyJSONRPCResponseError> { .failure(NotImplementedError) }
func prepareRename(id: JSONId, params: PrepareRenameParams) async -> Result<PrepareRenameResponse, AnyJSONRPCResponseError> { .failure(NotImplementedError) }
func prepareTypeHeirarchy(id: JSONId, params: TypeHierarchyPrepareParams) async -> Result<PrepareTypeHeirarchyResponse, AnyJSONRPCResponseError> { .failure(NotImplementedError) }
func rename(id: JSONId, params: RenameParams) async -> Result<RenameResponse, AnyJSONRPCResponseError> { .failure(NotImplementedError) }
func inlayHint(id: JSONId, params: InlayHintParams) async -> Result<InlayHintResponse, AnyJSONRPCResponseError> { .failure(NotImplementedError) }
func inlayHintResolve(id: JSONId, params: InlayHint) async -> Result<InlayHintResponse, AnyJSONRPCResponseError> { .failure(NotImplementedError) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation

public struct TypeHierarchyPrepareParams: Codable, Hashable, Sendable {
public let textDocument: TextDocumentIdentifier
public let position: Position
public let workDoneToken: ProgressToken?

public init(textDocument: TextDocumentIdentifier, position: Position, workDoneToken: ProgressToken? = nil) {
self.textDocument = textDocument
self.position = position
self.workDoneToken = workDoneToken
}
}

public struct TypeHierarchyItem: Codable, Hashable, Sendable {
public let name: String
public let kind: SymbolKind
public let tags: [SymbolTag]?
public let detail: String?
public let uri: DocumentUri
public let range: LSPRange
public let selectionRange: LSPRange
public let data: LSPAny?
}

public typealias PrepareTypeHeirarchyResponse = [TypeHierarchyItem]?
4 changes: 4 additions & 0 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public enum ClientRequest: Sendable {
case textDocumentSignatureHelp = "textDocument/signatureHelp"
case textDocumentDeclaration = "textDocument/declaration"
case textDocumentDefinition = "textDocument/definition"
case textDocumentPrepareTypeHierarchy = "textDocument/prepareTypeHierarchy"
case textDocumentTypeDefinition = "textDocument/typeDefinition"
case textDocumentImplementation = "textDocument/implementation"
case textDocumentReferences = "textDocument/references"
Expand Down Expand Up @@ -204,6 +205,7 @@ public enum ClientRequest: Sendable {
case linkedEditingRange(LinkedEditingRangeParams, Handler<LinkedEditingRangeResponse>)
case prepareCallHierarchy(CallHierarchyPrepareParams, Handler<CallHierarchyPrepareResponse>)
case prepareRename(PrepareRenameParams, Handler<PrepareRenameResponse>)
case prepareTypeHierarchy(TypeHierarchyPrepareParams, Handler<PrepareTypeHeirarchyResponse>)
case rename(RenameParams, Handler<RenameResponse>)
case inlayHint(InlayHintParams, Handler<InlayHintResponse>)
case inlayHintResolve(InlayHint, Handler<InlayHintResponse>)
Expand Down Expand Up @@ -282,6 +284,8 @@ public enum ClientRequest: Sendable {
return .textDocumentPrepareCallHierarchy
case .prepareRename:
return .textDocumentPrepareRename
case .prepareTypeHierarchy:
return .textDocumentPrepareTypeHierarchy
case .rename:
return .textDocumentRename
case .inlayHint:
Expand Down

0 comments on commit c6ff09f

Please sign in to comment.