11import ChatService
2- import SuggestionModel
3- import GitHubCopilotService
42import Environment
53import Foundation
4+ import GitHubCopilotService
65import Logger
76import Preferences
87import SuggestionInjector
8+ import SuggestionModel
9+ import SuggestionService
910import XPCShared
1011
1112@ServiceActor
@@ -91,25 +92,25 @@ final class Workspace {
9192 ] , context: nil
9293 )
9394
94- private var _copilotSuggestionService : GitHubCopilotSuggestionServiceType ?
95+ private var _suggestionService : SuggestionServiceType ?
9596
96- private var copilotSuggestionService : GitHubCopilotSuggestionServiceType ? {
97+ private var suggestionService : SuggestionServiceType ? {
9798 // Check if the workspace is disabled.
9899 let isSuggestionDisabledGlobally = UserDefaults . shared
99100 . value ( for: \. disableSuggestionFeatureGlobally)
100101 if isSuggestionDisabledGlobally {
101102 let enabledList = UserDefaults . shared. value ( for: \. suggestionFeatureEnabledProjectList)
102103 if !enabledList. contains ( where: { path in projectRootURL. path. hasPrefix ( path) } ) {
103104 // If it's disable, remove the service
104- _copilotSuggestionService = nil
105+ _suggestionService = nil
105106 return nil
106107 }
107108 }
108109
109- if _copilotSuggestionService == nil {
110- _copilotSuggestionService = Environment . createSuggestionService ( projectRootURL)
110+ if _suggestionService == nil {
111+ _suggestionService = Environment . createSuggestionService ( projectRootURL)
111112 }
112- return _copilotSuggestionService
113+ return _suggestionService
113114 }
114115
115116 var isSuggestionFeatureEnabled : Bool {
@@ -129,10 +130,10 @@ final class Workspace {
129130
130131 userDefaultsObserver. onChange = { [ weak self] in
131132 guard let self else { return }
132- _ = self . copilotSuggestionService
133+ _ = self . suggestionService
133134 }
134135 }
135-
136+
136137 func refreshUpdateTime( ) {
137138 lastSuggestionUpdateTime = Environment . now ( )
138139 }
@@ -219,15 +220,16 @@ extension Workspace {
219220
220221 filespace. suggestionSourceSnapshot = snapshot
221222
222- guard let copilotSuggestionService else { throw SuggestionFeatureDisabledError ( ) }
223- let completions = try await copilotSuggestionService . getCompletions (
223+ guard let suggestionService else { throw SuggestionFeatureDisabledError ( ) }
224+ let completions = try await suggestionService . getSuggestions (
224225 fileURL: fileURL,
225226 content: editor. lines. joined ( separator: " " ) ,
226227 cursorPosition: editor. cursorPosition,
227228 tabSize: editor. tabSize,
228229 indentSize: editor. indentSize,
229230 usesTabsForIndentation: editor. usesTabsForIndentation,
230- ignoreSpaceOnlySuggestions: true
231+ ignoreSpaceOnlySuggestions: true ,
232+ referenceFileURL: filespaces. values. map ( \. fileURL)
231233 )
232234
233235 filespace. suggestions = completions
@@ -271,7 +273,7 @@ extension Workspace {
271273 filespaces [ fileURL] ? . usesTabsForIndentation = editor. usesTabsForIndentation
272274 }
273275 Task {
274- await copilotSuggestionService ? . notifyRejected ( filespaces [ fileURL] ? . suggestions ?? [ ] )
276+ await suggestionService ? . notifyRejected ( filespaces [ fileURL] ? . suggestions ?? [ ] )
275277 }
276278 filespaces [ fileURL] ? . reset ( resetSnapshot: false )
277279 }
@@ -296,8 +298,8 @@ extension Workspace {
296298 let suggestion = allSuggestions. remove ( at: filespace. suggestionIndex)
297299
298300 Task {
299- await copilotSuggestionService ? . notifyAccepted ( suggestion)
300- await copilotSuggestionService ? . notifyRejected ( allSuggestions)
301+ await suggestionService ? . notifyAccepted ( suggestion)
302+ await suggestionService ? . notifyRejected ( allSuggestions)
301303 }
302304
303305 filespaces [ fileURL] ? . reset ( )
@@ -308,7 +310,7 @@ extension Workspace {
308310 func notifyOpenFile( filespace: Filespace ) {
309311 refreshUpdateTime ( )
310312 Task {
311- try await copilotSuggestionService ? . notifyOpenTextDocument (
313+ try await suggestionService ? . notifyOpenTextDocument (
312314 fileURL: filespace. fileURL,
313315 content: try String ( contentsOf: filespace. fileURL, encoding: . utf8)
314316 )
@@ -319,7 +321,7 @@ extension Workspace {
319321 filespace. refreshUpdateTime ( )
320322 refreshUpdateTime ( )
321323 Task {
322- try await copilotSuggestionService ? . notifyChangeTextDocument (
324+ try await suggestionService ? . notifyChangeTextDocument (
323325 fileURL: filespace. fileURL,
324326 content: content
325327 )
@@ -330,7 +332,7 @@ extension Workspace {
330332 filespace. refreshUpdateTime ( )
331333 refreshUpdateTime ( )
332334 Task {
333- try await copilotSuggestionService ? . notifySaveTextDocument ( fileURL: filespace. fileURL)
335+ try await suggestionService ? . notifySaveTextDocument ( fileURL: filespace. fileURL)
334336 }
335337 }
336338}
@@ -340,7 +342,7 @@ extension Workspace {
340342 for (fileURL, _) in filespaces {
341343 if isFilespaceExpired ( fileURL: fileURL, availableTabs: availableTabs) {
342344 Task {
343- try await copilotSuggestionService ? . notifyCloseTextDocument ( fileURL: fileURL)
345+ try await suggestionService ? . notifyCloseTextDocument ( fileURL: fileURL)
344346 }
345347 filespaces [ fileURL] = nil
346348 }
0 commit comments