File tree 3 files changed +15
-3
lines changed
3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
+ * [ #294 ] ( https://github.com/clojure-emacs/refactor-nrepl/pull/294 ) : Properly skip uneval nodes when looking for the first/last sexp
6
+
5
7
## 2.5.1 (2021-02-16)
6
8
7
9
### Bugs fixed
Original file line number Diff line number Diff line change 8
8
[zipper]
9
9
(take-while (complement zip/end?) (iterate zip/next zipper)))
10
10
11
- (defn- comment-or-string-or-nil? [zloc]
11
+ (defn- comment-or-string-or-uneval-or- nil? [zloc]
12
12
(or (nil? zloc)
13
+ (= :uneval (zip/tag zloc))
13
14
(not (zip/sexpr zloc)) ; comment node
14
15
(string? (zip/sexpr zloc))))
15
16
18
19
(let [reader (zip-reader/string-reader file-content)]
19
20
(loop [sexp (zip-parser/parse reader)]
20
21
(let [zloc (zip/edn sexp)]
21
- (if (and zloc (not (comment-or-string-or-nil? zloc)))
22
+ (if (and zloc (not (comment-or-string-or-uneval-or- nil? zloc)))
22
23
(zip/string zloc)
23
24
(when (.peek-char reader)
24
25
(recur (zip-parser/parse reader))))))))
25
26
26
27
(defn get-last-sexp
27
28
^String [file-content]
28
29
(let [zloc (->> file-content zip/of-string zip/rightmost)]
29
- (some (fn [zloc] (when-not (comment-or-string-or-nil? zloc)
30
+ (some (fn [zloc] (when-not (comment-or-string-or-uneval-or- nil? zloc)
30
31
(zip/string zloc)))
31
32
(take-while (complement nil?) (iterate zip/left zloc)))))
32
33
Original file line number Diff line number Diff line change 10
10
#{foo bar baz}
11
11
;; some other stuff
12
12
(foobar baz)" )
13
+ (def file-content-with-uneval " #_ foo
14
+ (foobar baz)" )
15
+
13
16
(def binding-location [3 8 ])
14
17
(def set-location [7 35 ])
15
18
(def map-location [7 28 ])
33
36
(apply sut/get-enclosing-sexp file-content when-not-location )))
34
37
(t/is (= nil (sut/get-first-sexp weird-file-content)))
35
38
(t/is (= " #{foo bar baz}" (sut/get-first-sexp file-content-with-set))))
39
+
40
+ (t/deftest get-first-sexp
41
+ (t/is (= " (ns resources.testproject.src.com.example.sexp-test)"
42
+ (sut/get-first-sexp file-content)))
43
+ (t/is (= " (foobar baz)"
44
+ (sut/get-first-sexp file-content-with-uneval))))
You can’t perform that action at this time.
0 commit comments