File tree Expand file tree Collapse file tree 3 files changed +34
-9
lines changed
Expand file tree Collapse file tree 3 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
33## Unreleased
4+
45- Improved ` eca_edit_file ` to automatically handle whitespace and indentation differences in single-occurrence edits.
6+ - Fix contexts in user prompts (not system contexts) not parsing lines ranges properly.
57
68## 0.73.5
79
Original file line number Diff line number Diff line change 8888 {:type :file
8989 :path path
9090 :content (llm-api/refine-file-context path lines-range)}
91- :partial lines-range))))
91+ :partial ( some? lines-range) ))))
9292
9393(defn raw-contexts->refined [contexts db]
9494 (mapcat (fn [{:keys [type path lines-range position uri]}]
117117 contexts))
118118
119119(defn contexts-str-from-prompt
120- " Extract all contexts (@something) and refine them."
120+ " Extract all contexts (@something) and refine them.
121+ Parse lines if present in contexts like @/path/to/file:L1-L4"
121122 [prompt db]
122- (let [context-pattern #"[@]([^\s ]+)"
123+ (let [; ; Capture @<path> with optional :L<start>-L<end>
124+ context-pattern #"@([^\s :]+)(?::L(\d +)-L(\d +))?"
123125 matches (re-seq context-pattern prompt)]
124126 (when (seq matches)
125- (let [raw-contexts (mapv (fn [[full-match path]]
126- (let [ type ( if ( string/starts-with? full-match " @ " )
127- " file "
128- " file " )]
129- { :type type
130- :path path} ))
127+ (let [raw-contexts (mapv (fn [[_ path s e ]]
128+ (assoc-some { : type " file "
129+ :path path}
130+ :lines-range ( when ( and s e)
131+ { :start ( Integer/parseInt s)
132+ :end ( Integer/parseInt e)}) ))
131133 matches)]
132134 (raw-contexts->refined raw-contexts db)))))
133135
Original file line number Diff line number Diff line change 321321 :path b-file
322322 :content b-content}])
323323 (#'f.context/parse-agents-file a-file)))))))
324+
325+ (deftest contexts-str-from-prompt-test
326+ (testing " not context mention"
327+ (is (match?
328+ nil
329+ (f.context/contexts-str-from-prompt " check /path/to/file" (h/db )))))
330+ (testing " Context mention"
331+ (with-redefs [llm-api/refine-file-context (constantly " Some content" )]
332+ (is (match?
333+ [{:type :file
334+ :path (h/file-path " /path/to/file" )
335+ :content " Some content" }]
336+ (f.context/contexts-str-from-prompt " check @/path/to/file" (h/db ))))))
337+ (testing " Context mention with lines range"
338+ (with-redefs [llm-api/refine-file-context (constantly " Some content" )]
339+ (is (match?
340+ [{:type :file
341+ :path (h/file-path " /path/to/file" )
342+ :partial true
343+ :content " Some content" }]
344+ (f.context/contexts-str-from-prompt " check @/path/to/file:L1-L4" (h/db )))))))
You can’t perform that action at this time.
0 commit comments