@@ -7,13 +7,15 @@ import XcodeInspector
77@Reducer
88public struct PromptToCodeGroup {
99 @ObservableState
10- public struct State : Equatable {
10+ public struct State {
1111 public var promptToCodes : IdentifiedArrayOf < PromptToCodePanel . State > = [ ]
1212 public var activeDocumentURL : PromptToCodePanel . State . ID ? = XcodeInspector . shared
1313 . realtimeActiveDocumentURL
1414 public var activePromptToCode : PromptToCodePanel . State ? {
1515 get {
16- if let detached = promptToCodes. first ( where: { !$0. isAttachedToSelectionRange } ) {
16+ if let detached = promptToCodes
17+ . first ( where: { !$0. promptToCodeState. isAttachedToTarget } )
18+ {
1719 return detached
1820 }
1921 guard let id = activeDocumentURL else { return nil }
@@ -27,60 +29,15 @@ public struct PromptToCodeGroup {
2729 }
2830 }
2931
30- public struct PromptToCodeInitialState : Equatable {
31- public var code : String
32- public var selectionRange : CursorRange ?
33- public var language : CodeLanguage
34- public var identSize : Int
35- public var usesTabsForIndentation : Bool
36- public var documentURL : URL
37- public var projectRootURL : URL
38- public var allCode : String
39- public var allLines : [ String ]
40- public var isContinuous : Bool
41- public var commandName : String ?
42- public var defaultPrompt : String
43- public var extraSystemPrompt : String ?
44- public var generateDescriptionRequirement : Bool ?
45-
46- public init (
47- code: String ,
48- selectionRange: CursorRange ? ,
49- language: CodeLanguage ,
50- identSize: Int ,
51- usesTabsForIndentation: Bool ,
52- documentURL: URL ,
53- projectRootURL: URL ,
54- allCode: String ,
55- allLines: [ String ] ,
56- isContinuous: Bool ,
57- commandName: String ? ,
58- defaultPrompt: String ,
59- extraSystemPrompt: String ? ,
60- generateDescriptionRequirement: Bool ?
61- ) {
62- self . code = code
63- self . selectionRange = selectionRange
64- self . language = language
65- self . identSize = identSize
66- self . usesTabsForIndentation = usesTabsForIndentation
67- self . documentURL = documentURL
68- self . projectRootURL = projectRootURL
69- self . allCode = allCode
70- self . allLines = allLines
71- self . isContinuous = isContinuous
72- self . commandName = commandName
73- self . defaultPrompt = defaultPrompt
74- self . extraSystemPrompt = extraSystemPrompt
75- self . generateDescriptionRequirement = generateDescriptionRequirement
76- }
77- }
78-
79- public enum Action : Equatable {
32+ public enum Action {
8033 /// Activate the prompt to code if it exists or create it if it doesn't
81- case activateOrCreatePromptToCode( PromptToCodeInitialState )
82- case createPromptToCode( PromptToCodeInitialState )
83- case updatePromptToCodeRange( id: PromptToCodePanel . State . ID , range: CursorRange )
34+ case activateOrCreatePromptToCode( PromptToCodePanel . State )
35+ case createPromptToCode( PromptToCodePanel . State )
36+ case updatePromptToCodeRange(
37+ id: PromptToCodePanel . State . ID ,
38+ snippetId: UUID ,
39+ range: CursorRange
40+ )
8441 case discardAcceptedPromptToCodeIfNotContinuous( id: PromptToCodePanel . State . ID )
8542 case updateActivePromptToCode( documentURL: URL )
8643 case discardExpiredPromptToCode( documentURLs: [ URL ] )
@@ -103,37 +60,22 @@ public struct PromptToCodeGroup {
10360 return . run { send in
10461 await send ( . createPromptToCode( s) )
10562 }
106- case let . createPromptToCode( s) :
107- let newPromptToCode = PromptToCodePanel . State (
108- code: s. code,
109- prompt: s. defaultPrompt,
110- language: s. language,
111- indentSize: s. identSize,
112- usesTabsForIndentation: s. usesTabsForIndentation,
113- projectRootURL: s. projectRootURL,
114- documentURL: s. documentURL,
115- allCode: s. allCode,
116- allLines: s. allLines,
117- commandName: s. commandName,
118- isContinuous: s. isContinuous,
119- selectionRange: s. selectionRange,
120- extraSystemPrompt: s. extraSystemPrompt,
121- generateDescriptionRequirement: s. generateDescriptionRequirement
122- )
63+ case let . createPromptToCode( newPromptToCode) :
12364 // insert at 0 so it has high priority then the other detached prompt to codes
12465 state. promptToCodes. insert ( newPromptToCode, at: 0 )
12566 return . run { send in
126- if !newPromptToCode. prompt . isEmpty {
67+ if !newPromptToCode. promptToCodeState . instruction . isEmpty {
12768 await send ( . promptToCode( newPromptToCode. id, . modifyCodeButtonTapped) )
12869 }
12970 } . cancellable (
13071 id: PromptToCodePanel . CancellationKey. modifyCode ( newPromptToCode. id) ,
13172 cancelInFlight: true
13273 )
13374
134- case let . updatePromptToCodeRange( id, range) :
135- if let p = state. promptToCodes [ id: id] , p. isAttachedToSelectionRange {
136- state. promptToCodes [ id: id] ? . selectionRange = range
75+ case let . updatePromptToCodeRange( id, snippetId, range) :
76+ if let p = state. promptToCodes [ id: id] , p. promptToCodeState. isAttachedToTarget {
77+ state. promptToCodes [ id: id] ? . promptToCodeState. snippets [ id: snippetId] ?
78+ . attachedRange = range
13779 }
13880 return . none
13981
@@ -153,7 +95,7 @@ public struct PromptToCodeGroup {
15395
15496 case . promptToCode:
15597 return . none
156-
98+
15799 case . activePromptToCode:
158100 return . none
159101 }
@@ -166,7 +108,7 @@ public struct PromptToCodeGroup {
166108 PromptToCodePanel ( )
167109 . dependency ( \. promptToCodeService, promptToCodeServiceFactory ( ) )
168110 } )
169-
111+
170112 Reduce { state, action in
171113 switch action {
172114 case let . promptToCode( id, . cancelButtonTapped) :
0 commit comments