Skip to content

Commit cb77f0e

Browse files
committed
Update presentModification to also take a source
1 parent 0f6a311 commit cb77f0e

File tree

4 files changed

+47
-47
lines changed

4 files changed

+47
-47
lines changed

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,18 @@ struct PseudoCommandHandler: CommandHandler {
271271
}
272272
}
273273

274-
func presentModification(fileURL: URL, snippets: [ModificationSnippet]) async {
274+
func presentModification(
275+
source: ModificationAgentRequest.ModificationSource,
276+
snippets: [ModificationSnippet]
277+
) async {
275278
do {
276279
@Dependency(\.workspacePool) var workspacePool
277280
let (workspace, filespace) = try await workspacePool
278-
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
281+
.fetchOrCreateWorkspaceAndFilespace(fileURL: source.documentURL)
279282
let store = await Service.shared.guiController.store
280-
let content = try String(contentsOf: fileURL)
281-
let lines = content.breakLines(appendLineBreakToLastLine: false)
282283
await store.send(.promptToCodeGroup(.activateOrCreatePromptToCode(.init(
283284
promptToCodeState: Shared(.init(
284-
source: .init(
285-
language: filespace.language,
286-
documentURL: filespace.fileURL,
287-
projectRootURL: workspace.projectRootURL,
288-
content: content,
289-
lines: lines
290-
),
285+
source: source,
291286
snippets: IdentifiedArray(uniqueElements: snippets),
292287
instruction: "",
293288
extraSystemPrompt: "",

Tool/Sources/CommandHandler/CommandHandler.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ public protocol CommandHandler {
2626
// MARK: Modification
2727

2828
func acceptPromptToCode() async
29-
func presentModification(fileURL: URL, snippets: [ModificationSnippet]) async
29+
func presentModification(
30+
source: ModificationAgentRequest.ModificationSource,
31+
snippets: [ModificationSnippet]
32+
) async
3033

3134
// MARK: Custom Command
3235

@@ -104,8 +107,11 @@ public final class UniversalCommandHandler: CommandHandler {
104107
await commandHandler.acceptPromptToCode()
105108
}
106109

107-
public func presentModification(fileURL: URL, snippets: [ModificationSnippet]) async {
108-
await commandHandler.presentModification(fileURL: fileURL, snippets: snippets)
110+
public func presentModification(
111+
source: ModificationAgentRequest.ModificationSource,
112+
snippets: [ModificationSnippet]
113+
) async {
114+
await commandHandler.presentModification(source: source, snippets: snippets)
109115
}
110116

111117
public func handleCustomCommand(_ command: CustomCommand) async {
@@ -162,7 +168,10 @@ struct NOOPCommandHandler: CommandHandler {
162168
print("accept prompt to code")
163169
}
164170

165-
func presentModification(fileURL: URL, snippets: [ModificationSnippet]) {
171+
func presentModification(
172+
source: ModificationAgentRequest.ModificationSource,
173+
snippets: [ModificationSnippet]
174+
) {
166175
print("present modification")
167176
}
168177

Tool/Sources/ModificationBasic/ModificationAgent.swift

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,53 @@ public enum ModificationAgentResponse {
88
}
99

1010
public struct ModificationAgentRequest {
11-
var code: String
12-
var requirement: String
13-
var source: ModificationSource
14-
var isDetached: Bool
15-
var extraSystemPrompt: String?
16-
var generateDescriptionRequirement: Bool?
11+
public var code: String
12+
public var requirement: String
13+
public var source: ModificationSource
14+
public var isDetached: Bool
15+
public var extraSystemPrompt: String?
16+
public var generateDescriptionRequirement: Bool?
17+
public var range: CursorRange
1718

18-
public struct ModificationSource {
19+
public struct ModificationSource: Equatable {
1920
public var language: CodeLanguage
2021
public var documentURL: URL
2122
public var projectRootURL: URL
2223
public var content: String
2324
public var lines: [String]
24-
public var range: CursorRange
2525

2626
public init(
2727
language: CodeLanguage,
2828
documentURL: URL,
2929
projectRootURL: URL,
3030
content: String,
31-
lines: [String],
32-
range: CursorRange
31+
lines: [String]
3332
) {
3433
self.language = language
3534
self.documentURL = documentURL
3635
self.projectRootURL = projectRootURL
3736
self.content = content
3837
self.lines = lines
39-
self.range = range
4038
}
4139
}
40+
41+
public init(
42+
code: String,
43+
requirement: String,
44+
source: ModificationSource,
45+
isDetached: Bool,
46+
extraSystemPrompt: String? = nil,
47+
generateDescriptionRequirement: Bool? = nil,
48+
range: CursorRange
49+
) {
50+
self.code = code
51+
self.requirement = requirement
52+
self.source = source
53+
self.isDetached = isDetached
54+
self.extraSystemPrompt = extraSystemPrompt
55+
self.generateDescriptionRequirement = generateDescriptionRequirement
56+
self.range = range
57+
}
4258
}
4359

4460
public protocol ModificationAgent {

Tool/Sources/PromptToCodeCustomization/PromptToCodeCustomization.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,7 @@ struct NoPromptToCodeCustomizedUI: PromptToCodeCustomizedUI {
6060
}
6161

6262
public struct PromptToCodeState: Equatable {
63-
public struct Source: Equatable {
64-
public var language: CodeLanguage
65-
public var documentURL: URL
66-
public var projectRootURL: URL
67-
public var content: String
68-
public var lines: [String]
69-
70-
public init(
71-
language: CodeLanguage,
72-
documentURL: URL,
73-
projectRootURL: URL,
74-
content: String,
75-
lines: [String]
76-
) {
77-
self.language = language
78-
self.documentURL = documentURL
79-
self.projectRootURL = projectRootURL
80-
self.content = content
81-
self.lines = lines
82-
}
83-
}
63+
public typealias Source = ModificationAgentRequest.ModificationSource
8464

8565
public var source: Source
8666
public var history: [ModificationHistoryNode] = []

0 commit comments

Comments
 (0)