@@ -7,13 +7,17 @@ import XcodeInspector
77public struct ActiveDocumentChatContextCollector : ChatContextCollector {
88 public init ( ) { }
99
10- public func generateSystemPrompt( history: [ ChatMessage ] , content prompt: String ) -> String {
10+ public func generateContext(
11+ history: [ ChatMessage ] ,
12+ scopes: Set < String > ,
13+ content: String
14+ ) -> ChatContext ? {
1115 let content = getEditorInformation ( )
1216 let relativePath = content. documentURL. path
1317 . replacingOccurrences ( of: content. projectURL. path, with: " " )
1418 let selectionRange = content. editorContent? . selections. first ?? . outOfScope
1519 let editorContent = {
16- if prompt . hasPrefix ( " @ file" ) {
20+ if scopes . contains ( " file " ) {
1721 return """
1822 File Content:``` \( content. language. rawValue)
1923 \( content. editorContent? . content ?? " " )
@@ -53,7 +57,7 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
5357 """
5458 }
5559
56- if prompt . hasPrefix ( " @ selection" ) {
60+ if scopes . contains ( " selection " ) {
5761 return """
5862 Selected Code \
5963 (start from line \( selectionRange. start. line) ):``` \( content. language. rawValue)
@@ -72,27 +76,30 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
7276 """
7377 } ( )
7478
75- return """
76- Active Document Context:###
77- Document Relative Path: \( relativePath)
78- Selection Range Start: \
79- Line \( selectionRange. start. line) \
80- Character \( selectionRange. start. character)
81- Selection Range End: \
82- Line \( selectionRange. end. line) \
83- Character \( selectionRange. end. character)
84- Cursor Position: \
85- Line \( selectionRange. end. line) \
86- Character \( selectionRange. end. character)
87- \( editorContent)
88- Line Annotations:
89- \(
90- content. editorContent? . lineAnnotations
91- . map { " - \( $0) " }
92- . joined ( separator: " \n " ) ?? " N/A "
79+ return . init(
80+ systemPrompt: """
81+ Active Document Context:###
82+ Document Relative Path: \( relativePath)
83+ Selection Range Start: \
84+ Line \( selectionRange. start. line) \
85+ Character \( selectionRange. start. character)
86+ Selection Range End: \
87+ Line \( selectionRange. end. line) \
88+ Character \( selectionRange. end. character)
89+ Cursor Position: \
90+ Line \( selectionRange. end. line) \
91+ Character \( selectionRange. end. character)
92+ \( editorContent)
93+ Line Annotations:
94+ \(
95+ content. editorContent? . lineAnnotations
96+ . map { " - \( $0) " }
97+ . joined ( separator: " \n " ) ?? " N/A "
98+ )
99+ ###
100+ """ ,
101+ functions: [ ]
93102 )
94- ###
95- """
96103 }
97104}
98105
0 commit comments