|
3 | 3 | [clojure.tools.nrepl.middleware.session :refer [session]]
|
4 | 4 | [clojure.tools.nrepl.middleware.pr-values :refer [pr-values]]
|
5 | 5 | [clojure.tools.nrepl.server :as nrepl-server]
|
| 6 | + [cider.nrepl.version :as version] |
6 | 7 | [cider.nrepl.middleware.util.cljs :as cljs]
|
7 | 8 | [cider.nrepl.middleware.pprint :as pprint]
|
8 |
| - [cider.nrepl.middleware.version] |
9 | 9 | [cider.nrepl.print-method]))
|
10 | 10 |
|
11 | 11 | (def DELAYS (atom nil))
|
|
60 | 60 |
|
61 | 61 | ;;; Wrappers
|
62 | 62 |
|
63 |
| -(def-wrapper wrap-debug cider.nrepl.middleware.debug/handle-debug |
64 |
| - #{"eval"} |
65 |
| - (cljs/requires-piggieback |
66 |
| - {:doc "Provide instrumentation and debugging functionality." |
67 |
| - :expects #{"eval"} |
68 |
| - :requires #{#'pprint/wrap-pprint-fn #'session} |
69 |
| - :handles {"debug-input" |
70 |
| - {:doc "Read client input on debug action." |
71 |
| - :requires {"input" "The user's reply to the input request."} |
72 |
| - :returns {"status" "done"}} |
73 |
| - "init-debugger" |
74 |
| - {:doc "Initialize the debugger so that `breakpoint` works correctly. This usually does not respond immediately. It sends a response when a breakpoint is reached or when the message is discarded." |
75 |
| - :requires {"id" "A message id that will be responded to when a breakpoint is reached."}} |
76 |
| - "debug-instrumented-defs" |
77 |
| - {:doc "Return an alist of definitions currently thought to be instrumented on each namespace. Due to Clojure's versatility, this could include false postives, but there will not be false negatives. Instrumentations inside protocols are not listed." |
78 |
| - :returns {"status" "done" |
79 |
| - "list" "The alist of (NAMESPACE . VARS) that are thought to be instrumented."}} |
80 |
| - "debug-middleware" |
81 |
| - {:doc "Debug a code form or fall back on regular eval." |
82 |
| - :requires {"id" "A message id that will be responded to when a breakpoint is reached." |
83 |
| - "code" "Code to debug, there must be a #dbg or a #break reader macro in it, or nothing will happen." |
84 |
| - "file" "File where the code is located." |
85 |
| - "ns" "Passed to \"eval\"." |
86 |
| - "point" "Position in the file where the provided code begins."} |
87 |
| - :returns {"status" "\"done\" if the message will no longer be used, or \"need-debug-input\" during debugging sessions"}}}})) |
| 63 | +(def wrap-pprint-fn-optional-arguments |
| 64 | + "Common pprint arguments for CIDER's middleware." |
| 65 | + {"pprint-fn" "The namespace-qualified name of a single-arity function to use for pretty-printing. Defaults to `clojure.pprint/pprint`." |
| 66 | + "print-length" "Value to bind to `*print-length*` when pretty-printing. Defaults to the value bound in the current REPL session." |
| 67 | + "print-level" "Value to bind to `*print-level*` when pretty-printing. Defaults to the value bound in the current REPL session." |
| 68 | + "print-meta" "Value to bind to `*print-meta*` when pretty-printing. Defaults to the value bound in the current REPL session." |
| 69 | + "print-right-margin" "Value to bind to `clojure.pprint/*print-right-margin*` when pretty-printing. Defaults to the value bound in the current REPL session."}) |
88 | 70 |
|
89 |
| -(def-wrapper wrap-enlighten cider.nrepl.middleware.enlighten/handle-enlighten |
90 |
| - :enlighten |
91 |
| - {:expects #{"eval" #'wrap-debug}}) |
| 71 | +(def-wrapper wrap-pprint-fn cider.nrepl.middleware.pprint/handle-pprint-fn |
| 72 | + (fn [msg] true) |
| 73 | + {:doc "Middleware that provides a common interface for other middlewares that |
| 74 | + need to perform customisable pretty-printing. |
| 75 | +
|
| 76 | + A namespace-qualified name of the function to be used for printing can |
| 77 | + be optionally passed in the `:pprint-fn` slot, the default value being |
| 78 | + `clojure.pprint/pprint`. |
| 79 | +
|
| 80 | + The `:pprint-fn` slot will be replaced with a closure that calls the |
| 81 | + given printing function with `*print-length*`, `*print-level*`, |
| 82 | + `*print-meta*`, and `clojure.pprint/*print-right-margin*` bound to the |
| 83 | + values of the `:print-length`, `:print-level`, `:print-meta`, and |
| 84 | + `:print-right-margin` slots respectively. |
| 85 | +
|
| 86 | + Middlewares further down the stack can then look up the `:pprint-fn` |
| 87 | + slot and call it where necessary." |
| 88 | + :requires #{#'session}}) |
| 89 | + |
| 90 | +(def-wrapper wrap-pprint cider.nrepl.middleware.pprint/handle-pprint |
| 91 | + #{"eval" "load-file"} |
| 92 | + (cljs/expects-piggieback |
| 93 | + {:doc "Middleware that adds a pretty-printing option to the eval op. |
| 94 | + Passing a non-nil value in the `:pprint` slot will cause eval to call |
| 95 | + clojure.pprint/pprint on its result. The `:right-margin` slot can be |
| 96 | + used to bind `*clojure.pprint/*print-right-margin*` during the |
| 97 | + evaluation. (N.B., the encoding used to transmit the request map |
| 98 | + `msg` across the wire will convert presumably falsey values into |
| 99 | + truthy values. If you don't want something to be pretty printed, |
| 100 | + remove the `:pprint` key entirely from your request map, don't try |
| 101 | + and set the value to nil, false, or string representations of the |
| 102 | + above)." |
| 103 | + :requires #{"clone" #'pr-values #'wrap-pprint-fn} |
| 104 | + :expects #{"eval" "load-file"} |
| 105 | + :handles {"pprint-middleware" |
| 106 | + {:doc "Enhances the `eval` op by adding pretty-printing. Not an op in itself." |
| 107 | + :optional (merge wrap-pprint-fn-optional-arguments |
| 108 | + {"pprint" "If present and non-nil, pretty-print the result of evaluation."})}}})) |
92 | 109 |
|
93 | 110 | (def-wrapper wrap-apropos cider.nrepl.middleware.apropos/handle-apropos
|
94 | 111 | {:doc "Middleware that handles apropos requests"
|
|
124 | 141 | "complete-flush-caches"
|
125 | 142 | {:doc "Forces the completion backend to repopulate all its caches"}}}))
|
126 | 143 |
|
| 144 | +(def-wrapper wrap-debug cider.nrepl.middleware.debug/handle-debug |
| 145 | + #{"eval"} |
| 146 | + (cljs/requires-piggieback |
| 147 | + {:doc "Provide instrumentation and debugging functionality." |
| 148 | + :expects #{"eval"} |
| 149 | + :requires #{#'wrap-pprint-fn #'session} |
| 150 | + :handles {"debug-input" |
| 151 | + {:doc "Read client input on debug action." |
| 152 | + :requires {"input" "The user's reply to the input request."} |
| 153 | + :returns {"status" "done"}} |
| 154 | + "init-debugger" |
| 155 | + {:doc "Initialize the debugger so that `breakpoint` works correctly. This usually does not respond immediately. It sends a response when a breakpoint is reached or when the message is discarded." |
| 156 | + :requires {"id" "A message id that will be responded to when a breakpoint is reached."}} |
| 157 | + "debug-instrumented-defs" |
| 158 | + {:doc "Return an alist of definitions currently thought to be instrumented on each namespace. Due to Clojure's versatility, this could include false postives, but there will not be false negatives. Instrumentations inside protocols are not listed." |
| 159 | + :returns {"status" "done" |
| 160 | + "list" "The alist of (NAMESPACE . VARS) that are thought to be instrumented."}} |
| 161 | + "debug-middleware" |
| 162 | + {:doc "Debug a code form or fall back on regular eval." |
| 163 | + :requires {"id" "A message id that will be responded to when a breakpoint is reached." |
| 164 | + "code" "Code to debug, there must be a #dbg or a #break reader macro in it, or nothing will happen." |
| 165 | + "file" "File where the code is located." |
| 166 | + "ns" "Passed to \"eval\"." |
| 167 | + "point" "Position in the file where the provided code begins."} |
| 168 | + :returns {"status" "\"done\" if the message will no longer be used, or \"need-debug-input\" during debugging sessions"}}}})) |
| 169 | + |
| 170 | +(def-wrapper wrap-enlighten cider.nrepl.middleware.enlighten/handle-enlighten |
| 171 | + :enlighten |
| 172 | + {:expects #{"eval" #'wrap-debug}}) |
| 173 | + |
127 | 174 | (def-wrapper wrap-format cider.nrepl.middleware.format/handle-format
|
128 | 175 | {:doc "Middleware providing support for formatting Clojure code and EDN data."
|
129 |
| - :requires #{#'pprint/wrap-pprint-fn} |
| 176 | + :requires #{#'wrap-pprint-fn} |
130 | 177 | :handles {"format-code"
|
131 | 178 | {:doc "Reformats the given Clojure code, returning the result as a string."
|
132 | 179 | :requires {"code" "The code to format."}
|
|
249 | 296 |
|
250 | 297 | (def-wrapper wrap-refresh cider.nrepl.middleware.refresh/handle-refresh
|
251 | 298 | {:doc "Refresh middleware."
|
252 |
| - :requires #{"clone" #'pprint/wrap-pprint-fn} |
| 299 | + :requires #{"clone" #'wrap-pprint-fn} |
253 | 300 | :handles {"refresh"
|
254 | 301 | {:doc "Reloads all changed files in dependency order."
|
255 |
| - :optional (merge pprint/wrap-pprint-fn-optional-arguments |
| 302 | + :optional (merge wrap-pprint-fn-optional-arguments |
256 | 303 | {"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath."
|
257 | 304 | "before" "The namespace-qualified name of a zero-arity function to call before reloading."
|
258 | 305 | "after" "The namespace-qualified name of a zero-arity function to call after reloading."})
|
|
262 | 309 | "error-ns" "The namespace that caused reloading to fail when `status` is `:error`."}}
|
263 | 310 | "refresh-all"
|
264 | 311 | {:doc "Reloads all files in dependency order."
|
265 |
| - :optional (merge pprint/wrap-pprint-fn-optional-arguments |
| 312 | + :optional (merge wrap-pprint-fn-optional-arguments |
266 | 313 | {"dirs" "List of directories to scan. If no directories given, defaults to all directories on the classpath."
|
267 | 314 | "before" "The namespace-qualified name of a zero-arity function to call before reloading."
|
268 | 315 | "after" "The namespace-qualified name of a zero-arity function to call after reloading."})
|
|
305 | 352 | (cljs/requires-piggieback
|
306 | 353 | {:doc "Middleware that handles stacktrace requests, sending
|
307 | 354 | cause and stack frame info for the most recent exception."
|
308 |
| - :requires #{#'session #'pprint/wrap-pprint-fn} |
| 355 | + :requires #{#'session #'wrap-pprint-fn} |
309 | 356 | :expects #{}
|
310 | 357 | :handles {"stacktrace" {:doc "Return messages describing each cause and stack frame of the most recent exception."
|
311 |
| - :optional pprint/wrap-pprint-fn-optional-arguments |
| 358 | + :optional wrap-pprint-fn-optional-arguments |
312 | 359 | :returns {"status" "\"done\", or \"no-error\" if `*e` is nil"}}}}))
|
313 | 360 |
|
314 | 361 | (def-wrapper wrap-test cider.nrepl.middleware.test/handle-test
|
315 | 362 | {:doc "Middleware that handles testing requests."
|
316 |
| - :requires #{#'session #'pprint/wrap-pprint-fn} |
| 363 | + :requires #{#'session #'wrap-pprint-fn} |
317 | 364 | :expects #{#'pr-values}
|
318 | 365 | :handles {"test"
|
319 | 366 | {:doc "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."
|
320 |
| - :optional pprint/wrap-pprint-fn-optional-arguments} |
| 367 | + :optional wrap-pprint-fn-optional-arguments} |
321 | 368 | "test-all"
|
322 | 369 | {:doc "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."
|
323 |
| - :optional pprint/wrap-pprint-fn-optional-arguments} |
| 370 | + :optional wrap-pprint-fn-optional-arguments} |
324 | 371 | "test-stacktrace"
|
325 | 372 | {: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."
|
326 |
| - :optional pprint/wrap-pprint-fn-optional-arguments} |
| 373 | + :optional wrap-pprint-fn-optional-arguments} |
327 | 374 | "retest"
|
328 | 375 | {: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."
|
329 |
| - :optional pprint/wrap-pprint-fn-optional-arguments}}}) |
| 376 | + :optional wrap-pprint-fn-optional-arguments}}}) |
330 | 377 |
|
331 | 378 | (def-wrapper wrap-trace cider.nrepl.middleware.trace/handle-trace
|
332 | 379 | {:doc "Toggle tracing of a given var."
|
|
365 | 412 | "ns" "The current namespace"}
|
366 | 413 | :returns {"status" "done"}}}})
|
367 | 414 |
|
| 415 | +(def-wrapper wrap-version cider.nrepl.middleware.version/handle-version |
| 416 | + {:doc "Provides CIDER-nREPL version information." |
| 417 | + :describe-fn #'version/cider-version-reply ;; For the "describe" op. Merged into `:aux`. |
| 418 | + :handles |
| 419 | + {"cider-version" |
| 420 | + {:doc "Returns the version of the CIDER-nREPL middleware." |
| 421 | + :requires {} |
| 422 | + :returns {"cider-version" "CIDER-nREPL's version map." |
| 423 | + "status" "done"}}}}) |
| 424 | + |
368 | 425 |
|
369 | 426 | ;;; Cider's Handler
|
370 | 427 |
|
|
381 | 438 | wrap-macroexpand
|
382 | 439 | wrap-ns
|
383 | 440 | wrap-out
|
| 441 | + wrap-pprint |
| 442 | + wrap-pprint-fn |
384 | 443 | wrap-refresh
|
385 | 444 | wrap-resource
|
386 | 445 | wrap-spec
|
|
389 | 448 | wrap-trace
|
390 | 449 | wrap-tracker
|
391 | 450 | wrap-undef
|
392 |
| - cider.nrepl.middleware.pprint/wrap-pprint |
393 |
| - cider.nrepl.middleware.pprint/wrap-pprint-fn |
394 |
| - cider.nrepl.middleware.version/wrap-version]) |
| 451 | + wrap-version]) |
395 | 452 |
|
396 | 453 | (def cider-nrepl-handler
|
397 | 454 | "CIDER's nREPL handler."
|
|
0 commit comments