@@ -89,17 +89,11 @@ final class BuildServerBuildSystemTests: XCTestCase {
89
89
"""
90
90
] ,
91
91
buildServer: """
92
- import threading
93
-
94
92
class BuildServer(AbstractBuildServer):
95
- timer_has_fired: bool = False
96
-
97
- def timer_fired(self):
98
- self.timer_has_fired = True
99
- self.send_notification( " buildTarget/didChange " , {})
93
+ has_changed_targets: bool = False
100
94
101
95
def workspace_build_targets(self, request: Dict[str, object]) -> Dict[str, object]:
102
- if self.timer_has_fired :
96
+ if self.has_changed_targets :
103
97
return {
104
98
" targets " : [
105
99
{
@@ -112,11 +106,10 @@ final class BuildServerBuildSystemTests: XCTestCase {
112
106
]
113
107
}
114
108
else:
115
- threading.Timer(1, self.timer_fired).start()
116
109
return { " targets " : []}
117
110
118
111
def buildtarget_sources(self, request: Dict[str, object]) -> Dict[str, object]:
119
- assert self.timer_has_fired
112
+ assert self.has_changed_targets
120
113
return {
121
114
" items " : [
122
115
{
@@ -129,10 +122,14 @@ final class BuildServerBuildSystemTests: XCTestCase {
129
122
}
130
123
131
124
def textdocument_sourcekitoptions(self, request: Dict[str, object]) -> Dict[str, object]:
132
- assert self.timer_has_fired
125
+ assert self.has_changed_targets
133
126
return {
134
127
" compilerArguments " : [r " $TEST_DIR/Test.swift " , " -DDEBUG " , $SDK_ARGS]
135
128
}
129
+
130
+ def workspace_did_change_watched_files(self, notification: Dict[str, object]) -> None:
131
+ self.has_changed_targets = True
132
+ self.send_notification( " buildTarget/didChange " , {})
136
133
"""
137
134
)
138
135
@@ -144,6 +141,13 @@ final class BuildServerBuildSystemTests: XCTestCase {
144
141
)
145
142
XCTAssertEqual ( initialDiagnostics. fullReport? . items, [ ] )
146
143
144
+ // We use an arbitrary file change to signal to the BSP server that it should send the targets changed notification
145
+ project. testClient. send (
146
+ DidChangeWatchedFilesNotification ( changes: [
147
+ FileEvent ( uri: try DocumentURI ( string: " file:///dummy " ) , type: . created)
148
+ ] )
149
+ )
150
+
147
151
// But then the 1s timer in the build server should fire, we get a `buildTarget/didChange` notification and we have
148
152
// build settings for Test.swift
149
153
try await repeatUntilExpectedResult {
@@ -168,14 +172,8 @@ final class BuildServerBuildSystemTests: XCTestCase {
168
172
"""
169
173
] ,
170
174
buildServer: """
171
- import threading
172
-
173
175
class BuildServer(AbstractBuildServer):
174
- timer_has_fired: bool = False
175
-
176
- def timer_fired(self):
177
- self.timer_has_fired = True
178
- self.send_notification( " buildTarget/didChange " , {})
176
+ has_changed_settings: bool = False
179
177
180
178
def workspace_build_targets(self, request: Dict[str, object]) -> Dict[str, object]:
181
179
return {
@@ -203,15 +201,18 @@ final class BuildServerBuildSystemTests: XCTestCase {
203
201
}
204
202
205
203
def textdocument_sourcekitoptions(self, request: Dict[str, object]) -> Dict[str, object]:
206
- if self.timer_has_fired :
204
+ if self.has_changed_settings :
207
205
return {
208
206
" compilerArguments " : [r " $TEST_DIR/Test.swift " , " -DDEBUG " , $SDK_ARGS]
209
207
}
210
208
else:
211
- threading.Timer(1, self.timer_fired).start()
212
209
return {
213
210
" compilerArguments " : [r " $TEST_DIR/Test.swift " , $SDK_ARGS]
214
211
}
212
+
213
+ def workspace_did_change_watched_files(self, notification: Dict[str, object]) -> None:
214
+ self.has_changed_settings = True
215
+ self.send_notification( " buildTarget/didChange " , {})
215
216
"""
216
217
)
217
218
@@ -223,6 +224,13 @@ final class BuildServerBuildSystemTests: XCTestCase {
223
224
)
224
225
XCTAssertEqual ( initialDiagnostics. fullReport? . items. map ( \. message) , [ " DEBUG NOT SET " ] )
225
226
227
+ // We use an arbitrary file change to signal to the BSP server that it should send the targets changed notification
228
+ project. testClient. send (
229
+ DidChangeWatchedFilesNotification ( changes: [
230
+ FileEvent ( uri: try DocumentURI ( string: " file:///dummy " ) , type: . created)
231
+ ] )
232
+ )
233
+
226
234
// But then the 1s timer in the build server should fire, we get a `buildTarget/didChange` notification and we get
227
235
// build settings for Test.swift that include -DDEBUG
228
236
try await repeatUntilExpectedResult {
0 commit comments