forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerRequestHandler.swift
More file actions
46 lines (42 loc) · 1.71 KB
/
ServerRequestHandler.swift
File metadata and controls
46 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Foundation
import Combine
import JSONRPC
import LanguageClient
import LanguageServerProtocol
import Logger
protocol ServerRequestHandler {
func handleRequest(_ request: AnyJSONRPCRequest, callback: @escaping (AnyJSONRPCResponse) -> Void)
}
class ServerRequestHandlerImpl : ServerRequestHandler {
public static let shared = ServerRequestHandlerImpl()
private let conversationContextHandler: ConversationContextHandler = ConversationContextHandlerImpl.shared
func handleRequest(_ request: AnyJSONRPCRequest, callback: @escaping (AnyJSONRPCResponse) -> Void) {
let methodName = request.method
switch methodName {
case "conversation/context":
do {
let params = try JSONEncoder().encode(request.params)
let contextParams = try JSONDecoder().decode(ConversationContextParams.self, from: params)
conversationContextHandler.handleConversationContext(
ConversationContextRequest(id: request.id, method: request.method, params: contextParams),
completion: callback)
} catch {
callback(
AnyJSONRPCResponse(
id: request.id,
result: JSONValue.array([
JSONValue.null,
JSONValue.hash([
"code": .number(-32602/* Invalid params */),
"message": .string("Error: \(error.localizedDescription)")])
])
)
)
Logger.gitHubCopilot.error(error)
}
break
default:
break
}
}
}