Skip to content

Commit

Permalink
[Fix clojure-emacs#597] Don't process incomplete messages unless sure
Browse files Browse the repository at this point in the history
  Probably also fixes the related clojure-emacs#583 and clojure-emacs#586.
  • Loading branch information
vspinu committed Jun 11, 2014
1 parent e6bfe3b commit 90cecbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ for presenting fontified documentation, including Javadoc.
* `cider-select` can now switch to the `*cider-error*` buffer (bound to `x`).

### Changes

* [#597](https://github.com/clojure-emacs/cider/issues/597) Don't process nREPL
messages unless the whole message has been received.
* [#603](https://github.com/clojure-emacs/cider/pull/603) New variable
`cider-show-error-buffer` to control the behavior of the error buffer. Obsoletes
`cider-popup-on-error`, `cider-popup-stacktraces` and
Expand Down
19 changes: 13 additions & 6 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ could be received even for requests with status \"done\"."
(funcall callback response)
(nrepl-default-handler response)))))

(defun nrepl-net-decode ()
(defun nrepl-decode-current-buffer ()
"Decode the data in the current buffer.
Remove the processed data from the buffer if the decode successful."
(let* ((start (point-min))
Expand All @@ -323,24 +323,31 @@ Remove the processed data from the buffer if the decode successful."
(nrepl-decode data)
(delete-region start end))))

(defun nrepl-net-process-input (process)
(defun nrepl-handle-process-output (process)
"Handle all complete messages from PROCESS.
Assume that any error during decoding indicates an incomplete message."
(with-current-buffer (process-buffer process)
(let ((nrepl-connection-dispatch (current-buffer)))
;; TODO: Implement fine-grained error handling
(with-demoted-errors
(while (> (buffer-size) 1)
(let ((responses (nrepl-net-decode)))
(dolist (response responses)
(nrepl-dispatch response))))))))
(let ((responses (nrepl-decode-current-buffer)))
(dolist (r responses)
(nrepl-dispatch r))))))))

(defvar nrepl-output-timeout 0.01
"Seconds to wait before decoding nREPL output.")

(defun nrepl-net-filter (process string)
"Decode the message(s) from PROCESS contained in STRING and dispatch."
(with-current-buffer (process-buffer process)
(goto-char (point-max))
(insert string))
(nrepl-net-process-input process))
;; end of the dict maybe?
(when (eq ?e (aref string (1- (length string))))
;; wait a bit to make sure we are at the real end
(unless (accept-process-output process nrepl-output-timeout)
(nrepl-handle-process-output process))))

(defun nrepl-sentinel (process message)
"Handle sentinel events from PROCESS.
Expand Down

0 comments on commit 90cecbd

Please sign in to comment.