Skip to content

Commit ea47a07

Browse files
committed
Ignore cancellations
1 parent d99330e commit ea47a07

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Core/Sources/PromptToCodeService/PromptToCodeService.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ public final class PromptToCodeService: ObservableObject {
6161
description = fragment.description
6262
}
6363
}
64+
} catch is CancellationError {
65+
return
6466
} catch {
67+
if (error as NSError).code == NSURLErrorCancelled {
68+
return
69+
}
70+
6571
if let oldCode {
6672
code = oldCode
6773
}
@@ -81,7 +87,7 @@ public final class PromptToCodeService: ObservableObject {
8187
description = oldDescription
8288
}
8389
self.oldCode = nil
84-
self.oldDescription = nil
90+
oldDescription = nil
8591
}
8692

8793
public func generateCompletion() -> CopilotCompletion {
@@ -130,7 +136,7 @@ final class OpenAIPromptToCodeAPI: PromptToCodeAPI {
130136
) async throws -> AsyncThrowingStream<(code: String, description: String), Error> {
131137
let userPreferredLanguage = UserDefaults.shared.value(for: \.chatGPTLanguage)
132138
let textLanguage = userPreferredLanguage.isEmpty ? "" : "in \(userPreferredLanguage)"
133-
139+
134140
let prompt = {
135141
let indentRule = usesTabsForIndentation ? "\(indentSize) tabs" : "\(indentSize) spaces"
136142
if code.isEmpty {
@@ -141,7 +147,9 @@ final class OpenAIPromptToCodeAPI: PromptToCodeAPI {
141147
indentRule
142148
).
143149
144-
Please reply to me start with the code block, followed by a short description in 1-3 sentences about what you did \(textLanguage).
150+
Please reply to me start with the code block, followed by a short description in 1-3 sentences about what you did \(
151+
textLanguage
152+
).
145153
"""
146154
} else {
147155
return """
@@ -151,7 +159,9 @@ final class OpenAIPromptToCodeAPI: PromptToCodeAPI {
151159
indentRule
152160
).
153161
154-
Please reply to me start with the code block followed by a short description about what you did in 1-3 sentences \(textLanguage).
162+
Please reply to me start with the code block followed by a short description about what you did in 1-3 sentences \(
163+
textLanguage
164+
).
155165
156166
```
157167
\(code)

Core/Sources/Service/GUI/PromptToCodeProvider+Service.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extension PromptToCodeProvider {
3535
Task { [weak self] in
3636
do {
3737
try await service.modifyCode(prompt: requirement)
38+
} catch is CancellationError {
39+
return
3840
} catch {
3941
Task { @MainActor [weak self] in
4042
self?.errorMessage = error.localizedDescription

0 commit comments

Comments
 (0)