Skip to content

Commit a0885cc

Browse files
committed
Adjust ActiveDocumentChatContextCollector
1 parent df3e5de commit a0885cc

File tree

7 files changed

+212
-244
lines changed

7 files changed

+212
-244
lines changed

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/ActiveDocumentChatContextCollector.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
7070

7171
func getActiveDocumentContext(_ info: EditorInformation) -> ActiveDocumentContext {
7272
var activeDocumentContext = activeDocumentContext ?? .init(
73+
filePath: "",
7374
relativePath: "",
7475
language: .builtIn(.swift),
7576
fileContent: "",
@@ -85,16 +86,19 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
8586
}
8687

8788
func extractSystemPrompt(_ context: ActiveDocumentContext) -> String {
88-
let start = "User Editing Document Context:###"
89+
let start = """
90+
User Editing Document Context:###
91+
(The context may change during the conversation, so it may not match our conversation.)
92+
"""
8993
let end = "###"
9094
let relativePath = "Document Relative Path: \(context.relativePath)"
91-
let language = "Language: \(context.language)"
95+
let language = "Language: \(context.language.rawValue)"
9296

9397
if let focusedContext = context.focusedContext {
94-
let codeContext = "\(focusedContext.contextRange) \(focusedContext.context)"
98+
let codeContext = "Focused Context:\(focusedContext.contextRange) \(focusedContext.context)"
9599
let codeRange = "Focused Range [line, character]: \(focusedContext.codeRange)"
96100
let code = """
97-
Focused Code (start from line \(focusedContext.codeRange.start.line)):
101+
Focused Code (start from line \(focusedContext.codeRange.start.line), call `expandFocusRange` if you need more context):
98102
```\(context.language.rawValue)
99103
\(focusedContext.code)
100104
```
@@ -104,6 +108,7 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
104108
: """
105109
File Annotations:
106110
\(focusedContext.otherLineAnnotations.map { " - \($0)" }.joined(separator: "\n"))
111+
(call `moveToCodeAroundLine` if you context about the line annotations here)
107112
"""
108113
let codeAnnotations = focusedContext.lineAnnotations.isEmpty
109114
? ""
@@ -148,6 +153,7 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
148153
}
149154

150155
struct ActiveDocumentContext {
156+
var filePath: String
151157
var relativePath: String
152158
var language: CodeLanguage
153159
var fileContent: String
@@ -243,6 +249,7 @@ struct ActiveDocumentContext {
243249
return false
244250
}()
245251

252+
filePath = info.documentURL.path
246253
relativePath = info.relativePath
247254
language = info.language
248255
fileContent = info.editorContent?.content ?? ""

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/FocusedCodeFinder/FocusedCodeFinder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct UnknownLanguageFocusedCodeFinder: FocusedCodeFinder {
3838
// search up and down for up to 7 lines.
3939
let lines = activeDocumentContext.lines
4040
var startLineIndex = max(containingRange.start.line - 3, 0)
41-
var endLineIndex = min(containingRange.start.line + 3, lines.count - 1)
41+
let endLineIndex = min(containingRange.start.line + 3, lines.count - 1)
4242
if endLineIndex - startLineIndex <= 6, startLineIndex > 0 {
4343
startLineIndex = max(startLineIndex - (6 - (endLineIndex - startLineIndex)), 0)
4444
}

0 commit comments

Comments
 (0)