forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeiumWorkspacePlugin.swift
More file actions
60 lines (52 loc) · 1.62 KB
/
CodeiumWorkspacePlugin.swift
File metadata and controls
60 lines (52 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Foundation
import Logger
import Workspace
public final class CodeiumWorkspacePlugin: WorkspacePlugin {
private var _codeiumService: CodeiumService?
@CodeiumActor
var codeiumService: CodeiumService? {
if let service = _codeiumService { return service }
do {
return try createCodeiumService()
} catch {
Logger.codeium.error("Failed to create Codeium service: \(error)")
return nil
}
}
deinit {
if let _codeiumService {
_codeiumService.terminate()
}
}
@CodeiumActor
func createCodeiumService() throws -> CodeiumService {
let newService = try CodeiumService(
projectRootURL: projectRootURL,
onServiceLaunched: {
},
onServiceTerminated: {
// start handled in the service.
}
)
_codeiumService = newService
return newService
}
@CodeiumActor
func finishLaunchingService() {
guard let workspace, let _codeiumService else { return }
Task {
try? await _codeiumService.notifyOpenWorkspace(workspaceURL: workspaceURL)
for (_, filespace) in workspace.filespaces {
let documentURL = filespace.fileURL
guard let content = try? String(contentsOf: documentURL) else { continue }
try? await _codeiumService.notifyOpenTextDocument(
fileURL: documentURL,
content: content
)
}
}
}
func terminate() {
_codeiumService = nil
}
}