@@ -89,17 +89,11 @@ final class BuildServerBuildSystemTests: XCTestCase {
8989 """
9090 ] ,
9191 buildServer: """
92- import threading
93-
9492 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
10094
10195 def workspace_build_targets(self, request: Dict[str, object]) -> Dict[str, object]:
102- if self.timer_has_fired :
96+ if self.has_changed_targets :
10397 return {
10498 " targets " : [
10599 {
@@ -112,11 +106,10 @@ final class BuildServerBuildSystemTests: XCTestCase {
112106 ]
113107 }
114108 else:
115- threading.Timer(1, self.timer_fired).start()
116109 return { " targets " : []}
117110
118111 def buildtarget_sources(self, request: Dict[str, object]) -> Dict[str, object]:
119- assert self.timer_has_fired
112+ assert self.has_changed_targets
120113 return {
121114 " items " : [
122115 {
@@ -129,10 +122,14 @@ final class BuildServerBuildSystemTests: XCTestCase {
129122 }
130123
131124 def textdocument_sourcekitoptions(self, request: Dict[str, object]) -> Dict[str, object]:
132- assert self.timer_has_fired
125+ assert self.has_changed_targets
133126 return {
134127 " compilerArguments " : [r " $TEST_DIR/Test.swift " , " -DDEBUG " , $SDK_ARGS]
135128 }
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 " , {})
136133 """
137134 )
138135
@@ -144,6 +141,13 @@ final class BuildServerBuildSystemTests: XCTestCase {
144141 )
145142 XCTAssertEqual ( initialDiagnostics. fullReport? . items, [ ] )
146143
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+
147151 // But then the 1s timer in the build server should fire, we get a `buildTarget/didChange` notification and we have
148152 // build settings for Test.swift
149153 try await repeatUntilExpectedResult {
@@ -168,14 +172,8 @@ final class BuildServerBuildSystemTests: XCTestCase {
168172 """
169173 ] ,
170174 buildServer: """
171- import threading
172-
173175 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
179177
180178 def workspace_build_targets(self, request: Dict[str, object]) -> Dict[str, object]:
181179 return {
@@ -203,15 +201,18 @@ final class BuildServerBuildSystemTests: XCTestCase {
203201 }
204202
205203 def textdocument_sourcekitoptions(self, request: Dict[str, object]) -> Dict[str, object]:
206- if self.timer_has_fired :
204+ if self.has_changed_settings :
207205 return {
208206 " compilerArguments " : [r " $TEST_DIR/Test.swift " , " -DDEBUG " , $SDK_ARGS]
209207 }
210208 else:
211- threading.Timer(1, self.timer_fired).start()
212209 return {
213210 " compilerArguments " : [r " $TEST_DIR/Test.swift " , $SDK_ARGS]
214211 }
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 " , {})
215216 """
216217 )
217218
@@ -223,6 +224,13 @@ final class BuildServerBuildSystemTests: XCTestCase {
223224 )
224225 XCTAssertEqual ( initialDiagnostics. fullReport? . items. map ( \. message) , [ " DEBUG NOT SET " ] )
225226
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+
226234 // But then the 1s timer in the build server should fire, we get a `buildTarget/didChange` notification and we get
227235 // build settings for Test.swift that include -DDEBUG
228236 try await repeatUntilExpectedResult {
0 commit comments