From 2c24aaae2219689c05e7165a9b7b3acdbecae21d Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Sun, 25 Oct 2015 10:26:46 +0200 Subject: [PATCH] [Fix #1330] Leverage the source-tracking mechanism introduced in nREPL 0.2.11 This works only for Clojure right now. --- CHANGELOG.md | 1 + README.md | 12 ++++++------ cider-client.el | 9 +++++---- cider-interaction.el | 5 +++-- cider-mode.el | 0 cider-util.el | 4 ++++ nrepl-client.el | 21 +++++++++++---------- 7 files changed, 30 insertions(+), 22 deletions(-) mode change 100755 => 100644 cider-mode.el diff --git a/CHANGELOG.md b/CHANGELOG.md index 476b9b746..43d37e55d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 99764193c..ffddbe630 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cider-client.el b/cider-client.el index 84331b09a..c525fee64 100644 --- a/cider-client.el +++ b/cider-client.el @@ -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. diff --git a/cider-interaction.el b/cider-interaction.el index a07b20c6b..672ffcda5 100644 --- a/cider-interaction.el +++ b/cider-interaction.el @@ -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 @@ -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. diff --git a/cider-mode.el b/cider-mode.el old mode 100755 new mode 100644 diff --git a/cider-util.el b/cider-util.el index c448fabba..dc90789d3 100644 --- a/cider-util.el +++ b/cider-util.el @@ -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 diff --git a/nrepl-client.el b/nrepl-client.el index 88373b22c..e58001716 100644 --- a/nrepl-client.el +++ b/nrepl-client.el @@ -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))