Skip to content

Commit e7175f1

Browse files
authored
Merge pull request #590 from cichli/session-exec
Use new session exec in test and refresh middleware
2 parents d9be18e + 6d61a14 commit e7175f1

File tree

24 files changed

+310
-321
lines changed

24 files changed

+310
-321
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## master (unreleased)
44

5+
### New features
6+
7+
* The `refresh` op is now interruptible.
8+
9+
### Changes
10+
11+
* **(Breaking)** Upgrade to nREPL 0.6.0. This is now the minimum required version.
12+
* **(Breaking)** Upgrade to piggieback 0.4.0. This is now the minimum required version.
13+
* **(Breaking)** Remove `cider.nrepl.middleware.pprint`. All functionality has been replaced by the built-in printing support in nREPL 0.6.0.
14+
515
## 0.20.0 (2019-01-14)
616

717
### New features

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ boot -d nrepl:0.5.3 -d cider/cider-nrepl:0.20.0 -i "(require 'cider.tasks)" cide
161161
Or for all of their projects by adding a `~/.boot/profile.boot` file like so:
162162

163163
```clojure
164-
(set-env! :dependencies '[[nrepl "0.5.3"]
164+
(set-env! :dependencies '[[nrepl "0.6.0"]
165165
[cider/cider-nrepl "0.20.0"]])
166166

167167
(require '[cider.tasks :refer [add-middleware nrepl-server]])
@@ -268,8 +268,6 @@ Middleware | Op(s) | Description
268268
`wrap-macroexpand`| `macroexpand/macroexpand-1/macroexpand-all/macroexpand-step` | Macroexpand a Clojure form.
269269
`wrap-ns` | `ns-list/ns-vars/ns-path/ns-load-all/ns-aliases` | Namespace browsing & loading.
270270
`wrap-spec` | `spec-list/spec-form/spec-example` | Spec browsing.
271-
`wrap-pprint` | - | **(DEPRECATED)** Adds pretty-printing support to code evaluation. It also installs a dummy `pprint-middleware` op. Thus `wrap-pprint` is discoverable through the `describe` op.
272-
`wrap-pprint-fn` | - | **(DEPRECATED)** Provides a common pretty-printing interface for other middlewares that need to perform customisable pretty-printing.
273271
`wrap-profile` | `toggle-profile/toggle-profile-ns/is-var-profiled/profile-summary/profile-var-summary/clear-profile/get-max-samples/set-max-samples` | Provides profiling support based on the [profile](https://github.com/thunknyc/profile) library.
274272
`wrap-refresh` | `refresh/refresh-all/refresh-clear` | Code reloading.
275273
`wrap-resource` | `resource` | Return resource path.

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{:paths ["src" "resources"]
2-
:deps {nrepl {:mvn/version "0.4.5"}
2+
:deps {nrepl {:mvn/version "0.6.0"}
33
cider/orchard {:mvn/version "0.3.1"}
44
thunknyc/profile {:mvn/version "0.5.2"}
55
mvxcvi/puget {:mvn/version "1.0.2"}

project.clj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
(defproject cider/cider-nrepl "0.20.1-SNAPSHOT"
1+
(defproject cider/cider-nrepl "0.21.0-SNAPSHOT"
22
:description "nREPL middlewares for CIDER"
33
:url "https://github.com/clojure-emacs/cider-nrepl"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
77

8-
:dependencies [[nrepl "0.5.3"]
8+
:dependencies [[nrepl "0.6.0"]
99
^:source-dep [cider/orchard "0.4.0"]
1010
^:source-dep [thunknyc/profile "0.5.2"]
1111
^:source-dep [mvxcvi/puget "1.1.0"]
@@ -79,7 +79,7 @@
7979
:test {:source-paths ["test/src"]
8080
:java-source-paths ["test/java"]
8181
:resource-paths ["test/resources"]
82-
:dependencies [[cider/piggieback "0.3.10"]]}
82+
:dependencies [[cider/piggieback "0.4.0"]]}
8383

8484
;; Need ^:repl because of: https://github.com/technomancy/leiningen/issues/2132
8585
:repl ^:repl [:test
@@ -95,7 +95,6 @@
9595
cider.nrepl/wrap-macroexpand
9696
cider.nrepl/wrap-ns
9797
cider.nrepl/wrap-out
98-
cider.nrepl/wrap-pprint-fn
9998
cider.nrepl/wrap-profile
10099
cider.nrepl/wrap-refresh
101100
cider.nrepl/wrap-resource

src/cider/nrepl.clj

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
(:require
33
[cider.nrepl.version :as version]
44
[cider.nrepl.middleware.util.cljs :as cljs]
5-
[cider.nrepl.middleware.pprint :as pprint]
65
[cider.nrepl.print-method]
76
[nrepl.middleware :refer [set-descriptor!]]
7+
[nrepl.middleware.caught :refer [wrap-caught]]
8+
[nrepl.middleware.print :refer [wrap-print wrap-print-optional-arguments]]
89
[nrepl.middleware.session :refer [session]]
9-
[nrepl.middleware.pr-values :refer [pr-values]]
1010
[nrepl.server :as nrepl-server]))
1111

1212
(def delayed-handlers
@@ -79,34 +79,10 @@
7979
;; makes the code a bit more complex, but improves a lot the startup time
8080
;; as almost nothing gets loaded during REPL boot time.
8181

82-
(def wrap-pprint-fn-optional-arguments
83-
"Common pprint arguments for CIDER's middleware."
84-
{"pprint-fn" "The namespace-qualified name of a 1 or 2-arity function to use for pretty-printing. Defaults to `cider.nrepl.pprint/pprint`."
85-
"print-options" "A map of configuration entries that the pprint-fn will understand. Those would typically be specific to the pprint-fn in question."})
86-
87-
(def-wrapper wrap-pprint-fn cider.nrepl.middleware.pprint/handle-pprint-fn
88-
(fn [msg] true)
89-
{:doc "Middleware that provides a common interface for other middlewares that
90-
need to perform customisable pretty-printing.
91-
92-
A namespace-qualified name of the function to be used for printing can
93-
be optionally passed in the `:pprint-fn` slot, the default value being
94-
`cider.nrepl.pprint/pprint`. The function name can be passed as
95-
a string or symbol. Note that function should take 1 or two params - the
96-
object to print and the an optional map of print params. The params should
97-
be passed as `:print-options` - a map of key/value params.
98-
99-
The `:pprint-fn` slot will be replaced with the var that maps to the name
100-
that was initially passed.
101-
102-
Middlewares further down the stack can then look up the `:pprint-fn`
103-
slot, call it where necessary, and pass it the value of the `:print-options` slot."
104-
:requires #{#'session}
105-
:expects #{"eval" "load-file"}})
106-
10782
(def-wrapper wrap-content-type cider.nrepl.middleware.content-type/handle-content-type
10883
#{"eval"}
10984
{:doc "Middleware that adds `content-type` annotations to the result of the the eval op."
85+
:requires #{#'wrap-print}
11086
:expects #{"eval" "load-file"}
11187
:returns {"content-type" "A MIME type for the response, if one can be detected."
11288
"content-transfer-encoding" "The encoding (if any) of the content."
@@ -162,7 +138,7 @@
162138
(cljs/requires-piggieback
163139
{:doc "Provide instrumentation and debugging functionality."
164140
:expects #{"eval"}
165-
:requires #{#'wrap-pprint-fn #'session}
141+
:requires #{#'wrap-print #'session}
166142
:handles {"debug-input"
167143
{:doc "Read client input on debug action."
168144
:requires {"input" "The user's reply to the input request."}
@@ -189,7 +165,7 @@
189165

190166
(def-wrapper wrap-format cider.nrepl.middleware.format/handle-format
191167
{:doc "Middleware providing support for formatting Clojure code and EDN data."
192-
:requires #{#'wrap-pprint-fn}
168+
:requires #{#'wrap-print}
193169
:handles {"format-code"
194170
{:doc "Reformats the given Clojure code, returning the result as a string."
195171
:requires {"code" "The code to format."}
@@ -198,8 +174,7 @@
198174
"format-edn"
199175
{:doc "Reformats the given EDN data, returning the result as a string."
200176
:requires {"edn" "The data to format."}
201-
:optional {"print-options" "A map of params for the print function."
202-
"pprint-fn" "Fully qualified name of the print function to be used."}
177+
:optional wrap-print-optional-arguments
203178
:returns {"formatted-edn" "The formatted data."}}}})
204179

205180
(def-wrapper wrap-info cider.nrepl.middleware.info/handle-info
@@ -228,7 +203,7 @@
228203
in the `:inspect` slot will cause the last value returned by eval to
229204
be inspected. Returns a string representation of the resulting
230205
inspector's state in the `:value` slot."
231-
:requires #{"clone" #'pr-values}
206+
:requires #{"clone" #'wrap-caught #'wrap-print}
232207
:expects #{"eval"}
233208
:handles {"inspect-pop"
234209
{:doc "Moves one level up in the inspector stack."
@@ -358,10 +333,10 @@
358333

359334
(def-wrapper wrap-refresh cider.nrepl.middleware.refresh/handle-refresh
360335
{:doc "Refresh middleware."
361-
:requires #{"clone" #'wrap-pprint-fn}
336+
:requires #{"clone" #'wrap-print}
362337
:handles {"refresh"
363338
{:doc "Reloads all changed files in dependency order."
364-
:optional (merge wrap-pprint-fn-optional-arguments
339+
:optional (merge wrap-print-optional-arguments
365340
{"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath."
366341
"before" "The namespace-qualified name of a zero-arity function to call before reloading."
367342
"after" "The namespace-qualified name of a zero-arity function to call after reloading."})
@@ -371,7 +346,7 @@
371346
"error-ns" "The namespace that caused reloading to fail when `status` is `:error`."}}
372347
"refresh-all"
373348
{:doc "Reloads all files in dependency order."
374-
:optional (merge wrap-pprint-fn-optional-arguments
349+
:optional (merge wrap-print-optional-arguments
375350
{"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath."
376351
"before" "The namespace-qualified name of a zero-arity function to call before reloading."
377352
"after" "The namespace-qualified name of a zero-arity function to call after reloading."})
@@ -414,31 +389,30 @@
414389
(cljs/requires-piggieback
415390
{:doc "Middleware that handles stacktrace requests, sending
416391
cause and stack frame info for the most recent exception."
417-
:requires #{#'session #'wrap-pprint-fn}
392+
:requires #{#'session #'wrap-print}
418393
:expects #{}
419394
:handles {"stacktrace" {:doc "Return messages describing each cause and stack frame of the most recent exception."
420-
:optional wrap-pprint-fn-optional-arguments
395+
:optional wrap-print-optional-arguments
421396
:returns {"status" "\"done\", or \"no-error\" if `*e` is nil"}}}}))
422397

423398
(def-wrapper wrap-test cider.nrepl.middleware.test/handle-test
424399
{:doc "Middleware that handles testing requests."
425-
:requires #{#'session #'wrap-pprint-fn}
426-
:expects #{#'pr-values}
400+
:requires #{#'session #'wrap-print}
427401
:handles {"test-var-query"
428402
{:doc "Run tests specified by the `var-query` and return results. Results are cached for exception retrieval and to enable re-running of failed/erring tests."
429-
:optional wrap-pprint-fn-optional-arguments}
403+
:optional wrap-print-optional-arguments}
430404
"test"
431405
{:doc "[DEPRECATED] Run tests in the specified namespace and return results. This accepts a set of `tests` to be run; if nil, runs all tests. Results are cached for exception retrieval and to enable re-running of failed/erring tests."
432-
:optional wrap-pprint-fn-optional-arguments}
406+
:optional wrap-print-optional-arguments}
433407
"test-all"
434408
{:doc "[DEPRECATED] Run all tests in the project. If `load?` is truthy, all project namespaces are loaded; otherwise, only tests in presently loaded namespaces are run. Results are cached for exception retrieval and to enable re-running of failed/erring tests."
435-
:optional wrap-pprint-fn-optional-arguments}
409+
:optional wrap-print-optional-arguments}
436410
"test-stacktrace"
437411
{:doc "Rerun all tests that did not pass when last run. Results are cached for exception retrieval and to enable re-running of failed/erring tests."
438-
:optional wrap-pprint-fn-optional-arguments}
412+
:optional wrap-print-optional-arguments}
439413
"retest"
440414
{:doc "Return exception cause and stack frame info for an erring test via the `stacktrace` middleware. The error to be retrieved is referenced by namespace, var name, and assertion index within the var."
441-
:optional wrap-pprint-fn-optional-arguments}}})
415+
:optional wrap-print-optional-arguments}}})
442416

443417
(def-wrapper wrap-trace cider.nrepl.middleware.trace/handle-trace
444418
{:doc "Toggle tracing of a given var."
@@ -504,7 +478,6 @@
504478
wrap-out
505479
wrap-content-type
506480
wrap-slurp
507-
wrap-pprint-fn
508481
wrap-profile
509482
wrap-refresh
510483
wrap-resource

src/cider/nrepl/middleware/debug.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[cider.nrepl.middleware.util.instrument :as ins]
99
[cider.nrepl.middleware.util.nrepl :refer [notify-client]]
1010
[nrepl.middleware.interruptible-eval :refer [*msg*]]
11+
[nrepl.middleware.print :as print]
1112
[nrepl.middleware.session :as session]
1213
[nrepl.misc :refer [response-for]]
1314
[nrepl.transport :as transport]
@@ -216,7 +217,7 @@ this map (identified by a key), and will `dissoc` it afterwards."}
216217
(when-not (instance? ThreadDeath root-ex#)
217218
(debugger-send
218219
{:status :eval-error
219-
:causes [(let [causes# (stacktrace/analyze-causes e# (:pprint-fn *msg*) (:print-options *msg*))]
220+
:causes [(let [causes# (stacktrace/analyze-causes e# (::print/print-fn *msg*))]
220221
(when (coll? causes#) (last causes#)))]})))
221222
error#))]
222223
(if (= error# ~sym)
@@ -290,7 +291,7 @@ this map (identified by a key), and will `dissoc` it afterwards."}
290291
:causes [{:class "StackTrace"
291292
:message "Harmless user-requested stacktrace"
292293
:stacktrace (-> (Exception. "Dummy")
293-
(stacktrace/analyze-causes (:pprint-fn *msg*) (:print-options *msg*))
294+
(stacktrace/analyze-causes (::print/print-fn *msg*))
294295
last :stacktrace)}]}))
295296

296297
(def debug-commands

src/cider/nrepl/middleware/format.clj

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
[clojure.string :as str]
88
[clojure.tools.reader.edn :as edn]
99
[clojure.tools.reader.reader-types :as readers]
10-
[clojure.walk :as walk]))
10+
[clojure.walk :as walk]
11+
[nrepl.middleware.print :as print])
12+
(:import
13+
(java.io StringWriter)))
1114

1215
;;; Code formatting
1316
(defn- keyword->symbol [kw]
@@ -43,15 +46,18 @@
4346
(recur (conj forms form)))))))
4447

4548
(defn- format-edn
46-
[edn pprint-fn print-options]
49+
[edn print-fn]
4750
(->> (read-edn edn)
48-
(map #(pprint-fn % print-options))
51+
(map (fn [value]
52+
(let [writer (StringWriter.)]
53+
(print-fn value writer)
54+
(str writer))))
4955
(str/join "\n")
50-
str/trim))
56+
(str/trim)))
5157

5258
(defn format-edn-reply
53-
[{:keys [edn pprint-fn print-options] :as msg}]
54-
{:formatted-edn (format-edn edn pprint-fn print-options)})
59+
[{:keys [edn ::print/print-fn] :as msg}]
60+
{:formatted-edn (format-edn edn print-fn)})
5561

5662
;;; Middleware op handling
5763
(defn handle-format [handler msg]

src/cider/nrepl/middleware/inspect.clj

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,34 @@
33
[cider.nrepl.middleware.util.cljs :as cljs]
44
[cider.nrepl.middleware.util.error-handling :refer [base-error-response
55
with-safe-transport]]
6+
[nrepl.middleware.caught :as caught]
67
[nrepl.misc :refer [response-for]]
78
[nrepl.transport :as transport]
89
[orchard.inspect :as inspect])
910
(:import
1011
nrepl.transport.Transport))
1112

12-
(def ^:dynamic *inspector* (inspect/fresh))
13-
1413
(defn swap-inspector!
1514
[{:keys [session] :as msg} f & args]
1615
(-> session
17-
(swap! update-in [#'*inspector*] #(apply f % args))
18-
(get #'*inspector*)))
16+
(alter-meta! update ::inspector #(apply f % args))
17+
(get ::inspector)))
18+
19+
(defn- inspector-response
20+
([msg inspector]
21+
(inspector-response msg inspector {:status :done}))
22+
([msg {:keys [rendered] :as inspector} resp]
23+
(let [value (binding [*print-length* nil]
24+
(pr-str rendered))]
25+
(response-for msg resp {:value value}))))
1926

2027
(defn inspect-reply
2128
[{:keys [page-size transport] :as msg} eval-response]
2229
(let [value (cljs/response-value msg eval-response)
2330
page-size (or page-size 32)
2431
inspector (swap-inspector! msg #(-> (assoc % :page-size page-size)
2532
(inspect/start value)))]
26-
(binding [*print-length* nil]
27-
;; Remove print-length limit because it breaks the output in the middle of
28-
;; the page when inspecting long sequences.
29-
(transport/send
30-
transport
31-
(response-for msg :value (:rendered inspector))))))
33+
(transport/send transport (inspector-response msg inspector {}))))
3234

3335
(defn inspector-transport
3436
[{:keys [^Transport transport, session] :as msg}]
@@ -42,9 +44,9 @@
4244
;; If the eval errored, propagate the exception as error in the
4345
;; inspector middleware, so that the client CIDER code properly
4446
;; renders it instead of silently ignoring it.
45-
(contains? (:status response) :eval-error)
46-
(let [e (or (@session #'*e)
47-
(Exception. (or (:ex response) "")))
47+
(and (contains? (:status response) :eval-error)
48+
(contains? response ::caught/throwable))
49+
(let [e (::caught/throwable response)
4850
resp (base-error-response msg e :inspect-eval-error :done)]
4951
(.send transport resp))
5052

@@ -61,9 +63,6 @@
6163
[handler msg]
6264
(handler (eval-msg msg)))
6365

64-
(defn- inspector-response [msg inspector]
65-
(response-for msg :value (:rendered inspector) :status :done))
66-
6766
(defn pop-reply [msg]
6867
(inspector-response msg (swap-inspector! msg inspect/up)))
6968

@@ -74,7 +73,7 @@
7473
(inspector-response msg (swap-inspector! msg #(or % (inspect/fresh)))))
7574

7675
(defn get-path-reply [{:keys [session] :as msg}]
77-
(:path (get session #'*inspector*)))
76+
(get-in (meta session) [::inspector :path]))
7877

7978
(defn next-page-reply [msg]
8079
(inspector-response msg (swap-inspector! msg inspect/next-page)))

src/cider/nrepl/middleware/pprint.clj

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)