From 781db84036a3760b4986d05334b66772ffa1ac66 Mon Sep 17 00:00:00 2001 From: Lars Andersen Date: Tue, 11 Aug 2015 13:19:04 +0200 Subject: [PATCH] [Fix #108] Degrade gracefully on cljc projects 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. --- src/refactor_nrepl/find/find_macros.clj | 7 ++++++- src/refactor_nrepl/util.clj | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/refactor_nrepl/find/find_macros.clj b/src/refactor_nrepl/find/find_macros.clj index 8fe920c8..128c78a1 100644 --- a/src/refactor_nrepl/find/find_macros.clj +++ b/src/refactor_nrepl/find/find_macros.clj @@ -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) diff --git a/src/refactor_nrepl/util.clj b/src/refactor_nrepl/util.clj index 1f8333f9..47c00c4b 100644 --- a/src/refactor_nrepl/util.clj +++ b/src/refactor_nrepl/util.clj @@ -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] @@ -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,