Skip to content

Commit 622c210

Browse files
vemvbbatsov
authored andcommitted
Update rewrite-clj
Fixes #334 Fixes #332
1 parent 784e8fd commit 622c210

File tree

9 files changed

+61
-39
lines changed

9 files changed

+61
-39
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ executors:
2323
<<: *defaults
2424
openjdk11:
2525
docker:
26-
- image: circleci/clojure:openjdk-11-lein-2.9.1-node
26+
- image: circleci/clojure:openjdk-11-lein-2.9.3-buster-node
2727
environment:
2828
LEIN_ROOT: "true" # we intended to run lein as root
2929
JVM_OPTS: -Xmx3200m --illegal-access=deny # forbid reflective access (this flag doesn't exist for JDK8 or JDK17+)

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* Upgrade Orchard
1212
* Worth emphasizing: now the following options are available https://github.com/clojure-emacs/orchard/tree/v0.7.0#configuration-options
1313
* They can make the refactor-nrepl experience simpler / more robust.
14+
* Upgrade rewrite-clj
15+
* This fixes some features such as `rename-file-or-dir`.
1416
* Reliability improvement: try using `require` prior to `find-ns`
1517
* This increases the chances that a namespace will be found, which in turns makes refactor-nrepl more complete/accurate.
1618
* Replace Cheshire with `clojure.data.json`

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ test: .inline-deps
1818
cljfmt:
1919
lein with-profile -user,+$(VERSION),+cljfmt cljfmt check
2020

21+
cljfmt-fix:
22+
lein with-profile -user,+$(VERSION),+cljfmt cljfmt fix
23+
2124
eastwood:
2225
lein with-profile -user,+$(VERSION),+eastwood eastwood
2326

project.clj

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
:url "http://github.com/clojure-emacs/refactor-nrepl"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[nrepl "0.8.3"]
6+
:dependencies [[nrepl "0.9.0-beta3"]
77
^:inline-dep [http-kit "2.5.3"]
88
^:inline-dep [org.clojure/data.json "2.3.1"]
99
^:inline-dep [org.clojure/tools.analyzer.jvm "1.1.0"]
1010
^:inline-dep [org.clojure/tools.namespace "1.1.0" :exclusions [org.clojure/tools.reader]]
11-
^:inline-dep [org.clojure/tools.reader "1.3.5"]
12-
^:inline-dep [cider/orchard "0.7.1"]
13-
^:inline-dep [cljfmt "0.7.0"]
11+
^:inline-dep [org.clojure/tools.reader "1.3.6"]
12+
^:inline-dep [cider/orchard "0.7.3"]
13+
^:inline-dep [cljfmt "0.8.0" :exclusions [rewrite-clj rewrite-cljs]]
1414
^:inline-dep [clj-commons/fs "1.6.307"]
15-
^:inline-dep [rewrite-clj "0.6.1"]
15+
^:inline-dep [rewrite-clj "1.0.699-alpha"]
1616
^:inline-dep [version-clj "1.0.0"]]
1717
:exclusions [org.clojure/clojure] ; see versions matrix below
1818

@@ -30,7 +30,7 @@
3030
:unresolved-tree false}
3131
:filespecs [{:type :bytes :path "refactor-nrepl/refactor-nrepl/project.clj" :bytes ~(slurp "project.clj")}]
3232
:profiles {;; Clojure versions matrix
33-
:provided {:dependencies [[cider/cider-nrepl "0.25.9"]
33+
:provided {:dependencies [[cider/cider-nrepl "0.27.2"]
3434
[org.clojure/clojure "1.9.0"]
3535
;; For satisfying `:pedantic?`:
3636
[com.google.code.findbugs/jsr305 "3.0.2"]
@@ -45,7 +45,7 @@
4545
[org.clojure/clojure "1.11.0-master-SNAPSHOT" :classifier "sources"]]}
4646

4747
:test {:dependencies [[print-foo "1.0.2"]]}
48-
:dev {:dependencies [[org.clojure/clojurescript "1.10.520"]
48+
:dev {:dependencies [[org.clojure/clojurescript "1.10.879"]
4949
[org.clojure/core.async "1.3.618" :exclusions [org.clojure/clojure org.clojure/tools.reader]]
5050
[cider/piggieback "0.5.2"]
5151
[commons-io/commons-io "2.8.0"]]
@@ -56,7 +56,7 @@
5656
"testproject/src"]
5757
:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]}
5858
:cljfmt [:test
59-
{:plugins [[lein-cljfmt "0.7.0" :exclusions [org.clojure/clojure
59+
{:plugins [[lein-cljfmt "0.8.0" :exclusions [org.clojure/clojure
6060
org.clojure/clojurescript]]]
6161
:cljfmt {:indents {as-> [[:inner 0]]
6262
as->* [[:inner 0]]
@@ -73,7 +73,7 @@
7373
:add-linters [:performance :boxed-math]
7474
:config-files ["eastwood.clj"]}}
7575
:clj-kondo [:test
76-
{:dependencies [[clj-kondo "2021.09.15"]]}]}
76+
{:dependencies [[clj-kondo "2021.10.19"]]}]}
7777

7878
:jvm-opts ~(cond-> []
7979
(System/getenv "CI")

src/refactor_nrepl/ns/resolve_missing.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
;; This happends when class `candidate` depends on a class that is
3434
;; not available on the classpath.
35-
(catch NoClassDefFoundError _e
35+
(catch NoClassDefFoundError e
36+
(refactor-nrepl.util/maybe-log-exception e)
3637
{:name candidate :type :class})))
3738
candidates))
3839

src/refactor_nrepl/s_expressions.clj

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
(ns refactor-nrepl.s-expressions
2-
(:require [rewrite-clj.parser :as zip-parser]
3-
[rewrite-clj.reader :as zip-reader]
4-
[rewrite-clj.zip :as zip]))
2+
(:require
3+
[rewrite-clj.parser :as zip-parser]
4+
[rewrite-clj.reader :as zip-reader]
5+
[rewrite-clj.zip :as zip])
6+
(:import
7+
(clojure.tools.reader.reader_types IndexingPushbackReader)))
58

69
(defn all-zlocs
710
"Generate a seq of all zlocs in a depth-first manner"
@@ -16,7 +19,8 @@
1619

1720
(defn get-first-sexp
1821
^String [file-content]
19-
(let [reader (zip-reader/string-reader file-content)]
22+
(let [^IndexingPushbackReader
23+
reader (zip-reader/string-reader file-content)]
2024
(loop [sexp (zip-parser/parse reader)]
2125
(let [zloc (zip/edn sexp)]
2226
(if (and zloc (not (comment-or-string-or-uneval-or-nil? zloc)))

test/refactor_nrepl/ns/class_search_test.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#{"com/github/luben/zstd/ZstdInputStream"
88
"org/brotli/dec/BrotliInputStream"
99
"org/apache/tools/ant/Task"
10+
"org/apache/tools/ant/launch/AntMain"
1011
"com/sun/jdi/request/EventRequest"})
1112

1213
(def non-initializable-classes
@@ -18,7 +19,7 @@
1819
false
1920
(-> (Thread/currentThread) .getContextClassLoader))
2021
(catch NoClassDefFoundError e
21-
;; there are only 4 in ~7922 classes that cause NoClassDefFoundError,
22+
;; there are only ~5 in ~7922 classes that cause NoClassDefFoundError,
2223
;; see `#'acceptable-error-messages`.
2324
;; They don't have to do with classpath parsing so there's nothing to be fixed.
2425
(is (contains? acceptable-error-messages (.getMessage e))

test/refactor_nrepl/ns/resolve_missing_test.clj

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
(ns refactor-nrepl.ns.resolve-missing-test
2-
(:require [cider.piggieback :as piggieback]
3-
[clojure
4-
[edn :as edn]
5-
[test :as t]]
6-
[nrepl.core :as nrepl]
7-
[nrepl.server :as server]
8-
[refactor-nrepl.middleware :as middleware]))
2+
(:require
3+
[clojure.java.shell :as shell]
4+
[cider.piggieback :as piggieback]
5+
[clojure.edn :as edn]
6+
[clojure.test :as t :refer [testing]]
7+
[nrepl.core :as nrepl]
8+
[nrepl.server :as server]
9+
[refactor-nrepl.middleware :as middleware]))
910

1011
(def ^:dynamic *handler* (server/default-handler #'middleware/wrap-refactor))
1112
(def ^:dynamic *session* nil)
@@ -47,41 +48,53 @@
4748
(t/use-fixtures :each piggieback-fixture)
4849

4950
(t/deftest sanity
51+
(let [{:keys [exit]
52+
:as v} (shell/sh "node" "--version")]
53+
(assert (-> exit long zero?)
54+
(pr-str v)))
55+
5056
(t/testing "cljs repl is active"
5157
(let [response (message {:op :eval
5258
:code (nrepl/code js/console)})]
53-
(t/is (= "cljs.user" (:ns response)))
54-
(t/is (= #{"done"} (:status response)))))
59+
(testing (pr-str response)
60+
(t/is (= "cljs.user" (:ns response)))
61+
(t/is (= #{"done"} (:status response))))))
5562

5663
(t/testing "eval works"
5764
(let [response (message {:op :eval
5865
:code (nrepl/code (map even? (range 6)))})]
59-
(t/is (= "cljs.user" (:ns response)))
60-
(t/is (= ["(true false true false true false)"] (:value response)))
61-
(t/is (= #{"done"} (:status response)))))
66+
(testing (pr-str response)
67+
(t/is (= "cljs.user" (:ns response)))
68+
(t/is (= ["(true false true false true false)"] (:value response)))
69+
(t/is (= #{"done"} (:status response))))))
6270

6371
(t/testing "errors handled properly"
6472
(let [response (message {:op :eval
6573
:code (nrepl/code (ffirst 1))})]
66-
(t/is (= "class clojure.lang.ExceptionInfo"
67-
(:ex response)
68-
(:root-ex response)))
69-
(t/is (string? (:err response)))
70-
(t/is (= #{"eval-error" "done"} (:status response))))))
74+
(testing (pr-str response)
75+
(t/is (= "class clojure.lang.ExceptionInfo"
76+
(:ex response)
77+
(:root-ex response)))
78+
(t/is (string? (:err response)))
79+
(t/is (= #{"eval-error" "done"} (:status response)))))))
7180

7281
(t/deftest resolve-missing-test
7382
(t/testing "Finds functions is regular namespaces"
7483
(let [{:keys [^String error] :as response} (message {:op :resolve-missing :symbol 'print-doc})
84+
_ (assert (string? (:candidates response))
85+
(pr-str response))
7586
{:keys [name type]} (first (edn/read-string (:candidates response)))]
7687
(when error
7788
(println error)
7889
(throw (RuntimeException. error)))
79-
(t/is (= 'cljs.repl name))
80-
(t/is (= :ns type)))
90+
(testing (pr-str response)
91+
(t/is (= 'cljs.repl name))
92+
(t/is (= :ns type))))
8193
(t/testing "Finds macros"
8294
(let [{:keys [^String error] :as response} (message {:op :resolve-missing :symbol 'dir})
8395
{:keys [name type]} (first (edn/read-string (:candidates response)))]
8496
(when error
8597
(throw (RuntimeException. error)))
86-
(t/is (= 'cljs.repl name))
87-
(t/is (= :macro type))))))
98+
(testing (pr-str response)
99+
(t/is (= 'cljs.repl name))
100+
(t/is (= :macro type)))))))

test/refactor_nrepl/rename_file_or_dir_test.clj

-2
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@
147147
(is (some #(.endsWith ^String % "non_clj_file") @files))
148148
(is (= 4 (count (filter #(.endsWith ^String % ".cljs") @files)))))))
149149

150-
151150
;;; cljs
152151

153-
154152
(def from-file-path-cljs (.getAbsolutePath (File. "testproject/src/com/move/ns_to_be_moved_cljs.cljs")))
155153
(def to-file-path-cljs (.getAbsolutePath (File. "testproject/src/com/move/moved_ns_cljs.cljs")))
156154

0 commit comments

Comments
 (0)