Skip to content

Commit

Permalink
Add inspect-def-current-value to inspect middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas authored and bbatsov committed Oct 16, 2019
1 parent c305995 commit 9ceee6c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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"}))))))))

0 comments on commit 9ceee6c

Please sign in to comment.