forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomCommand.swift
More file actions
35 lines (32 loc) · 944 Bytes
/
CustomCommand.swift
File metadata and controls
35 lines (32 loc) · 944 Bytes
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
import Client
import CopilotModel
import Foundation
import XcodeKit
class CustomCommand: NSObject, XCSourceEditorCommand, CommandType {
let name: String
let identifer: String
init(name: String, identifer: String) {
self.name = name
self.identifer = identifer
}
func perform(
with invocation: XCSourceEditorCommandInvocation,
completionHandler: @escaping (Error?) -> Void
) {
Task {
do {
let service = try getService()
if let content = try await service.explainSelection(
editorContent: .init(invocation)
) {
invocation.accept(content)
}
completionHandler(nil)
} catch is CancellationError {
completionHandler(nil)
} catch {
completionHandler(error)
}
}
}
}