From fc5f293336258274769275b94425df5475d44afb Mon Sep 17 00:00:00 2001 From: Benedek Fazekas Date: Sat, 31 Oct 2015 21:28:12 +0000 Subject: [PATCH] Build AST for nses in project in topological order when warming the AST cache - fixes error after global rename symbol when def(n) being renamed is referred - might give remedy for #126 --- src/refactor_nrepl/analyzer.clj | 6 +++--- src/refactor_nrepl/ns/tracker.clj | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/refactor_nrepl/analyzer.clj b/src/refactor_nrepl/analyzer.clj index 1ff4fd0f..70d21c13 100644 --- a/src/refactor_nrepl/analyzer.clj +++ b/src/refactor_nrepl/analyzer.clj @@ -9,8 +9,8 @@ [clojure.tools.namespace.parse :refer [read-ns-decl]] [clojure.walk :as walk] [refactor-nrepl - [config :as config] - [core :as core]] + [config :as config]] + [refactor-nrepl.ns.tracker :as tracker] [clojure.string :as str]) (:import java.io.PushbackReader java.util.regex.Pattern)) @@ -121,7 +121,7 @@ "OK")))))) (defn warm-ast-cache [] - (doseq [f (core/find-in-project core/clj-file?)] + (doseq [f (tracker/project-files-in-topo-order)] (try (ns-ast (slurp f)) (catch Throwable th))) ;noop, ast-status will be reported separately diff --git a/src/refactor_nrepl/ns/tracker.clj b/src/refactor_nrepl/ns/tracker.clj index 5535e2ff..61b2d396 100644 --- a/src/refactor_nrepl/ns/tracker.clj +++ b/src/refactor_nrepl/ns/tracker.clj @@ -18,3 +18,11 @@ (for [[file ns] (:clojure.tools.namespace.file/filemap tracker) :when ((set deps) ns)] file))) + +(defn project-files-in-topo-order [] + (let [tracker (file/add-files (tracker/tracker) (core/find-in-project core/clj-file?)) + nses (dep/topo-sort (:clojure.tools.namespace.track/deps tracker)) + filemap (:clojure.tools.namespace.file/filemap tracker) + ns2file (zipmap (vals filemap) (keys filemap))] + (->> (map ns2file nses) + (remove nil?))))