File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Core/Sources/PromptToCodeService Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -135,21 +135,30 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
135135 }
136136 } ( )
137137
138+ let annotations = isDetached
139+ ? [ ]
140+ : extractAnnotations ( editorInformation: editor, source: source)
141+
138142 let firstMessage : String ? = {
139143 if code. isEmpty { return nil }
140- switch language {
141144 switch editor. language {
142145 case . builtIn( . markdown) , . plaintext:
143146 return """
144147 ```
145148 \( code)
146149 ```
150+
151+ line annotations found:
152+ \( annotations. map { " - \( $0) " } . joined ( separator: " \n " ) )
147153 """
148154 default :
149155 return """
150156 ```
151157 \( code)
152158 ```
159+
160+ line annotations found:
161+ \( annotations. map { " - \( $0) " } . joined ( separator: " \n " ) )
153162 """
154163 }
155164 } ( )
@@ -246,5 +255,20 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
246255
247256 return ( code, description)
248257 }
258+ func extractAnnotations(
259+ editorInformation: EditorInformation ,
260+ source: PromptToCodeSource
261+ ) -> [ String ] {
262+ guard let annotations = editorInformation. editorContent? . lineAnnotations else { return [ ] }
263+ return annotations
264+ . lazy
265+ . filter { annotation in
266+ annotation. line >= source. range. start. line + 1
267+ && annotation. line <= source. range. end. line + 1
268+ } . map { annotation in
269+ let relativeLine = annotation. line - source. range. start. line
270+ return " line \( relativeLine) : \( annotation. type) \( annotation. message) "
271+ }
272+ }
249273}
250274
You can’t perform that action at this time.
0 commit comments