diff --git a/README.md b/README.md index 696420a..6ddf098 100644 --- a/README.md +++ b/README.md @@ -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 | ✅ | diff --git a/Sources/LSPClient/Client.JSONRPCServerConnection.swift b/Sources/LSPClient/Client.JSONRPCServerConnection.swift index 679d14c..d9b21ff 100644 --- a/Sources/LSPClient/Client.JSONRPCServerConnection.swift +++ b/Sources/LSPClient/Client.JSONRPCServerConnection.swift @@ -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, _): diff --git a/Sources/LSPClient/Client.ServerConnection.swift b/Sources/LSPClient/Client.ServerConnection.swift index 6ea6c17..7af2c00 100644 --- a/Sources/LSPClient/Client.ServerConnection.swift +++ b/Sources/LSPClient/Client.ServerConnection.swift @@ -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)) } diff --git a/Sources/LSPServer/Server.JSONRPCClientConnection.swift b/Sources/LSPServer/Server.JSONRPCClientConnection.swift index b363604..fd7d0a6 100644 --- a/Sources/LSPServer/Server.JSONRPCClientConnection.swift +++ b/Sources/LSPServer/Server.JSONRPCClientConnection.swift @@ -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: diff --git a/Sources/LSPServer/Server.RequestHandler.swift b/Sources/LSPServer/Server.RequestHandler.swift index 8d74851..b7142fa 100644 --- a/Sources/LSPServer/Server.RequestHandler.swift +++ b/Sources/LSPServer/Server.RequestHandler.swift @@ -37,6 +37,7 @@ public protocol RequestHandler : ErrorHandler { func linkedEditingRange(id: JSONId, params: LinkedEditingRangeParams) async -> Result func prepareCallHierarchy(id: JSONId, params: CallHierarchyPrepareParams) async -> Result func prepareRename(id: JSONId, params: PrepareRenameParams) async -> Result + func prepareTypeHeirarchy(id: JSONId, params: TypeHierarchyPrepareParams) async -> Result func rename(id: JSONId, params: RenameParams) async -> Result func documentLink(id: JSONId, params: DocumentLinkParams) async -> Result func documentLinkResolve(id: JSONId, params: DocumentLink) async -> Result @@ -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): @@ -203,6 +206,7 @@ public extension RequestHandler { func linkedEditingRange(id: JSONId, params: LinkedEditingRangeParams) async -> Result { .failure(NotImplementedError) } func prepareCallHierarchy(id: JSONId, params: CallHierarchyPrepareParams) async -> Result { .failure(NotImplementedError) } func prepareRename(id: JSONId, params: PrepareRenameParams) async -> Result { .failure(NotImplementedError) } + func prepareTypeHeirarchy(id: JSONId, params: TypeHierarchyPrepareParams) async -> Result { .failure(NotImplementedError) } func rename(id: JSONId, params: RenameParams) async -> Result { .failure(NotImplementedError) } func inlayHint(id: JSONId, params: InlayHintParams) async -> Result { .failure(NotImplementedError) } func inlayHintResolve(id: JSONId, params: InlayHint) async -> Result { .failure(NotImplementedError) } diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/TypeHeirarchy.swift b/Sources/LanguageServerProtocol/LanguageFeatures/TypeHeirarchy.swift new file mode 100644 index 0000000..9419dcc --- /dev/null +++ b/Sources/LanguageServerProtocol/LanguageFeatures/TypeHeirarchy.swift @@ -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]? diff --git a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift index 991ce65..54af5e2 100644 --- a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift +++ b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift @@ -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" @@ -204,6 +205,7 @@ public enum ClientRequest: Sendable { case linkedEditingRange(LinkedEditingRangeParams, Handler) case prepareCallHierarchy(CallHierarchyPrepareParams, Handler) case prepareRename(PrepareRenameParams, Handler) + case prepareTypeHierarchy(TypeHierarchyPrepareParams, Handler) case rename(RenameParams, Handler) case inlayHint(InlayHintParams, Handler) case inlayHintResolve(InlayHint, Handler) @@ -282,6 +284,8 @@ public enum ClientRequest: Sendable { return .textDocumentPrepareCallHierarchy case .prepareRename: return .textDocumentPrepareRename + case .prepareTypeHierarchy: + return .textDocumentPrepareTypeHierarchy case .rename: return .textDocumentRename case .inlayHint: