Skip to content

Commit 24824fd

Browse files
committed
Adjust functions
1 parent 9052362 commit 24824fd

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/Functions/ExpandFocusRangeFunction.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ struct ExpandFocusRangeFunction: ChatGPTFunction {
77
struct Arguments: Codable {}
88

99
struct Result: ChatGPTFunctionResult {
10-
var text: String
10+
var range: CursorRange
1111

1212
var botReadableContent: String {
13-
"User Editing Document Context is updated"
13+
"User Editing Document Context is updated to display code at \(range)."
1414
}
1515
}
16+
17+
struct E: Error, LocalizedError {
18+
var errorDescription: String?
19+
}
1620

1721
var reportProgress: (String) async -> Void = { _ in }
1822

@@ -43,12 +47,12 @@ struct ExpandFocusRangeFunction: ChatGPTFunction {
4347
await reportProgress("Finding the focused code..")
4448
contextCollector?.activeDocumentContext?.expandFocusedRangeToContextRange()
4549
guard let newContext = contextCollector?.activeDocumentContext?.focusedContext else {
46-
let progress = "Failed to move to focused code."
50+
let progress = "Failed to expand focused code."
4751
await reportProgress(progress)
48-
return .init(text: progress)
52+
throw E(errorDescription: progress)
4953
}
50-
let progress = "Looking at \(newContext.codeRange) inside \(newContext.context)"
54+
let progress = "Looking at \(newContext.codeRange)."
5155
await reportProgress(progress)
52-
return .init(text: progress)
56+
return .init(range: newContext.codeRange)
5357
}
5458
}

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/Functions/MoveToCodeAroundLineFunction.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ struct MoveToCodeAroundLineFunction: ChatGPTFunction {
99
}
1010

1111
struct Result: ChatGPTFunctionResult {
12-
var text: String
12+
var range: CursorRange
1313

1414
var botReadableContent: String {
15-
"User Editing Document Context is updated"
15+
"User Editing Document Context is updated to display code at \(range)."
1616
}
1717
}
18+
19+
struct E: Error, LocalizedError {
20+
var errorDescription: String?
21+
}
1822

1923
var reportProgress: (String) async -> Void = { _ in }
2024

@@ -53,11 +57,11 @@ struct MoveToCodeAroundLineFunction: ChatGPTFunction {
5357
guard let newContext = contextCollector?.activeDocumentContext?.focusedContext else {
5458
let progress = "Failed to move to focused code."
5559
await reportProgress(progress)
56-
return .init(text: progress)
60+
throw E(errorDescription: progress)
5761
}
5862
let progress = "Looking at \(newContext.codeRange)"
5963
await reportProgress(progress)
60-
return .init(text: progress)
64+
return .init(range: newContext.codeRange)
6165
}
6266
}
6367

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/Functions/MoveToFocusedCodeFunction.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ struct MoveToFocusedCodeFunction: ChatGPTFunction {
77
struct Arguments: Codable {}
88

99
struct Result: ChatGPTFunctionResult {
10-
var text: String
10+
var range: CursorRange
1111

1212
var botReadableContent: String {
13-
"User Editing Document Context is updated"
13+
"User Editing Document Context is updated to display code at \(range)."
1414
}
1515
}
16+
17+
struct E: Error, LocalizedError {
18+
var errorDescription: String?
19+
}
1620

1721
var reportProgress: (String) async -> Void = { _ in }
1822

@@ -45,10 +49,10 @@ struct MoveToFocusedCodeFunction: ChatGPTFunction {
4549
guard let newContext = contextCollector?.activeDocumentContext?.focusedContext else {
4650
let progress = "Failed to move to focused code."
4751
await reportProgress(progress)
48-
return .init(text: progress)
52+
throw E(errorDescription: progress)
4953
}
50-
let progress = "Looking at \(newContext.codeRange) inside \(newContext.context)"
54+
let progress = "Looking at \(newContext.codeRange)."
5155
await reportProgress(progress)
52-
return .init(text: progress)
56+
return .init(range: newContext.codeRange)
5357
}
5458
}

0 commit comments

Comments
 (0)