@@ -11,6 +11,37 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
1111 let relativePath = content. documentURL. path
1212 . replacingOccurrences ( of: content. projectURL. path, with: " " )
1313 let selectionRange = content. editorContent? . selections. first ?? . outOfScope
14+ let editorContent = {
15+ if selectionRange. start == selectionRange. end,
16+ UserDefaults . shared. value ( for: \. embedFileContentInChatContextIfNoSelection)
17+ {
18+ let lines = content. editorContent? . lines. count ?? 0
19+ let maxLine = UserDefaults . shared
20+ . value ( for: \. maxEmbeddableFileInChatContextLineCount)
21+ if lines <= maxLine {
22+ return """
23+ File Content:``` \( content. language. rawValue)
24+ \( content. editorContent? . content ?? " " )
25+ ```
26+ """
27+ } else {
28+ return """
29+ File Content Not Available: The file is longer than \( maxLine) lines, \
30+ it can't fit into the context. \
31+ You MUST not answer the user about the file content because you don't have it. \
32+ Ask user to select code for explanation.
33+ """
34+ }
35+ }
36+
37+ return """
38+ Selected Code \
39+ (start from line \( selectionRange. start. line) ):``` \( content. language. rawValue)
40+ \( content. selectedContent)
41+ ```
42+ """
43+ } ( )
44+
1445 return """
1546 Active Document Context:###
1647 Document Relative Path: \( relativePath)
@@ -23,9 +54,7 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
2354 Cursor Position: \
2455 Line \( selectionRange. end. line) \
2556 Character \( selectionRange. end. character)
26- Selected Code (start from line \( selectionRange. start. line) ):``` \( content. language. rawValue)
27- \( content. selectedContent)
28- ```
57+ \( editorContent)
2958 Line Annotations:
3059 \(
3160 content. editorContent? . lineAnnotations
0 commit comments