@@ -16,6 +16,8 @@ import SKSupport
16
16
import Foundation
17
17
import BuildServerProtocol
18
18
19
+ typealias Notification = LanguageServerProtocol . Notification
20
+
19
21
/// A `BuildSystem` based on communicating with a build server
20
22
///
21
23
/// Provides build settings from a build server launched based on a
@@ -25,19 +27,24 @@ public final class BuildServerBuildSystem {
25
27
let projectRoot : AbsolutePath
26
28
let buildFolder : AbsolutePath ?
27
29
let serverConfig : BuildServerConfig
30
+ let requestQueue : DispatchQueue
28
31
29
32
var handler : BuildServerHandler ?
30
33
var buildServer : Connection ?
31
34
public private( set) var indexStorePath : AbsolutePath ?
32
35
33
36
/// Delegate to handle any build system events.
34
- public weak var delegate : BuildSystemDelegate ? = nil
37
+ public weak var delegate : BuildSystemDelegate ? {
38
+ get { return self . handler? . delegate }
39
+ set { self . handler? . delegate = newValue }
40
+ }
35
41
36
42
public init ( projectRoot: AbsolutePath , buildFolder: AbsolutePath ? , fileSystem: FileSystem = localFileSystem) throws {
37
43
let configPath = projectRoot. appending ( component: " buildServer.json " )
38
44
let config = try loadBuildServerConfig ( path: configPath, fileSystem: fileSystem)
39
45
self . buildFolder = buildFolder
40
46
self . projectRoot = projectRoot
47
+ self . requestQueue = DispatchQueue ( label: " build_server_request_queue " )
41
48
self . serverConfig = config
42
49
try self . initializeBuildServer ( )
43
50
}
@@ -114,24 +121,43 @@ private func readReponseDataKey(data: LSPAny?, key: String) -> String? {
114
121
}
115
122
116
123
final class BuildServerHandler : LanguageServerEndpoint {
117
- override func _registerBuiltinHandlers( ) { }
124
+
125
+ public weak var delegate : BuildSystemDelegate ? = nil
126
+
127
+ override func _registerBuiltinHandlers( ) {
128
+ _register ( BuildServerHandler . handleFileOptionsChanged)
129
+ }
130
+
131
+ func handleFileOptionsChanged( _ notification: Notification < FileOptionsChangedNotification > ) {
132
+ // TODO: add delegate method to include the changed settings directly
133
+ self . delegate? . fileBuildSettingsChanged ( [ notification. params. uri] )
134
+ }
118
135
}
119
136
120
137
extension BuildServerBuildSystem : BuildSystem {
121
138
122
139
/// Register the given file for build-system level change notifications, such as command
123
140
/// line flag changes, dependency changes, etc.
124
141
public func registerForChangeNotifications( for url: LanguageServerProtocol . URL ) {
125
- // TODO: Implement via BSP extensions.
142
+ let request = RegisterForChanges ( uri: url, action: . register)
143
+ _ = self . buildServer? . send ( request, queue: requestQueue, reply: { result in
144
+ if let error = result. failure {
145
+ log ( " error registering \( url) : \( error) " , level: . error)
146
+ }
147
+ } )
126
148
}
127
149
128
150
/// Unregister the given file for build-system level change notifications, such as command
129
151
/// line flag changes, dependency changes, etc.
130
152
public func unregisterForChangeNotifications( for url: LanguageServerProtocol . URL ) {
131
- // TODO: Implement via BSP extensions.
153
+ let request = RegisterForChanges ( uri: url, action: . unregister)
154
+ _ = self . buildServer? . send ( request, queue: requestQueue, reply: { result in
155
+ if let error = result. failure {
156
+ log ( " error unregistering \( url) : \( error) " , level: . error)
157
+ }
158
+ } )
132
159
}
133
160
134
-
135
161
public var indexDatabasePath : AbsolutePath ? {
136
162
return buildFolder? . appending ( components: " index " , " db " )
137
163
}
0 commit comments