Skip to content

Commit

Permalink
[Fix #108] Degrade gracefully on cljc projects
Browse files Browse the repository at this point in the history
Instead of blowing up, because the finding of macro definitions doesn't
work, we now return partial results in find-symbol like we did prior to
adding macro support.
  • Loading branch information
expez committed Aug 11, 2015
1 parent 25edcdc commit 781db84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/refactor_nrepl/find/find_macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@
"Finds all occurrences of the macro, including the definition, in
the project."
[fully-qualified-name]
(when (fully-qualified-name? fully-qualified-name)
(when (and
;; Fail gracefully instead of blowing up with reader errors
;; when project contains cljc files until we had proper
;; support
(empty? (util/find-cljc-files-in-project))
(fully-qualified-name? fully-qualified-name))
(let [all-defs (find-macro-definitions-in-project)
macro-def (first (filter #(= (:name %) fully-qualified-name) all-defs))
tracker (tracker/build-tracker)
Expand Down
14 changes: 13 additions & 1 deletion src/refactor_nrepl/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[find :refer [find-clojure-sources-in-dir]]
[parse :refer [read-ns-decl]]]
[me.raynes.fs :as fs])
(:import java.io.PushbackReader
(:import [java.io File PushbackReader]
java.util.regex.Pattern))

(defn alias-info [full-ast]
Expand Down Expand Up @@ -42,6 +42,18 @@
[]
(mapcat find-clojure-sources-in-dir (dirs-on-classpath*)))

(defn find-in-dir
"Searches recursively under dir for files matching (pred ^File file). "
[pred ^File dir]
(filter pred (file-seq dir)))

(defn cljc-file?
[^File f]
(.endsWith (.getPath f) ".cljc"))

(defn find-cljc-files-in-project []
(mapcat (partial find-in-dir cljc-file?) (dirs-on-classpath*)))

(defn node-at-loc? [loc-line loc-column node]
(let [{:keys [line end-line column end-column]} (:env node)]
;; The node for ::an-ns-alias/foo, when it appeared as a toplevel form,
Expand Down

0 comments on commit 781db84

Please sign in to comment.