Skip to content

Commit eb597fd

Browse files
committed
Remove a couple of async wrapper functions
These are no longer needed as all callers are async now.
1 parent e1548a0 commit eb597fd

File tree

6 files changed

+31
-93
lines changed

6 files changed

+31
-93
lines changed

Sources/SKCore/BuildSystemManager.swift

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,7 @@ extension BuildSystemManager {
254254
}
255255

256256
extension BuildSystemManager: BuildSystemDelegate {
257-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has ben asyncified
258-
public nonisolated func fileBuildSettingsChanged(_ changes: Set<DocumentURI>) {
259-
Task {
260-
await fileBuildSettingsChangedImpl(changes)
261-
}
262-
}
263-
264-
public func fileBuildSettingsChangedImpl(_ changedFiles: Set<DocumentURI>) async {
257+
public func fileBuildSettingsChanged(_ changedFiles: Set<DocumentURI>) async {
265258
let changedWatchedFiles = changedFiles.flatMap({ mainFile in
266259
self.watchedFiles.filter { $1.mainFile == mainFile }.keys
267260
})
@@ -271,14 +264,7 @@ extension BuildSystemManager: BuildSystemDelegate {
271264
}
272265
}
273266

274-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has ben asyncified
275-
public nonisolated func filesDependenciesUpdated(_ changedFiles: Set<DocumentURI>) {
276-
Task {
277-
await filesDependenciesUpdatedImpl(changedFiles)
278-
}
279-
}
280-
281-
public func filesDependenciesUpdatedImpl(_ changedFiles: Set<DocumentURI>) async {
267+
public func filesDependenciesUpdated(_ changedFiles: Set<DocumentURI>) async {
282268
// Empty changes --> assume everything has changed.
283269
guard !changedFiles.isEmpty else {
284270
if let delegate = self._delegate {
@@ -295,27 +281,13 @@ extension BuildSystemManager: BuildSystemDelegate {
295281
}
296282
}
297283

298-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has ben asyncified
299-
public nonisolated func buildTargetsChanged(_ changes: [BuildTargetEvent]) {
300-
Task {
301-
await buildTargetsChangedImpl(changes)
302-
}
303-
}
304-
305-
public func buildTargetsChangedImpl(_ changes: [BuildTargetEvent]) async {
284+
public func buildTargetsChanged(_ changes: [BuildTargetEvent]) async {
306285
if let delegate = self._delegate {
307286
await delegate.buildTargetsChanged(changes)
308287
}
309288
}
310289

311-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has ben asyncified
312-
public nonisolated func fileHandlingCapabilityChanged() {
313-
Task {
314-
await fileHandlingCapabilityChangedImpl()
315-
}
316-
}
317-
318-
public func fileHandlingCapabilityChangedImpl() async {
290+
public func fileHandlingCapabilityChanged() async {
319291
if let delegate = self._delegate {
320292
await delegate.fileHandlingCapabilityChanged()
321293
}

Sources/SKCore/CompilationDatabaseBuildSystem.swift

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,16 @@ extension CompilationDatabaseBuildSystem: BuildSystem {
8787

8888
public var indexPrefixMappings: [PathPrefixMapping] { return [] }
8989

90-
public func buildSettings(for document: DocumentURI, language: Language) async throws -> FileBuildSettings? {
91-
return self.settings(for: document)
90+
public func buildSettings(for document: DocumentURI, language: Language) async -> FileBuildSettings? {
91+
guard let url = document.fileURL else {
92+
// We can't determine build settings for non-file URIs.
93+
return nil
94+
}
95+
guard let db = database(for: url),
96+
let cmd = db[url].first else { return nil }
97+
return FileBuildSettings(
98+
compilerArguments: Array(cmd.commandLine.dropFirst()),
99+
workingDirectory: cmd.directory)
92100
}
93101

94102
public func registerForChangeNotifications(for uri: DocumentURI, language: Language) async {
@@ -168,22 +176,3 @@ extension CompilationDatabaseBuildSystem: BuildSystem {
168176
}
169177
}
170178
}
171-
172-
extension CompilationDatabaseBuildSystem {
173-
private func settings(for uri: DocumentURI) -> FileBuildSettings? {
174-
guard let url = uri.fileURL else {
175-
// We can't determine build settings for non-file URIs.
176-
return nil
177-
}
178-
guard let db = database(for: url),
179-
let cmd = db[url].first else { return nil }
180-
return FileBuildSettings(
181-
compilerArguments: Array(cmd.commandLine.dropFirst()),
182-
workingDirectory: cmd.directory)
183-
}
184-
185-
/// Exposed for *testing*.
186-
public func _settings(for uri: DocumentURI) -> FileBuildSettings? {
187-
return self.settings(for: uri)
188-
}
189-
}

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,7 @@ extension SourceKitServer: MessageHandler {
606606
// MARK: - Build System Delegate
607607

608608
extension SourceKitServer: BuildSystemDelegate {
609-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has been asyncified
610-
public nonisolated func buildTargetsChanged(_ changes: [BuildTargetEvent]) {
609+
public func buildTargetsChanged(_ changes: [BuildTargetEvent]) {
611610
// TODO: do something with these changes once build target support is in place
612611
}
613612

@@ -622,19 +621,11 @@ extension SourceKitServer: BuildSystemDelegate {
622621
return documentManager.openDocuments.intersection(changes)
623622
}
624623

625-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has been asyncified
626-
/// Non-async variant that executes `fileBuildSettingsChangedImpl` in a new task.
627-
public nonisolated func fileBuildSettingsChanged(_ changedFiles: Set<DocumentURI>) {
628-
Task {
629-
await self.fileBuildSettingsChangedImpl(changedFiles)
630-
}
631-
}
632-
633624
/// Handle a build settings change notification from the `BuildSystem`.
634625
/// This has two primary cases:
635626
/// - Initial settings reported for a given file, now we can fully open it
636627
/// - Changed settings for an already open file
637-
public func fileBuildSettingsChangedImpl(_ changedFiles: Set<DocumentURI>) async {
628+
public func fileBuildSettingsChanged(_ changedFiles: Set<DocumentURI>) async {
638629
for uri in changedFiles {
639630
guard self.documentManager.openDocuments.contains(uri) else {
640631
continue
@@ -648,17 +639,10 @@ extension SourceKitServer: BuildSystemDelegate {
648639
}
649640
}
650641

651-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has been asyncified
652-
public nonisolated func filesDependenciesUpdated(_ changedFiles: Set<DocumentURI>) {
653-
Task {
654-
await filesDependenciesUpdatedImpl(changedFiles)
655-
}
656-
}
657-
658642
/// Handle a dependencies updated notification from the `BuildSystem`.
659643
/// We inform the respective language services as long as the given file is open
660644
/// (not queued for opening).
661-
public func filesDependenciesUpdatedImpl(_ changedFiles: Set<DocumentURI>) async {
645+
public func filesDependenciesUpdated(_ changedFiles: Set<DocumentURI>) async {
662646
// Split the changedFiles into the workspaces they belong to.
663647
// Then invoke affectedOpenDocumentsForChangeSet for each workspace with its affected files.
664648
let changedFilesAndWorkspace = await changedFiles.asyncMap {
@@ -678,14 +662,7 @@ extension SourceKitServer: BuildSystemDelegate {
678662
}
679663
}
680664

681-
// FIXME: (async) Make this method isolated once `BuildSystemDelegate` has been asyncified
682-
public nonisolated func fileHandlingCapabilityChanged() {
683-
Task {
684-
await fileHandlingCapabilityChangedImpl()
685-
}
686-
}
687-
688-
public func fileHandlingCapabilityChangedImpl() {
665+
public func fileHandlingCapabilityChanged() {
689666
self.uriToWorkspaceCache = [:]
690667
}
691668
}

Tests/SKCoreTests/BuildSystemManagerTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ final class BuildSystemManagerTests: XCTestCase {
108108
bs.map[a] = nil
109109
let changed = expectation(description: "changed settings")
110110
await del.setExpected([(a, .swift, nil, changed, #file, #line)])
111-
bsm.fileBuildSettingsChanged([a])
111+
await bsm.fileBuildSettingsChanged([a])
112112
try await fulfillmentOfOrThrow([changed])
113113
}
114114

@@ -129,7 +129,7 @@ final class BuildSystemManagerTests: XCTestCase {
129129
bs.map[a] = FileBuildSettings(compilerArguments: ["x"])
130130
let changed = expectation(description: "changed settings")
131131
await del.setExpected([(a, .swift, bs.map[a]!, changed, #file, #line)])
132-
bsm.fileBuildSettingsChanged([a])
132+
await bsm.fileBuildSettingsChanged([a])
133133
try await fulfillmentOfOrThrow([changed])
134134
}
135135

@@ -152,13 +152,13 @@ final class BuildSystemManagerTests: XCTestCase {
152152
bs.map[a] = FileBuildSettings(compilerArguments: ["non-fallback", "args"])
153153
let changed = expectation(description: "changed settings")
154154
await del.setExpected([(a, .swift, bs.map[a]!, changed, #file, #line)])
155-
bsm.fileBuildSettingsChanged([a])
155+
await bsm.fileBuildSettingsChanged([a])
156156
try await fulfillmentOfOrThrow([changed])
157157

158158
bs.map[a] = nil
159159
let revert = expectation(description: "revert to fallback settings")
160160
await del.setExpected([(a, .swift, fallbackSettings, revert, #file, #line)])
161-
bsm.fileBuildSettingsChanged([a])
161+
await bsm.fileBuildSettingsChanged([a])
162162
try await fulfillmentOfOrThrow([revert])
163163
}
164164

@@ -186,7 +186,7 @@ final class BuildSystemManagerTests: XCTestCase {
186186
bs.map[b] = FileBuildSettings(compilerArguments: ["yy"])
187187
let changed = expectation(description: "changed settings")
188188
await del.setExpected([(a, .swift, bs.map[a]!, changed, #file, #line)])
189-
bsm.fileBuildSettingsChanged([a])
189+
await bsm.fileBuildSettingsChanged([a])
190190
try await fulfillmentOfOrThrow([changed])
191191

192192
// Test multiple changes.
@@ -198,7 +198,7 @@ final class BuildSystemManagerTests: XCTestCase {
198198
(a, .swift, bs.map[a]!, changedBothA, #file, #line),
199199
(b, .swift, bs.map[b]!, changedBothB, #file, #line),
200200
])
201-
bsm.fileBuildSettingsChanged([a, b])
201+
await bsm.fileBuildSettingsChanged([a, b])
202202
try await fulfillmentOfOrThrow([changedBothA, changedBothB])
203203
}
204204

@@ -228,7 +228,7 @@ final class BuildSystemManagerTests: XCTestCase {
228228
bs.map[b] = nil
229229
let changed = expectation(description: "changed settings")
230230
await del.setExpected([(b, .swift, nil, changed, #file, #line)])
231-
bsm.fileBuildSettingsChanged([b])
231+
await bsm.fileBuildSettingsChanged([b])
232232
try await fulfillmentOfOrThrow([changed])
233233
}
234234

@@ -327,7 +327,7 @@ final class BuildSystemManagerTests: XCTestCase {
327327
(h1, .c, newArgsH1, changed1, #file, #line),
328328
(h2, .c, newArgsH2, changed2, #file, #line),
329329
])
330-
bsm.fileBuildSettingsChanged([cpp])
330+
await bsm.fileBuildSettingsChanged([cpp])
331331

332332
try await fulfillmentOfOrThrow([changed1, changed2])
333333
}
@@ -370,7 +370,7 @@ final class BuildSystemManagerTests: XCTestCase {
370370
await bsm.unregisterForChangeNotifications(for: c)
371371
// At this point only b is registered, but that can race with notifications,
372372
// so ensure nothing bad happens and we still get the notification for b.
373-
bsm.fileBuildSettingsChanged([a, b, c])
373+
await bsm.fileBuildSettingsChanged([a, b, c])
374374

375375
try await fulfillmentOfOrThrow([changedB])
376376
}
@@ -396,7 +396,7 @@ final class BuildSystemManagerTests: XCTestCase {
396396
let depUpdate2 = expectation(description: "dependencies update 2")
397397
await del.setExpectedDependenciesUpdate([(a, depUpdate2, #file, #line)])
398398

399-
bsm.filesDependenciesUpdated([a])
399+
await bsm.filesDependenciesUpdated([a])
400400
try await fulfillmentOfOrThrow([depUpdate2])
401401
}
402402
}

Tests/SKCoreTests/CompilationDatabaseTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ final class CompilationDatabaseTests: XCTestCase {
217217
}
218218
]
219219
""") { buildSystem in
220-
let settings = await buildSystem._settings(for: DocumentURI(URL(fileURLWithPath: "/a/a.swift")))
220+
let settings = await buildSystem.buildSettings(for: DocumentURI(URL(fileURLWithPath: "/a/a.swift")), language: .swift)
221221
XCTAssertNotNil(settings)
222222
XCTAssertEqual(settings?.workingDirectory, "/a")
223223
XCTAssertEqual(settings?.compilerArguments, ["-swift-version", "4", "/a/a.swift"])

Tests/SourceKitLSPTests/SourceKitTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ final class SKTests: XCTestCase {
243243
XCTAssertEqual(note.params.diagnostics.count, 0)
244244
finishExpectation.fulfill()
245245
}
246-
server.filesDependenciesUpdated([DocumentURI(moduleRef.url)])
246+
await server.filesDependenciesUpdated([DocumentURI(moduleRef.url)])
247247

248248
try await fulfillmentOfOrThrow([finishExpectation])
249249
}
@@ -286,7 +286,7 @@ final class SKTests: XCTestCase {
286286
XCTAssertEqual(note.params.diagnostics.count, 0)
287287
finishExpectation.fulfill()
288288
}
289-
server.filesDependenciesUpdated([DocumentURI(moduleRef.url)])
289+
await server.filesDependenciesUpdated([DocumentURI(moduleRef.url)])
290290

291291
try await fulfillmentOfOrThrow([finishExpectation])
292292
}

0 commit comments

Comments
 (0)