this repo has no description
www.jonmsterling.com/01HC/
1// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
2//
3// SPDX-License-Identifier: MPL-2.0
4
5import Foundation
6import JSONRPC
7import LanguageServer
8import LanguageServerProtocol
9import Logging
10
11final class Server {
12 private let connection: JSONRPCClientConnection
13 private let eventHandler: EventHandler
14
15 init() {
16 let channel = DataChannel.stdio()
17 connection = JSONRPCClientConnection(channel)
18 eventHandler = EventHandler(connection: connection)
19 }
20
21 func start() async throws {
22 do {
23 Logger.shared.debug("Starting")
24 try await startEventLoop()
25 } catch {
26 Logger.shared.error("Server error: \(error)")
27 throw error
28 }
29 }
30
31 func startEventLoop() async throws {
32 for await event in await connection.eventSequence {
33 try await handle(event: event)
34 }
35 }
36
37 func handle(event: ClientEvent) async throws {
38 switch event {
39 case .request(let id, let request):
40 await eventHandler.handleRequest(id: id, request: request)
41 case .notification(let notification):
42 await eventHandler.handleNotification(notification)
43 case .error(_): ()
44 }
45 }
46}
47
48@main
49struct PterodactylLanguageServer {
50 static func main() async throws {
51 let server = Server()
52 try await server.start()
53 }
54}