Skip to content

Commit 1eed5bb

Browse files
committed
Move filespace creation on editor change to Service
1 parent e17ce5a commit 1eed5bb

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ public actor RealtimeSuggestionController {
4343
}
4444

4545
private func handleFocusElementChange(_ sourceEditor: SourceEditor) {
46-
Task { // Notify suggestion service for open file.
47-
try await Task.sleep(nanoseconds: 500_000_000)
48-
guard let fileURL = await XcodeInspector.shared.safe.realtimeActiveDocumentURL
49-
else { return }
50-
_ = try await Service.shared.workspacePool
51-
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
52-
}
53-
5446
self.sourceEditor = sourceEditor
5547

5648
let notificationsFromEditor = sourceEditor.axNotifications

Core/Sources/Service/Service.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Combine
12
import Dependencies
23
import Foundation
34
import SuggestionService
@@ -33,6 +34,7 @@ public final class Service {
3334
#endif
3435

3536
@Dependency(\.toast) var toast
37+
var cancellable = Set<AnyCancellable>()
3638

3739
private init() {
3840
@Dependency(\.workspacePool) var workspacePool
@@ -70,6 +72,19 @@ public final class Service {
7072
#endif
7173
DependencyUpdater().update()
7274
globalShortcutManager.start()
75+
76+
Task {
77+
await XcodeInspector.shared.safe.$activeDocumentURL
78+
.removeDuplicates()
79+
.filter { $0 != .init(fileURLWithPath: "/") }
80+
.compactMap { $0 }
81+
.sink { [weak self] fileURL in
82+
Task {
83+
try await self?.workspacePool
84+
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
85+
}
86+
}.store(in: &cancellable)
87+
}
7388
}
7489
}
7590

0 commit comments

Comments
 (0)