forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcceptPromptToCodeCommand.swift
More file actions
31 lines (29 loc) · 952 Bytes
/
AcceptPromptToCodeCommand.swift
File metadata and controls
31 lines (29 loc) · 952 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
import Client
import Foundation
import SuggestionBasic
import XcodeKit
class AcceptPromptToCodeCommand: NSObject, XCSourceEditorCommand, CommandType {
var name: String { "Accept Prompt to Code" }
func perform(
with invocation: XCSourceEditorCommandInvocation,
completionHandler: @escaping (Error?) -> Void
) {
Task {
do {
try await (Task(timeout: 7) {
let service = try getService()
if let content = try await service.getPromptToCodeAcceptedCode(
editorContent: .init(invocation)
) {
invocation.accept(content)
}
completionHandler(nil)
}.value)
} catch is CancellationError {
completionHandler(nil)
} catch {
completionHandler(error)
}
}
}
}