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