@@ -25,12 +25,14 @@ import ProService
2525
2626/// The running extension service.
2727public final class Service {
28+ @MainActor
2829 public static let shared = Service ( )
2930
30- let workspacePool = WorkspacePool ( )
31+ @ Dependency ( \ . workspacePool) var workspacePool
3132 @MainActor
32- public let guiController = GraphicalUserInterfaceController ( )
33- public let realtimeSuggestionController = RealtimeSuggestionController ( )
33+ public let guiController : GraphicalUserInterfaceController
34+ public let commandHandler : CommandHandler
35+ public let realtimeSuggestionController : RealtimeSuggestionController
3436 public let scheduledCleaner : ScheduledCleaner
3537 let globalShortcutManager : GlobalShortcutManager
3638 let keyBindingManager : KeyBindingManager
@@ -43,15 +45,47 @@ public final class Service {
4345 @Dependency ( \. toast) var toast
4446 var cancellable = Set < AnyCancellable > ( )
4547
48+ @MainActor
4649 private init ( ) {
47- WorkspacePoolDependencyKey . liveValue = workspacePool
48- CommandHandlerDependencyKey . liveValue = PseudoCommandHandler ( )
50+ @Dependency ( \. workspacePool) var workspacePool
51+ let commandHandler = PseudoCommandHandler ( )
52+ self . commandHandler = commandHandler
53+
54+ func setup< R> ( _ operation: ( ) -> R ) -> R {
55+ withDependencies { values in
56+ values. commandHandler = commandHandler
57+ } operation: {
58+ operation ( ) //
59+ }
60+ }
61+
62+ realtimeSuggestionController = setup { . init( ) }
63+ scheduledCleaner = setup { . init( ) }
64+ let guiController = setup { GraphicalUserInterfaceController ( ) }
65+ self . guiController = guiController
66+ globalShortcutManager = setup { . init( guiController: guiController) }
67+
68+ keyBindingManager = setup {
69+ . init(
70+ workspacePool: workspacePool,
71+ acceptSuggestion: {
72+ Task { await PseudoCommandHandler ( ) . acceptSuggestion ( ) }
73+ } ,
74+ dismissSuggestion: {
75+ Task { await PseudoCommandHandler ( ) . dismissSuggestion ( ) }
76+ }
77+ )
78+ }
79+
80+ #if canImport(ProService)
81+ proService = setup { ProService ( ) }
82+ #endif
4983
5084 BuiltinExtensionManager . shared. setupExtensions ( [
5185 GitHubCopilotExtension ( workspacePool: workspacePool) ,
5286 CodeiumExtension ( workspacePool: workspacePool) ,
5387 ] )
54- scheduledCleaner = . init ( )
88+
5589 workspacePool. registerPlugin {
5690 SuggestionServiceWorkspacePlugin ( workspace: $0) { SuggestionService . service ( ) }
5791 }
@@ -64,21 +98,6 @@ public final class Service {
6498 workspacePool. registerPlugin {
6599 BuiltinExtensionWorkspacePlugin ( workspace: $0)
66100 }
67-
68- globalShortcutManager = . init( guiController: guiController)
69- keyBindingManager = . init(
70- workspacePool: workspacePool,
71- acceptSuggestion: {
72- Task { await PseudoCommandHandler ( ) . acceptSuggestion ( ) }
73- } ,
74- dismissSuggestion: {
75- Task { await PseudoCommandHandler ( ) . dismissSuggestion ( ) }
76- }
77- )
78-
79- #if canImport(ProService)
80- proService = ProService ( )
81- #endif
82101
83102 scheduledCleaner. service = self
84103 }
@@ -101,9 +120,10 @@ public final class Service {
101120 . removeDuplicates ( )
102121 . filter { $0 != . init( fileURLWithPath: " / " ) }
103122 . compactMap { $0 }
104- . sink { [ weak self ] fileURL in
123+ . sink { fileURL in
105124 Task {
106- try await self ? . workspacePool
125+ @Dependency ( \. workspacePool) var workspacePool
126+ return try await workspacePool
107127 . fetchOrCreateWorkspaceAndFilespace ( fileURL: fileURL)
108128 }
109129 } . store ( in: & cancellable)
0 commit comments