Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erratic inspector behavior when multiple REPLs are connected #2454

Merged
merged 1 commit into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* Fix jack-in from inside of remote buffers.
* [#2408](https://github.com/clojure-emacs/cider/issues/2408): Auto-link to sesman session on `cider-find-var`.
* [#2454](https://github.com/clojure-emacs/cider/pull/2454): Fix erratic inspector behavior when multiple REPLs are connected

## 0.18.0 (2018-09-02)

Expand Down
20 changes: 13 additions & 7 deletions cider-inspector.el
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ This is used as an alternative to the built-in `last-command'. Whenever we
invoke any command through \\[execute-extended-command] and its variants,
the value of `last-command' is not set to the command it invokes.")

(defvar cider-inspector--current-repl nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should should probably be a buffer-local variable for the inspector buffers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong, but the inspector buffer is not retained between actions. At least, when I try to change a buffer-local variable, it is set back to nil once I do push/pop/whatever.

Copy link
Member

@bbatsov bbatsov Sep 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, well, this part of the codebase is pretty bad and needs a general cleanup. :-) I keep forgetting it's "special" compared to the rest of the code. No need for additional changes now, but generally we should be reusing the buffer most of the time instead of re-creating it all the time.

"Contains the reference to the REPL where inspector was last invoked from.
This is needed for internal inspector buffer operations (push,
pop) to execute against the correct REPL session.")

;; Operations
;;;###autoload
(defun cider-inspect-expr (expr ns)
Expand All @@ -142,6 +147,7 @@ Interactively, EXPR is read from the minibuffer, and NS the
current buffer's namespace."
(interactive (list (cider-read-from-minibuffer "Inspect expression: " (cider-sexp-at-point))
(cider-current-ns)))
(setq cider-inspector--current-repl (cider-current-repl))
(when-let* ((value (cider-sync-request:inspect-expr expr ns (or cider-inspector-page-size 32))))
(cider-inspector--render-value value)))

Expand Down Expand Up @@ -197,39 +203,39 @@ Current page will be reset to zero."
(defun cider-sync-request:inspect-pop ()
"Move one level up in the inspector stack."
(thread-first '("op" "inspect-pop")
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-push (idx)
"Inspect the inside value specified by IDX."
(thread-first `("op" "inspect-push"
"idx" ,idx)
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-refresh ()
"Re-render the currently inspected value."
(thread-first '("op" "inspect-refresh")
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-next-page ()
"Jump to the next page in paginated collection view."
(thread-first '("op" "inspect-next-page")
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-prev-page ()
"Jump to the previous page in paginated collection view."
(thread-first '("op" "inspect-prev-page")
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-set-page-size (page-size)
"Set the page size in paginated view to PAGE-SIZE."
(thread-first `("op" "inspect-set-page-size"
"page-size" ,page-size)
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-expr (expr ns page-size)
Expand All @@ -238,7 +244,7 @@ Set the page size in paginated view to PAGE-SIZE."
(thread-first (append (nrepl--eval-request expr ns)
`("inspect" "true"
"page-size" ,page-size))
(cider-nrepl-send-sync-request)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

;; Render Inspector from Structured Values
Expand Down