File tree Expand file tree Collapse file tree 5 files changed +44
-3
lines changed
test/clj/cider/nrepl/middleware Expand file tree Collapse file tree 5 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 6
6
7
7
* [ #546 ] ( https://github.com/clojure-emacs/cider-nrepl/pull/546 ) : Added support for matcher-combinators to the test middleware.
8
8
* [ #556 ] ( https://github.com/clojure-emacs/cider-nrepl/pull/556 ) : Added configuration option for cljfmt to the format middleware.
9
+ * [ #558 ] ( https://github.com/clojure-emacs/cider-nrepl/pull/558 ) : Added the ` ns-aliases ` op to the ns middleware.
9
10
10
11
### Changes
11
12
Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ Middleware | Op(s) | Description
267
267
` wrap-info ` | ` info/eldoc ` | File/line, arglists, docstrings and other metadata for vars.
268
268
` wrap-inspect ` |` inspect-(start/refresh/pop/push/reset/get-path) ` | Inspect a Clojure expression.
269
269
` wrap-macroexpand ` | ` macroexpand/macroexpand-1/macroexpand-all/macroexpand-step ` | Macroexpand a Clojure form.
270
- ` wrap-ns ` | ` ns-list/ns-vars/ns-path/ns-load-all ` | Namespace browsing & loading.
270
+ ` wrap-ns ` | ` ns-list/ns-vars/ns-path/ns-load-all/ns-aliases ` | Namespace browsing & loading.
271
271
` wrap-spec ` | ` spec-list/spec-form/spec-example ` | Spec browsing.
272
272
` wrap-pprint ` | | Adds pretty-printing support to code evaluation. It also installs a dummy ` pprint-middleware ` op. Thus ` wrap-pprint ` is discoverable through the ` describe ` op.
273
273
` wrap-pprint-fn ` | | Provides a common pretty-printing interface for other middlewares that need to perform customisable pretty-printing.
Original file line number Diff line number Diff line change 333
333
:return {" status" " done" " path" " The path to the file containing ns." }}
334
334
" ns-load-all"
335
335
{:doc " Loads all project namespaces."
336
- :return {" status" " done" " loaded-ns" " The list of ns that were loaded." }}}}))
336
+ :return {" status" " done" " loaded-ns" " The list of ns that were loaded." }}
337
+ " ns-aliases"
338
+ {:doc " Returns a map of [ns-alias] to [ns-name] in a namespace."
339
+ :requires {" ns" " The namespace to use." }
340
+ :return {" status" " done" " ns-aliases" " The map of [ns-alias] to [ns-name] in a namespace." }}}}))
337
341
338
342
(def-wrapper wrap-out cider.nrepl.middleware.out /handle-out
339
343
(cljs/expects-piggieback
Original file line number Diff line number Diff line change 1
1
(ns cider.nrepl.middleware.ns
2
+ (:refer-clojure :exclude [ns-aliases])
2
3
(:require
3
4
[cider.nrepl.middleware.util.cljs :as cljs]
4
5
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
96
97
[msg]
97
98
{:loaded-ns (ns/load-project-namespaces )})
98
99
100
+ (defn- ns-aliases-clj [ns ]
101
+ (->> (symbol ns )
102
+ clojure.core/ns-aliases
103
+ (u/update-vals ns-name)
104
+ u/transform-value))
105
+
106
+ (defn- ns-aliases-cljs [env ns ]
107
+ (->> (cljs-analysis/ns-aliases env ns )
108
+ (remove (fn [[k v]] (= k v)))
109
+ (into {})
110
+ u/transform-value))
111
+
112
+ (defn ns-aliases [{:keys [ns ] :as msg}]
113
+ (if-let [cljs-env (cljs/grab-cljs-env msg)]
114
+ (ns-aliases-cljs cljs-env ns )
115
+ (ns-aliases-clj ns )))
116
+
117
+ (defn- ns-aliases-reply [msg]
118
+ {:ns-aliases (ns-aliases msg)})
119
+
99
120
(defn handle-ns [handler msg]
100
121
(with-safe-transport handler msg
101
122
" ns-list" ns-list-reply
102
123
" ns-list-vars-by-name" ns-list-vars-by-name-reply
103
124
" ns-vars" ns-vars-reply
104
125
" ns-vars-with-meta" ns-vars-with-meta-reply
105
126
" ns-path" ns-path-reply
106
- " ns-load-all" ns-load-all-reply))
127
+ " ns-load-all" ns-load-all-reply
128
+ " ns-aliases" ns-aliases-reply))
Original file line number Diff line number Diff line change 81
81
(is (= (count (ns-list-vars-by-name 'ns-list-vars-by-name-test)) 1 ))
82
82
(is (not (seq (ns-list-vars-by-name 'all-your-base-are-belong-to-us)))))
83
83
84
+ (deftest ns-aliases-integration-test
85
+ (let [aliases (:ns-aliases (session/message {:op " ns-aliases"
86
+ :ns " cider.nrepl.middleware.ns-test" }))]
87
+ (is (map? aliases))
88
+ (is (= (:cider-ns aliases) " cider.nrepl.middleware.ns" ))))
89
+
84
90
(deftest error-handling-test
85
91
(testing " ns-list op error handling"
86
92
(with-redefs [cider-ns/ns-list (fn [& _] (throw (Exception. " ns-list error" )))]
115
121
(is (.startsWith (:err response) " java.lang.Exception: ns-path error" ))
116
122
(is (= (:ex response) " class java.lang.Exception" ))
117
123
(is (= (:status response) #{" ns-path-error" " done" }))
124
+ (is (:pp-stacktrace response)))))
125
+
126
+ (testing " ns-aliases op error handling"
127
+ (with-redefs [cider-ns/ns-aliases (fn [& _] (throw (Exception. " ns-aliases error" )))]
128
+ (let [response (session/message {:op " ns-aliases" :name " testing-function" })]
129
+ (is (.startsWith (:err response) " java.lang.Exception: ns-aliases error" ))
130
+ (is (= (:ex response) " class java.lang.Exception" ))
131
+ (is (= (:status response) #{" ns-aliases-error" " done" }))
118
132
(is (:pp-stacktrace response))))))
You can’t perform that action at this time.
0 commit comments