11import BuiltinExtension
22import CodeiumService
33import Combine
4+ import CommandHandler
45import Dependencies
56import Foundation
67import GitHubCopilotService
@@ -24,13 +25,14 @@ import ProService
2425
2526/// The running extension service.
2627public final class Service {
28+ @MainActor
2729 public static let shared = Service ( )
2830
29- @WorkspaceActor
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,14 +45,38 @@ public final class Service {
4345 @Dependency ( \. toast) var toast
4446 var cancellable = Set < AnyCancellable > ( )
4547
48+ @MainActor
4649 private init ( ) {
4750 @Dependency ( \. workspacePool) var workspacePool
51+ let commandHandler = PseudoCommandHandler ( )
52+ UniversalCommandHandler . shared. commandHandler = commandHandler
53+ self . commandHandler = commandHandler
54+
55+ realtimeSuggestionController = . init( )
56+ scheduledCleaner = . init( )
57+ let guiController = GraphicalUserInterfaceController ( )
58+ self . guiController = guiController
59+ globalShortcutManager = . init( guiController: guiController)
60+
61+ keyBindingManager = . init(
62+ workspacePool: workspacePool,
63+ acceptSuggestion: {
64+ Task { await PseudoCommandHandler ( ) . acceptSuggestion ( ) }
65+ } ,
66+ dismissSuggestion: {
67+ Task { await PseudoCommandHandler ( ) . dismissSuggestion ( ) }
68+ }
69+ )
70+
71+ #if canImport(ProService)
72+ proService = ProService ( )
73+ #endif
4874
4975 BuiltinExtensionManager . shared. setupExtensions ( [
5076 GitHubCopilotExtension ( workspacePool: workspacePool) ,
5177 CodeiumExtension ( workspacePool: workspacePool) ,
5278 ] )
53- scheduledCleaner = . init ( )
79+
5480 workspacePool. registerPlugin {
5581 SuggestionServiceWorkspacePlugin ( workspace: $0) { SuggestionService . service ( ) }
5682 }
@@ -63,21 +89,6 @@ public final class Service {
6389 workspacePool. registerPlugin {
6490 BuiltinExtensionWorkspacePlugin ( workspace: $0)
6591 }
66- self . workspacePool = workspacePool
67- globalShortcutManager = . init( guiController: guiController)
68- keyBindingManager = . init(
69- workspacePool: workspacePool,
70- acceptSuggestion: {
71- Task { await PseudoCommandHandler ( ) . acceptSuggestion ( ) }
72- } ,
73- dismissSuggestion: {
74- Task { await PseudoCommandHandler ( ) . dismissSuggestion ( ) }
75- }
76- )
77-
78- #if canImport(ProService)
79- proService = ProService ( )
80- #endif
8192
8293 scheduledCleaner. service = self
8394 }
@@ -100,9 +111,10 @@ public final class Service {
100111 . removeDuplicates ( )
101112 . filter { $0 != . init( fileURLWithPath: " / " ) }
102113 . compactMap { $0 }
103- . sink { [ weak self ] fileURL in
114+ . sink { fileURL in
104115 Task {
105- try await self ? . workspacePool
116+ @Dependency ( \. workspacePool) var workspacePool
117+ return try await workspacePool
106118 . fetchOrCreateWorkspaceAndFilespace ( fileURL: fileURL)
107119 }
108120 } . store ( in: & cancellable)
@@ -128,7 +140,7 @@ public extension Service {
128140 ) {
129141 do {
130142 #if canImport(ProService)
131- try Service . shared . proService. handleXPCServiceRequests (
143+ try proService. handleXPCServiceRequests (
132144 endpoint: endpoint,
133145 requestBody: requestBody,
134146 reply: reply
0 commit comments