|
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!]] |
8 | 7 | [nrepl.middleware.caught :refer [wrap-caught]] |
| 8 | + [nrepl.middleware.print :refer [wrap-print wrap-print-optional-arguments]] |
9 | 9 | [nrepl.middleware.session :refer [session]] |
10 | | - [nrepl.middleware.pr-values :refer [pr-values]] |
11 | 10 | [nrepl.server :as nrepl-server])) |
12 | 11 |
|
13 | 12 | (def delayed-handlers |
|
80 | 79 | ;; makes the code a bit more complex, but improves a lot the startup time |
81 | 80 | ;; as almost nothing gets loaded during REPL boot time. |
82 | 81 |
|
83 | | -(def wrap-pprint-fn-optional-arguments |
84 | | - "Common pprint arguments for CIDER's middleware." |
85 | | - {"pprint-fn" "The namespace-qualified name of a 1 or 2-arity function to use for pretty-printing. Defaults to `cider.nrepl.pprint/pprint`." |
86 | | - "print-options" "A map of configuration entries that the pprint-fn will understand. Those would typically be specific to the pprint-fn in question."}) |
87 | | - |
88 | | -(def-wrapper wrap-pprint-fn cider.nrepl.middleware.pprint/handle-pprint-fn |
89 | | - (fn [msg] true) |
90 | | - {:doc "Middleware that provides a common interface for other middlewares that |
91 | | - need to perform customisable pretty-printing. |
92 | | -
|
93 | | - A namespace-qualified name of the function to be used for printing can |
94 | | - be optionally passed in the `:pprint-fn` slot, the default value being |
95 | | - `cider.nrepl.pprint/pprint`. The function name can be passed as |
96 | | - a string or symbol. Note that function should take 1 or two params - the |
97 | | - object to print and the an optional map of print params. The params should |
98 | | - be passed as `:print-options` - a map of key/value params. |
99 | | -
|
100 | | - The `:pprint-fn` slot will be replaced with the var that maps to the name |
101 | | - that was initially passed. |
102 | | -
|
103 | | - Middlewares further down the stack can then look up the `:pprint-fn` |
104 | | - slot, call it where necessary, and pass it the value of the `:print-options` slot." |
105 | | - :requires #{#'session} |
106 | | - :expects #{"eval" "load-file"}}) |
107 | | - |
108 | 82 | (def-wrapper wrap-content-type cider.nrepl.middleware.content-type/handle-content-type |
109 | 83 | #{"eval"} |
110 | 84 | {:doc "Middleware that adds `content-type` annotations to the result of the the eval op." |
| 85 | + :requires #{#'wrap-print} |
111 | 86 | :expects #{"eval" "load-file"} |
112 | 87 | :returns {"content-type" "A MIME type for the response, if one can be detected." |
113 | 88 | "content-transfer-encoding" "The encoding (if any) of the content." |
|
163 | 138 | (cljs/requires-piggieback |
164 | 139 | {:doc "Provide instrumentation and debugging functionality." |
165 | 140 | :expects #{"eval"} |
166 | | - :requires #{#'wrap-pprint-fn #'session} |
| 141 | + :requires #{#'wrap-print #'session} |
167 | 142 | :handles {"debug-input" |
168 | 143 | {:doc "Read client input on debug action." |
169 | 144 | :requires {"input" "The user's reply to the input request."} |
|
190 | 165 |
|
191 | 166 | (def-wrapper wrap-format cider.nrepl.middleware.format/handle-format |
192 | 167 | {:doc "Middleware providing support for formatting Clojure code and EDN data." |
193 | | - :requires #{#'wrap-pprint-fn} |
| 168 | + :requires #{#'wrap-print} |
194 | 169 | :handles {"format-code" |
195 | 170 | {:doc "Reformats the given Clojure code, returning the result as a string." |
196 | 171 | :requires {"code" "The code to format."} |
|
199 | 174 | "format-edn" |
200 | 175 | {:doc "Reformats the given EDN data, returning the result as a string." |
201 | 176 | :requires {"edn" "The data to format."} |
202 | | - :optional {"print-options" "A map of params for the print function." |
203 | | - "pprint-fn" "Fully qualified name of the print function to be used."} |
| 177 | + :optional wrap-print-optional-arguments |
204 | 178 | :returns {"formatted-edn" "The formatted data."}}}}) |
205 | 179 |
|
206 | 180 | (def-wrapper wrap-info cider.nrepl.middleware.info/handle-info |
|
229 | 203 | in the `:inspect` slot will cause the last value returned by eval to |
230 | 204 | be inspected. Returns a string representation of the resulting |
231 | 205 | inspector's state in the `:value` slot." |
232 | | - :requires #{"clone" #'pr-values #'wrap-caught} |
| 206 | + :requires #{"clone" #'wrap-caught #'wrap-print} |
233 | 207 | :expects #{"eval"} |
234 | 208 | :handles {"inspect-pop" |
235 | 209 | {:doc "Moves one level up in the inspector stack." |
|
359 | 333 |
|
360 | 334 | (def-wrapper wrap-refresh cider.nrepl.middleware.refresh/handle-refresh |
361 | 335 | {:doc "Refresh middleware." |
362 | | - :requires #{"clone" #'wrap-pprint-fn} |
| 336 | + :requires #{"clone" #'wrap-print} |
363 | 337 | :handles {"refresh" |
364 | 338 | {:doc "Reloads all changed files in dependency order." |
365 | | - :optional (merge wrap-pprint-fn-optional-arguments |
| 339 | + :optional (merge wrap-print-optional-arguments |
366 | 340 | {"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath." |
367 | 341 | "before" "The namespace-qualified name of a zero-arity function to call before reloading." |
368 | 342 | "after" "The namespace-qualified name of a zero-arity function to call after reloading."}) |
|
372 | 346 | "error-ns" "The namespace that caused reloading to fail when `status` is `:error`."}} |
373 | 347 | "refresh-all" |
374 | 348 | {:doc "Reloads all files in dependency order." |
375 | | - :optional (merge wrap-pprint-fn-optional-arguments |
| 349 | + :optional (merge wrap-print-optional-arguments |
376 | 350 | {"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath." |
377 | 351 | "before" "The namespace-qualified name of a zero-arity function to call before reloading." |
378 | 352 | "after" "The namespace-qualified name of a zero-arity function to call after reloading."}) |
|
415 | 389 | (cljs/requires-piggieback |
416 | 390 | {:doc "Middleware that handles stacktrace requests, sending |
417 | 391 | cause and stack frame info for the most recent exception." |
418 | | - :requires #{#'session #'wrap-pprint-fn} |
| 392 | + :requires #{#'session #'wrap-print} |
419 | 393 | :expects #{} |
420 | 394 | :handles {"stacktrace" {:doc "Return messages describing each cause and stack frame of the most recent exception." |
421 | | - :optional wrap-pprint-fn-optional-arguments |
| 395 | + :optional wrap-print-optional-arguments |
422 | 396 | :returns {"status" "\"done\", or \"no-error\" if `*e` is nil"}}}})) |
423 | 397 |
|
424 | 398 | (def-wrapper wrap-test cider.nrepl.middleware.test/handle-test |
425 | 399 | {:doc "Middleware that handles testing requests." |
426 | | - :requires #{#'session #'wrap-pprint-fn} |
427 | | - :expects #{#'pr-values} |
| 400 | + :requires #{#'session #'wrap-print} |
428 | 401 | :handles {"test-var-query" |
429 | 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." |
430 | | - :optional wrap-pprint-fn-optional-arguments} |
| 403 | + :optional wrap-print-optional-arguments} |
431 | 404 | "test" |
432 | 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." |
433 | | - :optional wrap-pprint-fn-optional-arguments} |
| 406 | + :optional wrap-print-optional-arguments} |
434 | 407 | "test-all" |
435 | 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." |
436 | | - :optional wrap-pprint-fn-optional-arguments} |
| 409 | + :optional wrap-print-optional-arguments} |
437 | 410 | "test-stacktrace" |
438 | 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." |
439 | | - :optional wrap-pprint-fn-optional-arguments} |
| 412 | + :optional wrap-print-optional-arguments} |
440 | 413 | "retest" |
441 | 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." |
442 | | - :optional wrap-pprint-fn-optional-arguments}}}) |
| 415 | + :optional wrap-print-optional-arguments}}}) |
443 | 416 |
|
444 | 417 | (def-wrapper wrap-trace cider.nrepl.middleware.trace/handle-trace |
445 | 418 | {:doc "Toggle tracing of a given var." |
|
505 | 478 | wrap-out |
506 | 479 | wrap-content-type |
507 | 480 | wrap-slurp |
508 | | - wrap-pprint-fn |
509 | 481 | wrap-profile |
510 | 482 | wrap-refresh |
511 | 483 | wrap-resource |
|
0 commit comments