Skip to content
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
34 changes: 22 additions & 12 deletions src/cider/nrepl/middleware/debug.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
[clojure.tools.nrepl.misc :refer [response-for]]
[cider.nrepl.middleware.util.instrument :refer [instrument]]
[debugger.time :as t]
[debugger.config :as c]
[debugger.core :refer [break]]))

;;;; ## Interaction with the client
Expand All @@ -28,18 +30,26 @@
"Send value and coordinates to the client through the debug channel.
Sends a response to the message stored in debugger-message."
[value extras]
;; Notify cider that a (break) is incoming, along with the value of
;; the instrumented sexp and instructions on how to find it in the
;; code.
(transport/send
(:transport @debugger-message)
(response-for @debugger-message
(assoc extras
:debug-value (pr-str value)
:breakfunction nil)))
;; Send the actual break.
(binding [*out* (new java.io.StringWriter)]
(break value)))
;; If the user has recently replied (quit) to a `break` statement,
;; then debugger will not ask for input. Therefore, have to avoid
;; sending the following message in these cases.
(if (->> (t/now) (t/interval @c/*last-quit-at*) t/in-seconds (< c/*skip-repl-if-last-quit-ago*))
;; TODO: If clj-debugger makes the `read` call in `read-fn`
;; configurable (perhaps with a dynamic variable) we would have to
;; divide our breakpoint into two messages.
(do (transport/send
(:transport @debugger-message)
(response-for @debugger-message
(assoc extras
:debug-value (pr-str value)
:breakfunction nil)))
;; Send the actual break.
(binding [*out* (new java.io.StringWriter)]
(break value)))
;; Notify cider that a (break) is incoming, along with the value
;; of the instrumented sexp and instructions on how to find it in
;; the code.
value))

(defn instrument-and-eval
"Instrument form and evaluate the result.
Expand Down
10 changes: 10 additions & 0 deletions test/cider/nrepl/middleware/debug_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns cider.nrepl.middleware.debug-test
(:require [clojure.test :refer :all]
[debugger.time :as t]
[debugger.config :as c]
[cider.nrepl.middleware.debug :as d]))

(deftest breakpoint
(reset! c/*last-quit-at* (t/now))
(is (= (d/breakpoint 10 {}) 10)))