File tree Expand file tree Collapse file tree 4 files changed +3
-53
lines changed
test/clojure_mcp/tools/form_edit Expand file tree Collapse file tree 4 files changed +3
-53
lines changed Original file line number Diff line number Diff line change 239239 {:zloc updated-zloc
240240 :similar-matches (:similar-matches find-result)})))))
241241
242- ; ; Offset calculation functions for highlighting modified code
243-
244- (defn row-col->offset
245- " Convert row and column coordinates to a character offset in a string.
246-
247- Arguments:
248- - s: The source string
249- - target-row: The target row (1-based)
250- - target-col: The target column (1-based)
251-
252- Returns the character offset in the string."
253- [s target-row target-col]
254- (loop [lines (str/split-lines s)
255- current-row 1
256- offset 0 ]
257- (if (or (empty? lines) (>= current-row target-row))
258- (+ offset target-col) ; Add col for 1-based index
259- (recur (next lines)
260- (inc current-row)
261- (+ offset (count (first lines)) 1 )))))
262-
263- (defn zloc-offsets
264- " Calculate character offsets for a zipper location's start and end positions.
265-
266- Arguments:
267- - source-str: The source code string
268- - positions: A vector of [row col] pairs
269-
270- Returns a vector of character offsets."
271- [source-str positions]
272- (mapv (fn [[row col]] (row-col->offset source-str row col))
273- positions))
274-
275242; ; Source code formatting
276243
277244(def default-formatting-options
604571(defn find-and-edit-multi-sexp [zloc match-form new-form opts]
605572 (or (find-and-edit-multi-sexp* zloc match-form new-form opts)
606573 (binding [*match-clean* true ]
607- (find-and-edit-multi-sexp* zloc match-form new-form opts))))
574+ (find-and-edit-multi-sexp* zloc match-form new-form opts))))
Original file line number Diff line number Diff line change 447447 (cond-> {:operation operation}
448448 replace-all (assoc :all? true )))]
449449 (-> ctx
450- (assoc ::zloc (:zloc result))
451- (assoc ::edit-locations (:locations result)))
450+ (assoc ::zloc (:zloc result)))
452451 {::error true
453452 ::message (str " Could not find form: " match-form)})
454453 (catch Exception e
498497 ctx
499498 (-> ctx
500499 save-file
501- update-file-timestamp))))))
500+ update-file-timestamp))))))
Original file line number Diff line number Diff line change 44 without any MCP-specific code."
55 (:require
66 [clojure-mcp.sexp.match :as match]
7- [clojure-mcp.tools.form-edit.core :as form-edit]
87 [rewrite-clj.zip :as z]
98 [rewrite-clj.parser :as p]))
109
11- ; ; Re-export common utilities from form-edit.core
12- (def format-source-string form-edit /format-source-string )
13- (def load-file-content form-edit /load-file-content )
14- (def save-file-content form-edit /save-file-content )
15- (def zloc-offsets form-edit /zloc-offsets )
16-
1710(defn find-pattern-match
1811 " Finds a pattern match in Clojure source code.
1912
Original file line number Diff line number Diff line change 420420 (is (= :list (z/tag defn-zloc )))
421421 (is (str/includes? (z/string defn-zloc ) " defn test" )))))
422422
423- (deftest row-col-offset-test
424- (testing " row-col->offset correctly calculates character offsets"
425- (let [source " Line 1\n Line 2\n Line 3" ]
426- (is (= 0 (sut/row-col->offset source 1 0 )))
427- (is (= 3 (sut/row-col->offset source 1 3 )))
428- (is (= 7 (sut/row-col->offset source 2 0 )))
429- (is (= 10 (sut/row-col->offset source 2 3 )))
430- (is (= 14 (sut/row-col->offset source 3 0 ))))))
431-
432423(deftest format-source-string-test
433424 (testing " format-source-string correctly formats source code"
434425 (let [unformatted " (defn example-fn[x y] (+ x y) )"
You can’t perform that action at this time.
0 commit comments