-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerNotificationHandler.swift
More file actions
49 lines (44 loc) · 1.87 KB
/
ServerNotificationHandler.swift
File metadata and controls
49 lines (44 loc) · 1.87 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
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
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 "featureFlagsNotification":
if let data = try? JSONEncoder().encode(notification.params),
let featureFlags = try? JSONDecoder().decode(FeatureFlags.self, from: data) {
featureFlagNotifier.handleFeatureFlagNotification(featureFlags)
}
break
default:
break
}
}
}
}