forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewPromptToCodeService.swift
More file actions
48 lines (43 loc) · 1.58 KB
/
PreviewPromptToCodeService.swift
File metadata and controls
48 lines (43 loc) · 1.58 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
import Foundation
import SuggestionBasic
public final class PreviewPromptToCodeService: PromptToCodeServiceType {
public init() {}
public func modifyCode(
code: String,
requirement: String,
source: PromptToCodeSource,
isDetached: Bool,
extraSystemPrompt: String?,
generateDescriptionRequirement: Bool?
) async throws -> AsyncThrowingStream<(code: String, description: String), Error> {
return AsyncThrowingStream { continuation in
Task {
let code = """
struct Cat {
var name: String
}
print("Hello world!")
"""
let description = "I have created a struct `Cat`."
var resultCode = ""
var resultDescription = ""
do {
for character in code {
try await Task.sleep(nanoseconds: 50_000_000)
resultCode.append(character)
continuation.yield((resultCode, resultDescription))
}
for character in description {
try await Task.sleep(nanoseconds: 50_000_000)
resultDescription.append(character)
continuation.yield((resultCode, resultDescription))
}
continuation.finish()
} catch {
continuation.finish(throwing: error)
}
}
}
}
public func stopResponding() {}
}