cider-nrepl
cider-nrepl copied to clipboard
Debugger incorrectly steps through conditional forms
Once #435 is in, try
#dbg
(defn tt [a]
(let [b (+ a 1)]
#?(:clj (do
(loop [b b]
(if (pos? b)
(recur (- b 1))
(println "clj"))))
:cljs (println "cljs"))))
(tt 2)
The debugger within :clj
form breaks almost immediately.
@FiV0 You might consider taking a stab at this one as well.
@bbatsov Had seen it. You can assign it to me if you want.
@bbatsov @vspinu For this one I need some pointers/help. Consider the following code
#dbg
#?(:cljs (+ 1 2) :clj (inc (inc 1)))
In the maybe-debug
function
https://github.com/clojure-emacs/cider-nrepl/blob/f71b851a248ac95217b17f409ff7ab7669acd402/src/cider/nrepl/middleware/debug.clj#L612-L617
the code is still in string form, so something like "#dbg\n#?(....)". Once the evaluation gets to instrument-and-eval
https://github.com/clojure-emacs/cider-nrepl/blob/f71b851a248ac95217b17f409ff7ab7669acd402/src/cider/nrepl/middleware/debug.clj#L594-L597
the code has been "read" as clojure data and the form is just (inc (inc 1))
, so somewhere in between some reading seems to happen. I am assuming this happens in some lower handler in the nrepl. Is that correct? Essentially when reading such a form we need to do something like (read-string {:read-cond :preserve} "#dbg\n#?(....)")
as otherwise the bookkeeping of where stuff is located fails.
Maybe it's this line?
https://github.com/nrepl/nrepl/blob/1cc9baae631703c184894559a2232275dc50dff6/src/clojure/nrepl/middleware/interruptible_eval.clj#L110-L111
Yeah, I think that's the line. nREPL basically just delegates to Clojure's own REPL, so it wouldn't have to reimplement its functionality.
@bbatsov You think it would be ok to add an option to nrepl so that code is read with :preserve
. We could then do a first read via nrepl, locate stuff corretly in cider-nrepl
, do a second read
also in cider-nrepl
and then do stuff as usual. I don't see how to solve this one otherwise.
Probably that'd be fine. What exactly does :preserve
do? If it doesn't affect the evaluation then we can safely enable it.