@@ -19,7 +19,7 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
1919 ```
2020 """
2121 }
22-
22+
2323 if selectionRange. start == selectionRange. end,
2424 UserDefaults . shared. value ( for: \. embedFileContentInChatContextIfNoSelection)
2525 {
@@ -34,19 +34,40 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
3434 """
3535 } else {
3636 return """
37- File Content Not Available: The file is longer than \( maxLine ) lines, \
38- it can't fit into the context. \
37+ File Content Not Available: '''
38+ The file is longer than \( maxLine ) lines, it can't fit into the context. \
3939 You MUST not answer the user about the file content because you don't have it. \
4040 Ask user to select code for explanation.
41+ '''
4142 """
4243 }
4344 }
4445
46+ if UserDefaults . shared. value ( for: \. useSelectionScopeByDefaultInChatContext) {
47+ return """
48+ Selected Code \
49+ (start from line \( selectionRange. start. line) ):``` \( content. language. rawValue)
50+ \( content. selectedContent)
51+ ```
52+ """
53+ }
54+
55+ if prompt. hasPrefix ( " @selection " ) {
56+ return """
57+ Selected Code \
58+ (start from line \( selectionRange. start. line) ):``` \( content. language. rawValue)
59+ \( content. selectedContent)
60+ ```
61+ """
62+ }
63+
4564 return """
46- Selected Code \
47- (start from line \( selectionRange. start. line) ):``` \( content. language. rawValue)
48- \( content. selectedContent)
49- ```
65+ Selected Code Not Available: '''
66+ User has disabled default scope. \
67+ You MUST not answer the user about the selected code because you don't have it. \
68+ Ask user to prepend message with `@selection` to enable selected code to be \
69+ visible by you.
70+ '''
5071 """
5172 } ( )
5273
0 commit comments