Skip to content

Commit

Permalink
[Fix #196] Rewritten dependencies polluting ns-list
Browse files Browse the repository at this point in the history
Our own inlined deps, created by mranderson, as well as the inlined deps
from eastwood were polluting the result of the `ns-list` op.  These are
now filtered out.

This change improves all cider commands relying on a completing read of
some namespace e.g. `cider-browse-ns` and `cider-find-ns`
  • Loading branch information
expez committed Jun 11, 2015
1 parent e57a10e commit 51eeebd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/cider/nrepl/middleware/ns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
[transport :as transport]])
(:import java.util.jar.JarFile))

(defn inlined-dependency?
[^String ns]
(or
;; rewritten by mranderson
(.startsWith ns "deps.")
;; rewritten by dolly
(.startsWith ns "eastwood.copieddeps")))

(defn ns-list-clj []
(->> (all-ns)
(map ns-name)
(map name)
(remove inlined-dependency?)
(sort)))

(defn ns-vars-clj [ns]
Expand Down
15 changes: 11 additions & 4 deletions test/clj/cider/nrepl/middleware/ns_test.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
(ns cider.nrepl.middleware.ns-test
(:require [cider.nrepl.middleware.ns :refer [ns-list-clj ns-vars-clj]]
(:require [cider.nrepl.middleware.ns
:refer [ns-list-clj ns-vars-clj inlined-dependency?]]
[cider.nrepl.test-session :as session]
[cider.nrepl.test-transport :refer [messages test-transport]]
[clojure.test :refer :all]))

(deftest test-toogle-ns-list
(is (= (count (all-ns)) (count (ns-list-clj)))))
(deftest test-toggle-ns-list
(is (= (count (all-ns))
(count
(remove inlined-dependency? (ns-list-clj))))))

(deftest test-toogle-ns-vars
(let [ns "clojure.core"]
Expand All @@ -18,7 +21,11 @@
(deftest ns-list-integration-test
(let [ns-list (:ns-list (session/message {:op "ns-list"}))]
(is (sequential? ns-list))
(is (every? string? ns-list))))
(is (every? string? ns-list))
(testing "Removal of namespaces created by source rewriting"
(is (every? #(not (or (.startsWith % "deps.")
(.startsWith % "eastwood.copieddeps")))
ns-list)))))

(deftest ns-vars-integration-test
(let [ns-vars (:ns-vars (session/message {:op "ns-vars"
Expand Down

0 comments on commit 51eeebd

Please sign in to comment.