|
2 | 2 | (:require |
3 | 3 | [cider.nrepl.version :as version] |
4 | 4 | [cider.nrepl.middleware.util.cljs :as cljs] |
5 | | - [cider.nrepl.middleware.pprint :as pprint] |
6 | 5 | [cider.nrepl.print-method] |
7 | 6 | [nrepl.middleware :refer [set-descriptor!]] |
| 7 | + [nrepl.middleware.caught :refer [wrap-caught]] |
| 8 | + [nrepl.middleware.print :refer [wrap-print wrap-print-optional-arguments]] |
8 | 9 | [nrepl.middleware.session :refer [session]] |
9 | | - [nrepl.middleware.pr-values :refer [pr-values]] |
10 | 10 | [nrepl.server :as nrepl-server])) |
11 | 11 |
|
12 | 12 | (def delayed-handlers |
|
79 | 79 | ;; makes the code a bit more complex, but improves a lot the startup time |
80 | 80 | ;; as almost nothing gets loaded during REPL boot time. |
81 | 81 |
|
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 | | - |
107 | 82 | (def-wrapper wrap-content-type cider.nrepl.middleware.content-type/handle-content-type |
108 | 83 | #{"eval"} |
109 | 84 | {:doc "Middleware that adds `content-type` annotations to the result of the the eval op." |
| 85 | + :requires #{#'wrap-print} |
110 | 86 | :expects #{"eval" "load-file"} |
111 | 87 | :returns {"content-type" "A MIME type for the response, if one can be detected." |
112 | 88 | "content-transfer-encoding" "The encoding (if any) of the content." |
|
162 | 138 | (cljs/requires-piggieback |
163 | 139 | {:doc "Provide instrumentation and debugging functionality." |
164 | 140 | :expects #{"eval"} |
165 | | - :requires #{#'wrap-pprint-fn #'session} |
| 141 | + :requires #{#'wrap-print #'session} |
166 | 142 | :handles {"debug-input" |
167 | 143 | {:doc "Read client input on debug action." |
168 | 144 | :requires {"input" "The user's reply to the input request."} |
|
189 | 165 |
|
190 | 166 | (def-wrapper wrap-format cider.nrepl.middleware.format/handle-format |
191 | 167 | {:doc "Middleware providing support for formatting Clojure code and EDN data." |
192 | | - :requires #{#'wrap-pprint-fn} |
| 168 | + :requires #{#'wrap-print} |
193 | 169 | :handles {"format-code" |
194 | 170 | {:doc "Reformats the given Clojure code, returning the result as a string." |
195 | 171 | :requires {"code" "The code to format."} |
|
198 | 174 | "format-edn" |
199 | 175 | {:doc "Reformats the given EDN data, returning the result as a string." |
200 | 176 | :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 |
203 | 178 | :returns {"formatted-edn" "The formatted data."}}}}) |
204 | 179 |
|
205 | 180 | (def-wrapper wrap-info cider.nrepl.middleware.info/handle-info |
|
228 | 203 | in the `:inspect` slot will cause the last value returned by eval to |
229 | 204 | be inspected. Returns a string representation of the resulting |
230 | 205 | inspector's state in the `:value` slot." |
231 | | - :requires #{"clone" #'pr-values} |
| 206 | + :requires #{"clone" #'wrap-caught #'wrap-print} |
232 | 207 | :expects #{"eval"} |
233 | 208 | :handles {"inspect-pop" |
234 | 209 | {:doc "Moves one level up in the inspector stack." |
|
358 | 333 |
|
359 | 334 | (def-wrapper wrap-refresh cider.nrepl.middleware.refresh/handle-refresh |
360 | 335 | {:doc "Refresh middleware." |
361 | | - :requires #{"clone" #'wrap-pprint-fn} |
| 336 | + :requires #{"clone" #'wrap-print} |
362 | 337 | :handles {"refresh" |
363 | 338 | {:doc "Reloads all changed files in dependency order." |
364 | | - :optional (merge wrap-pprint-fn-optional-arguments |
| 339 | + :optional (merge wrap-print-optional-arguments |
365 | 340 | {"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath." |
366 | 341 | "before" "The namespace-qualified name of a zero-arity function to call before reloading." |
367 | 342 | "after" "The namespace-qualified name of a zero-arity function to call after reloading."}) |
|
371 | 346 | "error-ns" "The namespace that caused reloading to fail when `status` is `:error`."}} |
372 | 347 | "refresh-all" |
373 | 348 | {:doc "Reloads all files in dependency order." |
374 | | - :optional (merge wrap-pprint-fn-optional-arguments |
| 349 | + :optional (merge wrap-print-optional-arguments |
375 | 350 | {"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath." |
376 | 351 | "before" "The namespace-qualified name of a zero-arity function to call before reloading." |
377 | 352 | "after" "The namespace-qualified name of a zero-arity function to call after reloading."}) |
|
414 | 389 | (cljs/requires-piggieback |
415 | 390 | {:doc "Middleware that handles stacktrace requests, sending |
416 | 391 | cause and stack frame info for the most recent exception." |
417 | | - :requires #{#'session #'wrap-pprint-fn} |
| 392 | + :requires #{#'session #'wrap-print} |
418 | 393 | :expects #{} |
419 | 394 | :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 |
421 | 396 | :returns {"status" "\"done\", or \"no-error\" if `*e` is nil"}}}})) |
422 | 397 |
|
423 | 398 | (def-wrapper wrap-test cider.nrepl.middleware.test/handle-test |
424 | 399 | {:doc "Middleware that handles testing requests." |
425 | | - :requires #{#'session #'wrap-pprint-fn} |
426 | | - :expects #{#'pr-values} |
| 400 | + :requires #{#'session #'wrap-print} |
427 | 401 | :handles {"test-var-query" |
428 | 402 | {: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} |
430 | 404 | "test" |
431 | 405 | {: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} |
433 | 407 | "test-all" |
434 | 408 | {: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} |
436 | 410 | "test-stacktrace" |
437 | 411 | {: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} |
439 | 413 | "retest" |
440 | 414 | {: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}}}) |
442 | 416 |
|
443 | 417 | (def-wrapper wrap-trace cider.nrepl.middleware.trace/handle-trace |
444 | 418 | {:doc "Toggle tracing of a given var." |
|
504 | 478 | wrap-out |
505 | 479 | wrap-content-type |
506 | 480 | wrap-slurp |
507 | | - wrap-pprint-fn |
508 | 481 | wrap-profile |
509 | 482 | wrap-refresh |
510 | 483 | wrap-resource |
|
0 commit comments