Skip to content

Commit 40ee1de

Browse files
committed
Fix #'in-refresh-dirs?'
3.0.0-alpha4
1 parent 7d0bfa0 commit 40ee1de

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject refactor-nrepl "3.0.0-alpha1"
1+
(defproject refactor-nrepl "3.0.0-alpha4"
22
:description "nREPL middleware to support editor-agnostic refactoring"
33
:url "http://github.com/clojure-emacs/refactor-nrepl"
44
:license {:name "Eclipse Public License"

src/refactor_nrepl/ns/tracker.clj

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,38 @@
6060
(deps-set ns))]
6161
file)))
6262

63-
(defn- in-refresh-dirs? [refresh-dirs file]
63+
(defn- absolutize-refresh-dirs [refresh-dirs]
64+
(->> refresh-dirs
65+
(map (fn [^String s]
66+
(File. s)))
67+
(filter (fn [^File f]
68+
(.exists f)))
69+
(map (fn [^File f]
70+
(let [v (.getCanonicalPath f)]
71+
(cond-> v
72+
(not (str/ends-with? v File/separator))
73+
;; add a trailing slash for a more robust comparison with `file-as-absolute-paths`:
74+
(str File/separator)))))))
75+
76+
(defn in-refresh-dirs?
77+
"Is `filename` located within any of `refresh-dirs`?"
78+
[refresh-dirs refresh-dirs-as-absolute-paths filename]
6479
(if-not (seq refresh-dirs)
6580
;; the end user has not set the `refresh-dirs`, so this defn's logic should be bypassed:
6681
true
67-
(let [file-as-absolute-paths (-> file io/file .getCanonicalPath)
68-
refresh-dirs-as-absolute-paths (->> refresh-dirs
69-
(map (fn [^String s]
70-
(File. s)))
71-
(filter (fn [^File f]
72-
(.exists f)))
73-
(map (fn [^File f]
74-
(let [v (.getCanonicalPath f)]
75-
(cond-> v
76-
(not (str/ends-with? v File/separator))
77-
;; add a trailing slash for a more robust comparison with `file-as-absolute-paths`:
78-
(str File/separator))))))]
79-
(boolean (some #(str/starts-with? % file-as-absolute-paths)
80-
refresh-dirs-as-absolute-paths)))))
82+
(let [file (-> filename io/file)
83+
file-as-absolute-path (-> file .getCanonicalPath)]
84+
(and (-> file .exists)
85+
(-> file .isFile)
86+
(boolean (some (partial str/starts-with? file-as-absolute-path)
87+
refresh-dirs-as-absolute-paths))))))
8188

8289
(defn project-files-in-topo-order
8390
([]
8491
(project-files-in-topo-order false))
8592
([ignore-errors?]
8693
(let [tracker (build-tracker (util/with-suppressed-errors
87-
(every-pred (partial in-refresh-dirs? (user-refresh-dirs))
94+
(every-pred (partial in-refresh-dirs? refresh-dirs (absolutize-refresh-dirs user-refresh-dirs))
8895
core/clj-file?)
8996
ignore-errors?))
9097
nses (dep/topo-sort (:clojure.tools.namespace.track/deps tracker))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(ns refactor-nrepl.ns.tracker-test
2+
(:require
3+
[refactor-nrepl.ns.tracker :as sut]
4+
[clojure.test :refer [are deftest]]))
5+
6+
(deftest in-refresh-dirs?
7+
(are [refresh-dirs file-ns expected] (= expected
8+
(sut/in-refresh-dirs? refresh-dirs
9+
(#'sut/absolutize-refresh-dirs refresh-dirs)
10+
file-ns))
11+
;; if the refresh dirs are unset, we return `true` no matter what:
12+
[] "src/refactor_nrepl/ns/tracker.clj" true
13+
14+
["src"] "src/refactor_nrepl/ns/tracker.clj" true
15+
["src"] "test/refactor_nrepl/ns/tracker_test.clj" false
16+
["test"] "test/refactor_nrepl/ns/tracker_test.clj" true
17+
["src"] "project.clj" false
18+
["src"] "/" false
19+
["ffff"] "src/refactor_nrepl/ns/tracker.clj" false
20+
["src"] "src/refactor_nrepl/ns/trackeeeeeer.clj" false))

0 commit comments

Comments
 (0)