Skip to content

Commit 57eb92e

Browse files
mbuczkoexpez
authored andcommitted
[Fix #275] Honor cljr-ignore-analyzer-errors flag in macros analyzer
1 parent 75f5255 commit 57eb92e

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/refactor_nrepl/find/find_macros.clj

+9-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
(util/with-additional-ex-data [:file (.getAbsolutePath f)]
5252
(with-open [file-rdr (FileReader. f)]
5353
(binding [*ns* (or (core/path->namespace :no-error f) *ns*)
54+
reader/*read-eval* false
5455
reader/*data-readers* *data-readers*]
5556
(let [rdr (LineNumberingPushbackReader. file-rdr)
5657
opts {:read-cond :allow :features #{:clj} :eof :eof}]
@@ -81,9 +82,13 @@
8182

8283
(defn- find-macro-definitions-in-project
8384
"Finds all macros that are defined in the project."
84-
[]
85+
[ignore-errors?]
8586
(->> (core/find-in-project (some-fn core/cljc-file? core/clj-file?))
86-
(mapcat get-macro-definitions-in-file-with-caching)))
87+
(mapcat #(try
88+
(get-macro-definitions-in-file-with-caching %)
89+
(catch Exception e
90+
(when-not ignore-errors?
91+
(throw e)))))))
8792

8893
(defn- get-ns-aliases
8994
"Create a map of ns-aliases to namespaces."
@@ -207,9 +212,9 @@
207212
(defn find-macro
208213
"Finds all occurrences of the macro, including the definition, in
209214
the project."
210-
[fully-qualified-name]
215+
[fully-qualified-name ignore-errors?]
211216
(when (fully-qualified-name? fully-qualified-name)
212-
(let [all-defs (find-macro-definitions-in-project)
217+
(let [all-defs (find-macro-definitions-in-project ignore-errors?)
213218
macro-def (first (filter #(= (:name %) fully-qualified-name) all-defs))
214219
tracker (tracker/build-tracker)
215220
origin-ns (symbol (core/prefix fully-qualified-name))

src/refactor_nrepl/find/find_symbol.clj

+3-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@
234234

235235
(defn find-symbol [{:keys [file ns name line column ignore-errors]}]
236236
(core/throw-unless-clj-file file)
237-
(let [macros (future (find-macro (core/fully-qualify ns name)))
238-
globals (->> (find-global-symbol file ns name (= ignore-errors "true"))
237+
(let [ignore-errors? (= ignore-errors "true")
238+
macros (future (find-macro (core/fully-qualify ns name) ignore-errors?))
239+
globals (->> (find-global-symbol file ns name ignore-errors?)
239240
distinct
240241
(remove find-util/spurious?)
241242
future)]

test/refactor_nrepl/find/find_macros_test.clj

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(first (filter #(re-find regexp (:match %)) occurrences)))
77

88
(deftest find-macro-test
9-
(let [occurrences (find-macro "com.example.macro-def/my-macro")
9+
(let [occurrences (find-macro "com.example.macro-def/my-macro" false)
1010
{:keys [line-beg col-beg file match]}
1111
(first (filter #(.contains (:match %) "defmacro") occurrences))]
1212
(testing "finds the macro definition"
@@ -29,29 +29,29 @@
2929
(is (.endsWith file "macro_def.clj")))))
3030

3131
(deftest find-regular-symbol-test
32-
(is (nil? (find-macro "sym"))))
32+
(is (nil? (find-macro "sym" false))))
3333

3434
(deftest find-fully-qualified-random-name
35-
(is (nil? (find-macro "asdf"))))
35+
(is (nil? (find-macro "asdf" false))))
3636

3737
(deftest find-fully-qualified-fn
38-
(is (nil? (find-macro "refactor-nrepl.find.find-macros/find-macro"))))
38+
(is (nil? (find-macro "refactor-nrepl.find.find-macros/find-macro" false))))
3939

4040
(deftest finds-macro-defined-in-cljc-file
4141
(is (found? #"defmacro cljc-macro"
42-
(find-macro "com.example.macro-def-cljc/cljc-macro"))))
42+
(find-macro "com.example.macro-def-cljc/cljc-macro" false))))
4343

4444
(deftest finds-macro-defined-in-cljc-file-and-used-in-clj-file
4545
(is (found? #"(com.example.macro-def-cljc/cljc-macro :fully-qualified)"
46-
(find-macro "com.example.macro-def-cljc/cljc-macro"))))
46+
(find-macro "com.example.macro-def-cljc/cljc-macro" false))))
4747

4848
(deftest macro-definitions-are-cached
49-
(find-macro "com.example.macro-def/my-macro")
49+
(find-macro "com.example.macro-def/my-macro" false)
5050
(with-redefs [refactor-nrepl.find.find-macros/put-cached-macro-definitions
5151
(fn [& _] (throw (ex-info "Cache miss!" {})))]
52-
(is (found? #"defmacro my-macro" (find-macro "com.example.macro-def/my-macro"))))
52+
(is (found? #"defmacro my-macro" (find-macro "com.example.macro-def/my-macro" false))))
5353
(reset! @#'refactor-nrepl.find.find-macros/macro-defs-cache {})
5454
(with-redefs [refactor-nrepl.find.find-macros/put-cached-macro-definitions
5555
(fn [& _] (throw (Exception. "Expected!")))]
5656
(is (thrown-with-msg? Exception #"Expected!"
57-
(find-macro "com.example.macro-def/my-macro")))))
57+
(find-macro "com.example.macro-def/my-macro" false)))))

0 commit comments

Comments
 (0)