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
30 lines (28 loc) · 882 Bytes
/
CustomCommand.swift
File metadata and controls
30 lines (28 loc) · 882 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
import Client
import SuggestionModel
import Foundation
import XcodeKit
class CustomCommand: NSObject, XCSourceEditorCommand, CommandType {
var name: String = ""
func perform(
with invocation: XCSourceEditorCommandInvocation,
completionHandler: @escaping (Error?) -> Void
) {
Task {
do {
let service = try getService()
if let content = try await service.customCommand(
id: customCommandMap[invocation.commandIdentifier] ?? "",
editorContent: .init(invocation)
) {
invocation.accept(content)
}
completionHandler(nil)
} catch is CancellationError {
completionHandler(nil)
} catch {
completionHandler(error)
}
}
}
}