Skip to content

Commit 04f95f1

Browse files
committed
Eliminate middleware vector code duplication
1 parent 9d79b5f commit 04f95f1

File tree

7 files changed

+49
-96
lines changed

7 files changed

+49
-96
lines changed

src/cider/nrepl.clj

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
defers the loading of the actual middleware."
99
(:require
1010
[cider.nrepl.version :as version]
11+
[cider.nrepl.middleware :as mw]
1112
[cider.nrepl.middleware.util.cljs :as cljs]
1213
[cider.nrepl.print-method] ;; we load this namespace, so it's directly available to clients
1314
[nrepl.middleware :refer [set-descriptor!]]
@@ -524,34 +525,8 @@
524525
;; end users might opt to build custom handlers that don't
525526
;; include every middleware available.
526527

527-
(def cider-middleware
528-
"A vector of all CIDER middleware."
529-
`[wrap-apropos
530-
wrap-classpath
531-
wrap-clojuredocs
532-
wrap-complete
533-
wrap-content-type
534-
wrap-debug
535-
wrap-enlighten
536-
wrap-format
537-
wrap-info
538-
wrap-inspect
539-
wrap-macroexpand
540-
wrap-ns
541-
wrap-out
542-
wrap-slurp
543-
wrap-profile
544-
wrap-refresh
545-
wrap-resource
546-
wrap-spec
547-
wrap-stacktrace
548-
wrap-test
549-
wrap-trace
550-
wrap-tracker
551-
wrap-undef
552-
wrap-version
553-
wrap-xref])
528+
(def cider-middleware mw/cider-middleware) ;; for backwards compatibility
554529

555530
(def cider-nrepl-handler
556531
"CIDER's nREPL handler."
557-
(apply nrepl-server/default-handler (map resolve-or-fail cider-middleware)))
532+
(apply nrepl-server/default-handler (map resolve-or-fail mw/cider-middleware)))

src/cider/nrepl/middleware.clj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(ns cider.nrepl.middleware
2+
"This namespace mostly exists, so that
3+
it's easy to share the list of middlewares.
4+
Eventually the deferred loading will probably come here as well."
5+
{:added "0.25"})
6+
7+
(def cider-middleware
8+
'[cider.nrepl/wrap-apropos
9+
cider.nrepl/wrap-classpath
10+
cider.nrepl/wrap-clojuredocs
11+
cider.nrepl/wrap-complete
12+
cider.nrepl/wrap-content-type
13+
cider.nrepl/wrap-debug
14+
cider.nrepl/wrap-enlighten
15+
cider.nrepl/wrap-format
16+
cider.nrepl/wrap-info
17+
cider.nrepl/wrap-inspect
18+
cider.nrepl/wrap-macroexpand
19+
cider.nrepl/wrap-ns
20+
cider.nrepl/wrap-out
21+
cider.nrepl/wrap-slurp
22+
cider.nrepl/wrap-profile
23+
cider.nrepl/wrap-refresh
24+
cider.nrepl/wrap-resource
25+
cider.nrepl/wrap-spec
26+
cider.nrepl/wrap-stacktrace
27+
cider.nrepl/wrap-test
28+
cider.nrepl/wrap-trace
29+
cider.nrepl/wrap-tracker
30+
cider.nrepl/wrap-undef
31+
cider.nrepl/wrap-version
32+
cider.nrepl/wrap-xref])

src/cider_nrepl/plugin.clj

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"Provides a simple way to setup the CIDER nREPL middleware in
33
Leiningen projects."
44
(:require
5+
[cider.nrepl.middleware :as mw]
56
[cider.nrepl.version :refer [version-string]]
67
[clojure.java.io :as io]
78
[leiningen.core.main :as lein]))
@@ -59,34 +60,4 @@
5960
[['cider/cider-nrepl version-string]])
6061
(update-in [:repl-options :nrepl-middleware]
6162
(fnil into [])
62-
;; TODO: it would be better to avoid this duplication, but
63-
;; we can't require the `cider.nrepl` namespace because it
64-
;; requires `nrepl.*` namespaces which might conflict with
65-
;; Leiningen. Consider adding another namespace that
66-
;; contains the below definition (as data only, not
67-
;; requiring `cider.nrepl`).
68-
'[cider.nrepl/wrap-apropos
69-
cider.nrepl/wrap-classpath
70-
cider.nrepl/wrap-clojuredocs
71-
cider.nrepl/wrap-complete
72-
cider.nrepl/wrap-content-type
73-
cider.nrepl/wrap-debug
74-
cider.nrepl/wrap-enlighten
75-
cider.nrepl/wrap-format
76-
cider.nrepl/wrap-info
77-
cider.nrepl/wrap-inspect
78-
cider.nrepl/wrap-macroexpand
79-
cider.nrepl/wrap-ns
80-
cider.nrepl/wrap-out
81-
cider.nrepl/wrap-slurp
82-
cider.nrepl/wrap-profile
83-
cider.nrepl/wrap-refresh
84-
cider.nrepl/wrap-resource
85-
cider.nrepl/wrap-spec
86-
cider.nrepl/wrap-stacktrace
87-
cider.nrepl/wrap-test
88-
cider.nrepl/wrap-trace
89-
cider.nrepl/wrap-tracker
90-
cider.nrepl/wrap-undef
91-
cider.nrepl/wrap-version
92-
cider.nrepl/wrap-xref])))))
63+
mw/cider-middleware)))))

test/clj/cider/nrepl/middleware/format_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
:edn "{:b 2 :c 3 :a 1}"
151151
::print/print "fake.nrepl.pprint/puget-pprint"})
152152
(dissoc :id :session))]
153-
(is (= {:formatted-edn "{:b 2, :c 3, :a 1}",
154-
:status #{"done" "nrepl.middleware.print/error"},
153+
(is (= {:formatted-edn "{:b 2, :c 3, :a 1}"
154+
:status #{"done" "nrepl.middleware.print/error"}
155155
:nrepl.middleware.print/error "Couldn't resolve var fake.nrepl.pprint/puget-pprint"}
156156
response)))))

test/clj/cider/nrepl/plugin_test.clj

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
11
(ns cider.nrepl.plugin-test
2-
(:require [cider-nrepl.plugin :refer :all]
3-
[cider.nrepl.version :refer [version-string]]
4-
[clojure.test :refer :all]))
2+
(:require
3+
[cider-nrepl.plugin :refer :all]
4+
[cider.nrepl.middleware :as mw]
5+
[cider.nrepl.version :refer [version-string]]
6+
[clojure.test :refer :all]))
57

68
(def expected-output
7-
{:dependencies
8-
[['org.clojure/clojure]
9-
['cider/cider-nrepl version-string]],
10-
:repl-options
11-
{:nrepl-middleware
12-
'[cider.nrepl/wrap-apropos
13-
cider.nrepl/wrap-classpath
14-
cider.nrepl/wrap-clojuredocs
15-
cider.nrepl/wrap-complete
16-
cider.nrepl/wrap-content-type
17-
cider.nrepl/wrap-debug
18-
cider.nrepl/wrap-enlighten
19-
cider.nrepl/wrap-format
20-
cider.nrepl/wrap-info
21-
cider.nrepl/wrap-inspect
22-
cider.nrepl/wrap-macroexpand
23-
cider.nrepl/wrap-ns
24-
cider.nrepl/wrap-out
25-
cider.nrepl/wrap-slurp
26-
cider.nrepl/wrap-profile
27-
cider.nrepl/wrap-refresh
28-
cider.nrepl/wrap-resource
29-
cider.nrepl/wrap-spec
30-
cider.nrepl/wrap-stacktrace
31-
cider.nrepl/wrap-test
32-
cider.nrepl/wrap-trace
33-
cider.nrepl/wrap-tracker
34-
cider.nrepl/wrap-undef
35-
cider.nrepl/wrap-version
36-
cider.nrepl/wrap-xref]}})
9+
{:dependencies [['org.clojure/clojure]
10+
['cider/cider-nrepl version-string]]
11+
:repl-options {:nrepl-middleware mw/cider-middleware}})
3712

3813
(deftest version-checks
3914
(testing "undefined versions work"

test/cljs/cider/nrepl/piggieback_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:require
33
[cider.piggieback :as piggieback]
44
[cider.nrepl.test-session :as session]
5-
[cider.nrepl :refer [cider-middleware]]
5+
[cider.nrepl.middleware :refer [cider-middleware]]
66
[cljs.repl.nashorn :as nashorn]
77
[clojure.test :refer :all]
88
[nrepl.core :as nrepl]

test/common/cider_nrepl/plugin_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns cider-nrepl.plugin-test
22
(:require [cider-nrepl.plugin :as plugin]
3-
[cider.nrepl :refer [cider-middleware]]
3+
[cider.nrepl.middleware :refer [cider-middleware]]
44
[clojure.test :refer :all]
55
[leiningen.core.main :as lein]))
66

0 commit comments

Comments
 (0)