Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Jul 1, 2021
1 parent dd03c24 commit 8457b03
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/refactor_nrepl/analyzer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
(defn- build-ast
[ns aliases]
(when (and (ns-on-cp? ns)
(not (util/invalid-fqn? ns)))
(not (util/self-referential? ns)))
;; Use `locking`, because AST analysis can perform arbitrary evaluation.
;; Parallel analysis is not safe, especially as it can perform `require` calls.
(locking core/require-lock
Expand All @@ -94,8 +94,7 @@
(when-let [new-ast-or-err (try
(build-ast ns aliases)
(catch Throwable th
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
(-> th .printStackTrace))
(util/maybe-log-exception th)
th))]
(update-ast-cache file-content ns new-ast-or-err))))))

Expand Down
4 changes: 2 additions & 2 deletions src/refactor_nrepl/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[orchard.java.classpath :as cp]
[orchard.misc :as misc]
[me.raynes.fs :as fs]
[refactor-nrepl.util :refer [normalize-to-unix-path]]
[refactor-nrepl.util :as util :refer [normalize-to-unix-path]]
[refactor-nrepl.s-expressions :as sexp]
[refactor-nrepl.config :as config])
(:import [java.io File FileReader PushbackReader StringReader]))
Expand Down Expand Up @@ -325,7 +325,7 @@
(require n))
(find-ns n)
(catch Throwable e
(-> e .printStackTrace)
(util/maybe-log-exception e)
(when-not ignore-error?
(throw e)))))

Expand Down
3 changes: 1 addition & 2 deletions src/refactor_nrepl/find/find_macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
(mapcat #(try
(get-macro-definitions-in-file-with-caching %)
(catch Exception e
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
(-> e .printStackTrace))
(util/maybe-log-exception e)
(when-not ignore-errors?
(throw e)))))))

Expand Down
21 changes: 12 additions & 9 deletions src/refactor_nrepl/find/find_symbol.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [clojure
[set :as set]
[string :as str]]
[refactor-nrepl.util :refer [invalid-fqn?]]
[refactor-nrepl.util :as util :refer [self-referential?]]
[clojure.tools.analyzer.ast :refer [nodes postwalk]]
[clojure.tools.namespace.parse :as parse]
[refactor-nrepl
Expand Down Expand Up @@ -109,8 +109,7 @@
(find-symbol-in-ast fully-qualified-name)
(filter :line-beg))
(catch Exception e
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
(-> e .printStackTrace))
(util/maybe-log-exception e)
(when-not ignore-errors
(throw e))))
locs (into
Expand Down Expand Up @@ -140,12 +139,16 @@
(->> (core/dirs-on-classpath)
(mapcat (partial core/find-in-dir (every-pred (some-fn core/clj-file? core/cljc-file?)
(fn [f]
(let [n (some-> f
core/read-ns-form
parse/name-from-ns-decl)]
(if-not n
false
(not (invalid-fqn? n))))))))
(try
(let [n (some-> f
core/read-ns-form
parse/name-from-ns-decl)]
(if-not n
false
(not (self-referential? n))))
(catch Exception e
(util/maybe-log-exception e)
false))))))
(mapcat (partial find-symbol-in-file fully-qualified-name ignore-errors referred-syms)))))

(defn- get&read-enclosing-sexps
Expand Down
2 changes: 1 addition & 1 deletion src/refactor_nrepl/find/symbols_in_file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
cljs? (= dialect :cljs)
file-ns (or (when-let [s (-> parsed-ns :ns symbol)]
(when-not cljs?
(core/safe-find-ns s true)))
(core/safe-find-ns s :ignore-errors)))
*ns*)
ns-aliases (if cljs?
(ns-parser/aliases
Expand Down
4 changes: 2 additions & 2 deletions src/refactor_nrepl/ns/resolve_missing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[orchard.cljs.analysis :as cljs-ana]
[clojure.string :as str]
[refactor-nrepl.core :refer [prefix suffix]]
[refactor-nrepl.util :refer [invalid-fqn?]]
[refactor-nrepl.util :refer [self-referential?]]
[refactor-nrepl.ns.slam.hound.regrow :as slamhound]))

(defn- candidates [sym]
Expand Down Expand Up @@ -71,6 +71,6 @@
(some->> sym
symbol
candidates
(remove invalid-fqn?)
(remove self-referential?)
collate-type-info
pr-str)))
4 changes: 2 additions & 2 deletions src/refactor_nrepl/ns/slam/hound/search.clj
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@
(defn reset
"Reset the cache of classes"
[]
(alter-var-root #'available-classes (constantly (delay (get-available-classes))))
(alter-var-root #'available-classes-by-last-segment (constantly (delay (get-available-classes-by-last-segment)))))
(alter-var-root #'available-classes (constantly (get-available-classes)))
(alter-var-root #'available-classes-by-last-segment (constantly (get-available-classes-by-last-segment))))
10 changes: 8 additions & 2 deletions src/refactor_nrepl/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
(and (-> candidate str (.startsWith "refactor-nrepl"))
(not (-> candidate str (.contains "test")))))

(def invalid-fqn?
(defn self-referential?
"Does the argument represent namespace name (or a fully qualified name) that should not be analyzed?"
(some-fn inlined-dependency? refactor-nrepl?))
[candidate]
((some-fn inlined-dependency? refactor-nrepl?)
candidate))

(defn maybe-log-exception [^Throwable e]
(when (System/getProperty "refactor-nrepl.internal.log-exceptions")
(.printStackTrace e)))

0 comments on commit 8457b03

Please sign in to comment.