Skip to content

Commit

Permalink
[Fix #1330] Leverage the source-tracking mechanism introduced in nREP…
Browse files Browse the repository at this point in the history
…L 0.2.11

This works only for Clojure right now.
  • Loading branch information
bbatsov committed Oct 25, 2015
1 parent 3f771a2 commit 2c24aaa
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* [#1239](https://github.com/clojure-emacs/cider/issues/1239): New defcustom `cider-refresh-show-log-buffer`, controls the behaviour of the `*cider-refresh-log*` buffer when calling `cider-refresh`. When set to nil (the default), the log buffer will still be written to, but not displayed automatically. Instead, the most relevant information will be displayed in the echo area. When set to non-nil, the log buffer will be displayed every time `cider-refresh` is called.
* [#1328](https://github.com/clojure-emacs/cider/issues/1328): Auto-scroll the `*nrepl-server*` buffer on new output.
* [#1300](https://github.com/clojure-emacs/cider/issues/1300): Add the ability to replicate an existing connection with `cider-replicate-connection`.
* [#1330](https://github.com/clojure-emacs/cider/issues/1330): Leverage nREPL 0.2.11's source-tracking feature.

### Changes

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1253,15 +1253,15 @@ try to debug an expression (e.g., with `C-u
C-M-x`). [File an issue](https://github.com/clojure-emacs/cider-repl/issues/new)
and copy this information.

### Warning saying you have to use nREPL 0.2.7+
### Warning saying you have to use nREPL 0.2.11+

CIDER currently requires at least nREPL 0.2.7 to work properly (there were some
nasty bugs in 0.2.6). Unfortunately `leiningen` 2.5.1 (and older) pulls in exactly
0.2.6, so you if you're a lein user you'll have to upgrade to 2.5.2+. Alternatively,
you can add this to your `profiles.clj`:
CIDER currently requires at least nREPL 0.2.11 to work properly (there were some
nasty bugs in older version and no support tracking where some var was defined
in the source code). Leiningen users can add this to their `profiles.clj` to
force the proper dependency:

```clojure
{:user {:dependencies [[org.clojure/tools.nrepl "0.2.10"]]}}
{:user {:dependencies [[org.clojure/tools.nrepl "0.2.11"]]}}
```

Make sure you add the newer nREPL dependency to the `:dependencies` key instead
Expand Down
9 changes: 5 additions & 4 deletions cider-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,17 @@ Return the id of the sent message."
(nrepl--mark-id-completed id))
id))

(defun cider-nrepl-request:eval (input callback &optional ns point)
(defun cider-nrepl-request:eval (input callback &optional ns line column)
"Send the request INPUT and register the CALLBACK as the response handler.
If NS is non-nil, include it in the request. POINT, if non-nil, is the
position of INPUT in its buffer."
If NS is non-nil, include it in the request. LINE and COLUMN, if non-nil, define
the position of INPUT in its buffer."
(nrepl-request:eval input
callback
(cider-current-connection)
(cider-current-session)
ns
point))
line
column))

(defun cider-nrepl-sync-request:eval (input &optional ns)
"Send the INPUT to the nREPL server synchronously.
Expand Down
5 changes: 3 additions & 2 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace-qualified function of zero arity."
All of them are provided by CIDER's nREPL middleware (cider-nrepl).")

(defvar cider-required-nrepl-version "0.2.7"
(defvar cider-required-nrepl-version "0.2.11"
"The minimum nREPL version that's known to work properly with CIDER.")

;;; Minibuffer
Expand Down Expand Up @@ -1008,7 +1008,8 @@ arguments and only proceed with evaluation if it returns nil."
;; always eval ns forms in the user namespace
;; otherwise trying to eval ns form for the first time will produce an error
(if (cider-ns-form-p form) "user" (cider-current-ns))
start))))
(line-number-at-pos start)
(cider-column-number-at-pos start)))))

(defun cider-interactive-pprint-eval (form &optional callback right-margin)
"Evaluate FORM and dispatch the response to CALLBACK.
Expand Down
Empty file modified cider-mode.el
100755 → 100644
Empty file.
4 changes: 4 additions & 0 deletions cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ Any other value is just returned."
(eval (nth (random (length cider-words-of-inspiration))
cider-words-of-inspiration)))

(defun cider-column-number-at-pos (pos)
"Analog to `line-number-at-pos'."
(save-excursion (goto-char pos) (current-column)))

(provide 'cider-util)

;;; cider-util.el ends here
21 changes: 11 additions & 10 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -972,25 +972,26 @@ Register CALLBACK as the response handler."
callback
connection))

(defun nrepl--eval-request (input session &optional ns point)
(defun nrepl--eval-request (input session &optional ns line column)
"Prepare :eval request message for INPUT.
SESSION and NS provide context for the request.
If POINT is non-nil and current buffer is a file buffer, \"point\" and
\"file\" are added to the message."
If LINE and COLUMN are non-nil and current buffer is a file buffer, \"line\",
\"column\" and \"file\" are added to the message."
(append (and ns (list "ns" ns))
(list "op" "eval"
"session" session
"code" input)
(when (and point (buffer-file-name))
(when (and line column (buffer-file-name))
(list "file" (buffer-file-name)
"point" point))))
"line" line
"column" column))))

(defun nrepl-request:eval (input callback connection session &optional ns point)
(defun nrepl-request:eval (input callback connection session &optional ns line column)
"Send the request INPUT and register the CALLBACK as the response handler.
The request is dispatched via CONNECTION and SESSION.
If NS is non-nil, include it in the request. POINT, if non-nil, is the
position of INPUT in its buffer."
(nrepl-send-request (nrepl--eval-request input session ns point)
The request is dispatched via CONNECTION and SESSION. If NS is non-nil,
include it in the request. LINE and COLUMN, if non-nil, define the position
of INPUT in its buffer."
(nrepl-send-request (nrepl--eval-request input session ns line column)
callback
connection))

Expand Down

0 comments on commit 2c24aaa

Please sign in to comment.