|
(defun nrepl-make-response-handler (buffer value-handler stdout-handler |
|
stderr-handler done-handler |
|
&optional eval-error-handler |
|
content-type-handler |
|
truncated-handler) |
|
"Make a response handler for connection BUFFER. |
|
A handler is a function that takes one argument - response received from |
|
the server process. The response is an alist that contains at least `id' |
|
and `session' keys. Other standard response keys are `value', `out', `err', |
|
and `status'. |
|
|
|
The presence of a particular key determines the type of the response. For |
|
example, if `value' key is present, the response is of type `value', if |
|
`out' key is present the response is `stdout' etc. |
|
|
|
Depending on the type, the handler dispatches the appropriate value to one |
|
of the supplied handlers: VALUE-HANDLER, STDOUT-HANDLER, STDERR-HANDLER, |
|
DONE-HANDLER, EVAL-ERROR-HANDLER, CONTENT-TYPE-HANDLER, and |
|
TRUNCATED-HANDLER. |
|
|
|
Handlers are functions of the buffer and the value they handle, except for |
|
the optional CONTENT-TYPE-HANDLER which should be a function of the buffer, |
|
content, the content-type to be handled as a list `(type attrs)'. |
|
|
|
If the optional EVAL-ERROR-HANDLER is nil, the default `nrepl-err-handler' |
|
is used. If any of the other supplied handlers are nil nothing happens for |
|
the corresponding type of response." |
|
(lambda (response) |
|
(nrepl-dbind-response response (content-type content-transfer-encoding body |
|
value ns out err status id) |
|
(when (buffer-live-p buffer) |
|
(with-current-buffer buffer |
|
(when (and ns (not (cider-clojure-major-mode-p))) |
|
(cider-set-buffer-ns ns)))) |
|
(cond ((and content-type content-type-handler) |
|
(funcall content-type-handler buffer |
|
(if (string= content-transfer-encoding "base64") |
|
(base64-decode-string body) |
|
body) |
|
content-type)) |
|
(value |
|
(when value-handler |
|
(funcall value-handler buffer value))) |
|
(out |
|
(when stdout-handler |
|
(funcall stdout-handler buffer out))) |
|
(err |
|
(when stderr-handler |
|
(funcall stderr-handler buffer err))) |
|
(status |
|
(when (and truncated-handler (member "nrepl.middleware.print/truncated" status)) |
|
(let ((warning (format "\n... output truncated to %sB ..." |
|
(file-size-human-readable cider-print-quota)))) |
|
(funcall truncated-handler buffer warning))) |
|
(when (member "notification" status) |
|
(nrepl-dbind-response response (msg type) |
|
(nrepl-notify msg type))) |
|
(when (member "interrupted" status) |
|
(message "Evaluation interrupted.")) |
|
(when (member "eval-error" status) |
|
(funcall (or eval-error-handler nrepl-err-handler) buffer)) |
|
(when (member "namespace-not-found" status) |
|
(message "Namespace `%s' not found." ns)) |
|
(when (member "need-input" status) |
|
(cider-need-input buffer)) |
|
(when (member "done" status) |
|
(nrepl--mark-id-completed id) |
|
(when done-handler |
|
(funcall done-handler buffer)))))))) |
When connecting CIDER to a jank nREPL server, the REPL buffer opens without displaying the namespace prompt (e.g.
user>). The prompt only appears after pressing Enter.This appears to be related to how CIDER handles responses that include both
:valueand:status ("done")in the same message. Are"done"responses expected to be exclusive (i.e. not include other keys such as:value)?Expected behavior
The REPL prompt (e.g.
user>) should be displayed immediately after connecting and after each evaluation.Actual behavior
The REPL buffer opens without showing a prompt.
The prompt only appears after pressing Enter.
Evaluating expressions (e.g.
5) prints the result, but the prompt is still not shown until Enter is pressed again.Steps to reproduce the problem
Install jank:
https://book.jank-lang.org/getting-started/01-installation.html
Start the REPL:
Note the nREPL port:
In Emacs:
Create and open a file
scratch.jankEnable
clojure-modeRun:
Connect:
(use the port from step 2)
Observe the REPL buffer:
5-> result prints, but no prompt until Enter againAdditional context
From the nREPL message log, the final response includes both
:valueand:status:In CIDER’s response handler, it appears that
:valuetakes precedence over:status(due to acond), so the"done"handler, which is responsible for updating the REPL prompt, is not invoked when both keys are present in the same message:cider/lisp/nrepl-client.el
Lines 821 to 889 in f4a8bc4
Environment & Version information
CIDER version information
Lein / Clojure CLI version
jank 0.1-alpha
Emacs version
Operating system
any