Skip to content

Commit 8457b03

Browse files
committed
PR feedback
1 parent dd03c24 commit 8457b03

File tree

8 files changed

+30
-23
lines changed

8 files changed

+30
-23
lines changed

src/refactor_nrepl/analyzer.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
(defn- build-ast
7575
[ns aliases]
7676
(when (and (ns-on-cp? ns)
77-
(not (util/invalid-fqn? ns)))
77+
(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.
8080
(locking core/require-lock
@@ -94,8 +94,7 @@
9494
(when-let [new-ast-or-err (try
9595
(build-ast ns aliases)
9696
(catch Throwable th
97-
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
98-
(-> th .printStackTrace))
97+
(util/maybe-log-exception th)
9998
th))]
10099
(update-ast-cache file-content ns new-ast-or-err))))))
101100

src/refactor_nrepl/core.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[orchard.java.classpath :as cp]
77
[orchard.misc :as misc]
88
[me.raynes.fs :as fs]
9-
[refactor-nrepl.util :refer [normalize-to-unix-path]]
9+
[refactor-nrepl.util :as util :refer [normalize-to-unix-path]]
1010
[refactor-nrepl.s-expressions :as sexp]
1111
[refactor-nrepl.config :as config])
1212
(:import [java.io File FileReader PushbackReader StringReader]))
@@ -325,7 +325,7 @@
325325
(require n))
326326
(find-ns n)
327327
(catch Throwable e
328-
(-> e .printStackTrace)
328+
(util/maybe-log-exception e)
329329
(when-not ignore-error?
330330
(throw e)))))
331331

src/refactor_nrepl/find/find_macros.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@
8585
(mapcat #(try
8686
(get-macro-definitions-in-file-with-caching %)
8787
(catch Exception e
88-
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
89-
(-> e .printStackTrace))
88+
(util/maybe-log-exception e)
9089
(when-not ignore-errors?
9190
(throw e)))))))
9291

src/refactor_nrepl/find/find_symbol.clj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:require [clojure
33
[set :as set]
44
[string :as str]]
5-
[refactor-nrepl.util :refer [invalid-fqn?]]
5+
[refactor-nrepl.util :as util :refer [self-referential?]]
66
[clojure.tools.analyzer.ast :refer [nodes postwalk]]
77
[clojure.tools.namespace.parse :as parse]
88
[refactor-nrepl
@@ -109,8 +109,7 @@
109109
(find-symbol-in-ast fully-qualified-name)
110110
(filter :line-beg))
111111
(catch Exception e
112-
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
113-
(-> e .printStackTrace))
112+
(util/maybe-log-exception e)
114113
(when-not ignore-errors
115114
(throw e))))
116115
locs (into
@@ -140,12 +139,16 @@
140139
(->> (core/dirs-on-classpath)
141140
(mapcat (partial core/find-in-dir (every-pred (some-fn core/clj-file? core/cljc-file?)
142141
(fn [f]
143-
(let [n (some-> f
144-
core/read-ns-form
145-
parse/name-from-ns-decl)]
146-
(if-not n
147-
false
148-
(not (invalid-fqn? n))))))))
142+
(try
143+
(let [n (some-> f
144+
core/read-ns-form
145+
parse/name-from-ns-decl)]
146+
(if-not n
147+
false
148+
(not (self-referential? n))))
149+
(catch Exception e
150+
(util/maybe-log-exception e)
151+
false))))))
149152
(mapcat (partial find-symbol-in-file fully-qualified-name ignore-errors referred-syms)))))
150153

151154
(defn- get&read-enclosing-sexps

src/refactor_nrepl/find/symbols_in_file.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
cljs? (= dialect :cljs)
6060
file-ns (or (when-let [s (-> parsed-ns :ns symbol)]
6161
(when-not cljs?
62-
(core/safe-find-ns s true)))
62+
(core/safe-find-ns s :ignore-errors)))
6363
*ns*)
6464
ns-aliases (if cljs?
6565
(ns-parser/aliases

src/refactor_nrepl/ns/resolve_missing.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[orchard.cljs.analysis :as cljs-ana]
66
[clojure.string :as str]
77
[refactor-nrepl.core :refer [prefix suffix]]
8-
[refactor-nrepl.util :refer [invalid-fqn?]]
8+
[refactor-nrepl.util :refer [self-referential?]]
99
[refactor-nrepl.ns.slam.hound.regrow :as slamhound]))
1010

1111
(defn- candidates [sym]
@@ -71,6 +71,6 @@
7171
(some->> sym
7272
symbol
7373
candidates
74-
(remove invalid-fqn?)
74+
(remove self-referential?)
7575
collate-type-info
7676
pr-str)))

src/refactor_nrepl/ns/slam/hound/search.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,5 @@
134134
(defn reset
135135
"Reset the cache of classes"
136136
[]
137-
(alter-var-root #'available-classes (constantly (delay (get-available-classes))))
138-
(alter-var-root #'available-classes-by-last-segment (constantly (delay (get-available-classes-by-last-segment)))))
137+
(alter-var-root #'available-classes (constantly (get-available-classes)))
138+
(alter-var-root #'available-classes-by-last-segment (constantly (get-available-classes-by-last-segment))))

src/refactor_nrepl/util.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
(and (-> candidate str (.startsWith "refactor-nrepl"))
6464
(not (-> candidate str (.contains "test")))))
6565

66-
(def invalid-fqn?
66+
(defn self-referential?
6767
"Does the argument represent namespace name (or a fully qualified name) that should not be analyzed?"
68-
(some-fn inlined-dependency? refactor-nrepl?))
68+
[candidate]
69+
((some-fn inlined-dependency? refactor-nrepl?)
70+
candidate))
71+
72+
(defn maybe-log-exception [^Throwable e]
73+
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
74+
(.printStackTrace e)))

0 commit comments

Comments
 (0)