-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathServerNotificationHandler.swift
More file actions
75 lines (70 loc) · 3.15 KB
/
ServerNotificationHandler.swift
File metadata and controls
75 lines (70 loc) · 3.15 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import Combine
import Foundation
import JSONRPC
import LanguageServerProtocol
protocol ServerNotificationHandler {
var protocolProgressSubject: PassthroughSubject<ProgressParams, Never> { get }
func handleNotification(_ notification: AnyJSONRPCNotification)
}
class ServerNotificationHandlerImpl: ServerNotificationHandler {
public static let shared = ServerNotificationHandlerImpl()
var protocolProgressSubject: PassthroughSubject<LanguageServerProtocol.ProgressParams, Never>
var conversationProgressHandler: ConversationProgressHandler = ConversationProgressHandlerImpl.shared
var featureFlagNotifier: FeatureFlagNotifier = FeatureFlagNotifierImpl.shared
var copilotPolicyNotifier: CopilotPolicyNotifier = CopilotPolicyNotifierImpl.shared
var compressionHandler: CompressionHandler = CompressionHandlerImpl.shared
init() {
self.protocolProgressSubject = PassthroughSubject<ProgressParams, Never>()
}
func handleNotification(_ notification: AnyJSONRPCNotification) {
let methodName = notification.method
if let method = ServerNotification.Method(rawValue: methodName) {
switch method {
case .windowLogMessage:
break
case .protocolProgress:
if let data = try? JSONEncoder().encode(notification.params),
let progress = try? JSONDecoder().decode(ProgressParams.self, from: data) {
conversationProgressHandler.handleConversationProgress(progress)
}
default:
break
}
} else {
switch methodName {
case "copilot/didChangeFeatureFlags":
if let data = try? JSONEncoder().encode(notification.params),
let didChangeFeatureFlagsParams = try? JSONDecoder().decode(
DidChangeFeatureFlagsParams.self,
from: data
) {
featureFlagNotifier.handleFeatureFlagNotification(didChangeFeatureFlagsParams)
}
break
case "policy/didChange":
if let data = try? JSONEncoder().encode(notification.params),
let policy = try? JSONDecoder().decode(
CopilotPolicy.self,
from: data
) {
copilotPolicyNotifier.handleCopilotPolicyNotification(policy)
}
break
case "$/copilot/compressionStarted":
if let payload = GitHubCopilotNotification.CompressionStartedNotification
.decode(fromParams: notification.params) {
compressionHandler.onCompressionStarted.send(payload.conversationId)
}
break
case "$/copilot/compressionCompleted":
if let payload = GitHubCopilotNotification.CompressionCompletedNotification
.decode(fromParams: notification.params) {
compressionHandler.onCompressionCompleted.send(payload)
}
break
default:
break
}
}
}
}