Skip to content

Commit c05e692

Browse files
authored
Always perform a require prior to analyzing a ns (#321)
Part of #245
1 parent 67518a5 commit c05e692

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Reliability improvement: try using `require` prior to `find-ns`
1212
* This increases the chances that a namespace will be found, which in turns makes refactor-nrepl more complete/accurate.
1313
* Replace Cheshire with `clojure.data.json`
14-
* Build ASTs more robustly (by using locks and ruling out certain namespaces like refactor-nrepl itself)
14+
* Build ASTs more robustly (by using locks, `require`, and ruling out certain namespaces like refactor-nrepl itself)
1515
* Honor internal `future-cancel` calls, improving overall responsiveness and stability.
1616

1717
### Bugs fixed

project.clj

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
:test {:dependencies [[print-foo "1.0.2"]]}
4949
:dev {:global-vars {*warn-on-reflection* true}
5050
:dependencies [[org.clojure/clojurescript "1.10.520"]
51+
[org.clojure/core.async "1.3.618" :exclusions [org.clojure/clojure org.clojure/tools.reader]]
5152
[cider/piggieback "0.5.2"]
5253
[commons-io/commons-io "2.8.0"]]
5354
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}

src/refactor_nrepl/analyzer.clj

+7-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@
7777
(not (util/self-referential? ns)))
7878
;; Use `locking`, because AST analysis can perform arbitrary evaluation.
7979
;; Parallel analysis is not safe, especially as it can perform `require` calls.
80-
(locking core/require-lock
80+
(locking core/require-lock ;; for both `require` and `aj/analyze-ns`
81+
82+
;; Performing this `require` makes it more likely that t.ana will succeed.
83+
;; I believe it's because `require` will also require other namespaces recursively.
84+
;; t.ana does so in theory as well, but it's slightly more rigid,
85+
;; and/or does not always do the same exact thing the Clojure compiler would.
86+
(require ns)
8187
(let [opts {:passes-opts
8288
{:validate/unresolvable-symbol-handler shadow-unresolvable-symbol-handler
8389
:validate/throw-on-arity-mismatch false

test-resources/core_async_usage.clj

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(ns core-async-usage
2+
"Analyzing this ns used to be problematic, see git.io/Jcd7W"
3+
(:require
4+
[clojure.core.async :refer [go-loop]]))

test/refactor_nrepl/analyzer_test.clj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(ns refactor-nrepl.analyzer-test
2+
(:require
3+
[clojure.java.io :as io]
4+
[refactor-nrepl.analyzer :as sut]
5+
[clojure.test :refer [deftest is]]))
6+
7+
(deftest ns-ast-test
8+
(doseq [f ["core_async_usage.clj"]
9+
:let [c (-> f io/resource slurp)]]
10+
(is (some? (sut/ns-ast c)))))

0 commit comments

Comments
 (0)