Skip to content

Commit e013600

Browse files
author
Case Nelson
committed
getting clean ns to maintain cursor pos
1 parent a0435a0 commit e013600

File tree

6 files changed

+31
-36
lines changed

6 files changed

+31
-36
lines changed

Diff for: .agignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/rplugin

Diff for: rplugin/node/clj-refactor.js

+21-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/clj_refactor/edit.cljs

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
last))
2525

2626
(defn to-root [loc]
27-
(exec-to loc z/up #(not (top? %))))
27+
(if (top? loc)
28+
loc
29+
(exec-to loc z/up #(not (top? %)))))
2830

2931
(defn parent-let? [zloc]
3032
(= 'let (-> zloc z/up z/leftmost z/sexpr)))
@@ -129,7 +131,6 @@
129131
(defn read-position
130132
[old-pos zloc]
131133
(-> zloc
132-
(zdbg "read-position")
133134
(remove-all-after)
134135
(z/root-string)
135136
(z/of-string)
@@ -145,6 +146,6 @@
145146

146147
(defn find-mark
147148
[zloc marker]
148-
(if-let [mloc (z/find (to-root zloc) z/next #(= marker (get (z/node %) ::marker)))]
149+
(if-let [mloc (z/find (to-root zloc) z/next (fn [loc] (= marker (get (z/node loc) ::marker))))]
149150
mloc
150151
zloc))

Diff for: src/clj_refactor/main.cljs

+3-4
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@
5151
(z/of-string)
5252
(z/find-last-by-pos pos #(not= (z/tag %) :whitespace))
5353
(edit/mark-position :new-cursor)
54+
;; TODO should check if anything has changed
55+
;; - should return nil if transformer returned nil
5456
(transformer args)
5557
(edit/find-mark :new-cursor)
5658
(swap-position! new-cursor)
57-
(edit/zdbg (pr-str @new-cursor))
58-
;; TODO should check if anything has changed
59-
;; - should return nil if transformer returned nil
6059
(z/root-string)
6160
(parinfer/parenMode)
6261
(aget "text"))]
@@ -109,7 +108,7 @@
109108
;; REPL only commands
110109
(.command js/plugin "CAddMissingLibSpec" #js {:eval "expand('<cword>')" :nargs 0}
111110
(partial repl/add-missing-libspec run-transform))
112-
(.command js/plugin "CCleanNS" #js {:eval "expand('%:p')" :nargs 0}
111+
(.command js/plugin "CCleanNS" #js {:eval "[getpos('.'), expand('%:p')]" :nargs 0}
113112
(partial repl/clean-ns run-transform))
114113
(.command js/plugin "CRenameFile" #js {:eval "expand('%:p')" :nargs 1 :complete "file"}
115114
repl/rename-file)

Diff for: src/clj_refactor/repl.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
(defn clean-ns
6565
"Asks repl for the missing libspec.
6666
When the repl comes back with response, run transform to add to ns"
67-
[run-transform nvim _ path]
67+
[run-transform nvim _ [cursor path]]
6868
(fireplace-message
6969
nvim
7070
{:op "clean-ns" :path path :prefix-rewriting "false"}
@@ -73,7 +73,7 @@
7373
(let [ns-str (aget (first results) "ns")]
7474
(when (string? ns-str)
7575
(run-transform
76-
transform/replace-ns nvim [(parser/parse-string ns-str)] fake-cursor))))))
76+
transform/replace-ns nvim [(parser/parse-string ns-str)] cursor))))))
7777

7878
(defn rename-file
7979
[nvim [new-file] current-file]

Diff for: src/clj_refactor/transform.cljs

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
[rewrite-clj.zip.utils :as zu]
1717
[rewrite-clj.zip.whitespace :as ws]))
1818

19-
(defn zdbg
20-
[zloc]
21-
(println (z/sexpr zloc))
22-
zloc)
23-
2419
(defn introduce-let
2520
"Adds a let around the current form."
2621
[zloc [binding-name]]

0 commit comments

Comments
 (0)