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

Add inspect-def-current-value to inspect middleware #653

Merged
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
6 changes: 6 additions & 0 deletions src/cider/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@
"inspect-clear"
{:doc "Clears the state state of the inspector."
:requires {"session" "The current session"}
:returns {"status" "\"done\""}}
"inspect-def-current-value"
{:doc "Define the currently inspected value as a var with the given var-name in the provided namespace."
:requires {"session" "The current session"
"ns" "Namespace to define var on"
"var-name" "The var name"}
:returns {"status" "\"done\""}}}}))

(def-wrapper wrap-macroexpand cider.nrepl.middleware.macroexpand/handle-macroexpand
Expand Down
6 changes: 5 additions & 1 deletion src/cider/nrepl/middleware/inspect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
(defn clear-reply [msg]
(inspector-response msg (swap-inspector! msg (constantly (inspect/fresh)))))

(defn def-current-value [msg]
(inspector-response msg (swap-inspector! msg inspect/def-current-value (symbol (:ns msg)) (:var-name msg))))

(defn handle-inspect [handler msg]
(if (= (:op msg) "eval")
(eval-reply handler msg)
Expand All @@ -99,4 +102,5 @@
"inspect-next-page" next-page-reply
"inspect-prev-page" prev-page-reply
"inspect-set-page-size" set-page-size-reply
"inspect-clear" clear-reply)))
"inspect-clear" clear-reply
"inspect-def-current-value" def-current-value)))
17 changes: 17 additions & 0 deletions test/clj/cider/nrepl/middleware/inspect_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,20 @@
(first (:value (session/message {:op "eval"
:inspect "true"
:code "(range 100)"}))))))))

(deftest inspect-def-current-value-test
(testing "inspect-def-current-value defines a var with the current inspector value"
(is (= "{3 4}"
(first (:value (do
(session/message {:op "eval"
:code "(def test-val [{1 2} {3 4}])"})
(session/message {:op "eval"
:inspect "true"
:code "test-val"})
(session/message {:op "inspect-push"
:idx 2})
(session/message {:op "inspect-def-current-value"
:ns "user"
:var-name "sub-map"})
(session/message {:op "eval"
:code "sub-map"}))))))))