Skip to content

Commit 65da8bf

Browse files
committed
[Fix #232] Add compatibility with nREPL 0.4
Support with tools.nrepl is kept for now with the assumption that tools.nrepl namespaces would be loaded automatically by `lein repl` or `boot repl`. Support for tools.nrepl will likely be removed after a couple of releases (once mainstream Lein and Boot switch to nREPL 0.4). This also updates the archaic piggieback dep the project was using.
1 parent f75441e commit 65da8bf

File tree

9 files changed

+32
-17
lines changed

9 files changed

+32
-17
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ Add the following in `~/.boot/profile.boot`:
4343

4444
### Passing messages to and from refactor-nrepl
4545

46-
We've already called this a middleware, but we haven't really talked about what that means. refactor-nrepl is middleware for a REPL. Specifically it's middleware for a networked REPL, which is managed by [clojure.tools.nrepl](https://github.com/clojure/tools.nrepl). refactor-nrepl uses the running REPL to to gain insight about your project, in order to offer various refactorings.
46+
We've already called this a middleware, but we haven't really talked
47+
about what that means. refactor-nrepl is middleware for a REPL.
48+
Specifically it's middleware for a networked REPL, which is managed by
49+
[nREPL](https://github.com/nrepl/nrepl).
50+
refactor-nrepl uses the running REPL to to gain insight about your
51+
project, in order to offer various refactorings.
4752

4853
Most likely you're already in an environment with a nREPL client available, so you don't have to worry about anything except sending an receiving messages:
4954

5055
```cljs
51-
=> (require '[clojure.tools.nrepl :as repl])
56+
=> (require '[nrepl.core :as repl])
5257
nil
5358
=> (with-open [conn (repl/connect :port 59258)]
5459
(-> (repl/client conn 1000) ; message receive timeout required

project.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
:url "http://github.com/clojure-emacs/refactor-nrepl"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[org.clojure/tools.nrepl "0.2.13"]
6+
:dependencies [[nrepl "0.4.4"]
77
^:source-dep [http-kit "2.2.0"]
88
^:source-dep [cheshire "5.8.0"]
99
^:source-dep [org.clojure/tools.analyzer.jvm "0.7.1"]
@@ -27,10 +27,10 @@
2727
:dev {:plugins [[jonase/eastwood "0.2.0"]]
2828
:global-vars {*warn-on-reflection* true}
2929
:dependencies [[org.clojure/clojurescript "1.9.89"]
30-
[com.cemerick/piggieback "0.2.2"]
30+
[cider/piggieback "0.3.8"]
3131
[leiningen-core "2.7.1"]
3232
[commons-io/commons-io "2.6"]]
33-
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
33+
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}
3434
:java-source-paths ["test/java"]
3535
:resource-paths ["test/resources"
3636
"test/resources/testproject/src"]

src/refactor_nrepl/middleware.clj

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
(ns refactor-nrepl.middleware
22
(:require [cider.nrepl.middleware.util.cljs :as cljs]
33
[clojure.stacktrace :refer [print-cause-trace]]
4-
[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
5-
[clojure.tools.nrepl.misc :refer [response-for]]
6-
[clojure.tools.nrepl.transport :as transport]
74
[refactor-nrepl.config :as config]
85
[refactor-nrepl.core :as core]
96
[refactor-nrepl.ns.libspecs :refer [namespace-aliases]]
107
[refactor-nrepl.stubs-for-interface :refer [stubs-for-interface]]
118
[clojure.walk :as walk]))
129

10+
;; Compatibility with the legacy tools.nrepl and the new nREPL 0.4.x.
11+
;; The assumption is that if someone is using old lein repl or boot repl
12+
;; they'll end up using the tools.nrepl, otherwise the modern one.
13+
(if (find-ns 'clojure.tools.nrepl)
14+
(require
15+
'[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
16+
'[clojure.tools.nrepl.misc :refer [response-for]]
17+
'[clojure.tools.nrepl.transport :as transport])
18+
(require
19+
'[nrepl.middleware :refer [set-descriptor!]]
20+
'[nrepl.misc :refer [response-for]]
21+
'[nrepl.transport :as transport]))
22+
1323
(defn- require-and-resolve [sym]
1424
(require (symbol (namespace sym)))
1525
(resolve sym))

test/refactor_nrepl/client.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:require [clojure
33
[edn :as edn]
44
[string :as str]]
5-
[clojure.tools.nrepl :as nrepl])
5+
[nrepl.core :as nrepl])
66
(:import java.io.File))
77

88
(def ^:private nrepl-port

test/refactor_nrepl/integration_tests.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns refactor-nrepl.integration-tests
22
(:require [clojure.java.io :as io]
33
[clojure.test :refer :all]
4-
[clojure.tools.nrepl.server :as nrserver]
4+
[nrepl.server :as nrserver]
55
[refactor-nrepl middleware
66
[client :refer :all]
77
[core :as core]]

test/refactor_nrepl/ns/clean_ns_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
[string :as str]]
140140
[clojure.data.json :as json]
141141
[clojure.java.io :as io]
142-
[clojure.tools.nrepl
142+
[nrepl
143143
[middleware :refer [set-descriptor!]]
144144
[misc :refer [response-for]]
145145
[transport :as transport]]

test/refactor_nrepl/ns/resolve_missing_caching_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns refactor-nrepl.ns.resolve-missing-caching-test
22
(:require [clojure
33
[edn :as edn]]
4-
[clojure.tools.nrepl :as nrepl]
4+
[nrepl.core :as nrepl]
55
[refactor-nrepl.ns.resolve-missing-test :refer [session-fixture]]
66
[clojure.test :refer [deftest testing is use-fixtures]]
77
[clojure.string :as str]))

test/refactor_nrepl/ns/resolve_missing_test.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(ns refactor-nrepl.ns.resolve-missing-test
2-
(:require [cemerick.piggieback :as piggieback]
2+
(:require [cider.piggieback :as piggieback]
33
[clojure
44
[edn :as edn]
55
[test :as t]]
6-
[clojure.tools.nrepl :as nrepl]
7-
[clojure.tools.nrepl.server :as server]
6+
[nrepl.core :as nrepl]
7+
[nrepl.server :as server]
88
[refactor-nrepl.middleware :as middleware]))
99

1010
(def ^:dynamic *handler* (server/default-handler #'middleware/wrap-refactor))
@@ -35,7 +35,7 @@
3535
#'piggieback/wrap-cljs-repl)]
3636
(message {:op :eval
3737
:code (nrepl/code
38-
(require '[cemerick.piggieback :as piggieback])
38+
(require '[cider.piggieback :as piggieback])
3939
(require '[cljs.repl.node :as node])
4040
(piggieback/cljs-repl (node/repl-env)))})
4141
(f)

test/resources/artifacts_pprinted

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[string :as str]]
55
[clojure.data.json :as json]
66
[clojure.java.io :as io]
7-
[clojure.tools.nrepl
7+
[nrepl
88
[middleware :refer [set-descriptor!]]
99
[misc :refer [response-for]]
1010
[transport :as transport]]

0 commit comments

Comments
 (0)