forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcceptSuggestionCommand.swift
More file actions
33 lines (30 loc) · 962 Bytes
/
AcceptSuggestionCommand.swift
File metadata and controls
33 lines (30 loc) · 962 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
import Client
import SuggestionBasic
import Foundation
import XcodeKit
import XPCShared
class AcceptSuggestionCommand: NSObject, XCSourceEditorCommand, CommandType {
var name: String { "Accept Suggestion" }
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.getSuggestionAcceptedCode(
editorContent: .init(invocation)
) {
invocation.accept(content)
}
completionHandler(nil)
}.value)
} catch is CancellationError {
completionHandler(nil)
} catch {
completionHandler(error)
}
}
}
}