Skip to content

Commit 855a7f4

Browse files
grammatibbatsov
authored andcommitted
Fix force-step operations in the debugger (#1679)
Two operations, `:here` and `:out` currently support a `force?` parameter, which causes the debugger to skip breakpoints in other instrumented functions until reaching the specified point. They are bound to uppercase letters, `H` and `O` respectively. Neither was working previously, because the `force?` parameter was not being sent (in the case of `:here`), or was being sent incorrectly (in the case of `:out`).
1 parent 722db8c commit 855a7f4

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

cider-debug.el

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ In order to work properly, this mode must be activated by
343343
(when nrepl-ongoing-sync-request
344344
(ignore-errors (exit-recursive-edit)))))
345345

346+
;;; Bind the `:here` command to both h and H, because it behaves differently if
347+
;;; invoked with an uppercase letter.
346348
(define-key cider--debug-mode-map "h" #'cider-debug-move-here)
349+
(define-key cider--debug-mode-map "H" #'cider-debug-move-here)
347350

348351
(defun cider--debug-remove-overlays (&optional buffer)
349352
"Remove CIDER debug overlays from BUFFER if variable `cider--debug-mode' is nil."
@@ -383,6 +386,12 @@ In order to work properly, this mode must be activated by
383386
["List locals" cider-debug-toggle-locals :style toggle :selected cider-debug-display-locals])
384387
["Customize" (customize-group 'cider-debug)]))
385388

389+
(defun cider--uppercase-command-p ()
390+
"Return true if the last command was uppercase letter."
391+
(ignore-errors
392+
(let ((case-fold-search nil))
393+
(string-match "[[:upper:]]" (string last-command-event)))))
394+
386395
(defun cider-debug-mode-send-reply (command &optional key force)
387396
"Reply to the message that started current bufer's debugging session.
388397
COMMAND is sent as the input option. KEY can be provided to reply to a
@@ -395,17 +404,15 @@ message."
395404
(nrepl-dict-get cider--debug-mode-commands-dict
396405
(downcase (string last-command-event)))))
397406
nil
398-
(ignore-errors
399-
(let ((case-fold-search nil))
400-
(string-match "[[:upper:]]" (string last-command-event))))))
407+
(cider--uppercase-command-p)))
401408
(unless (or (string-prefix-p ":" command)
402409
(string-prefix-p "{" command))
403410
(setq command (concat ":" command)))
411+
(when (and (string-prefix-p ":" command) force)
412+
(setq command (format "{:response %s :force? true}" command)))
404413
(cider-nrepl-send-unhandled-request
405-
(append (list "op" "debug-input" "input" (or command ":quit")
406-
"key" (or key (nrepl-dict-get cider--debug-mode-response "key")))
407-
(when force
408-
'("force?" "true"))))
414+
(list "op" "debug-input" "input" (or command ":quit")
415+
"key" (or key (nrepl-dict-get cider--debug-mode-response "key"))))
409416
(ignore-errors (cider--debug-mode -1)))
410417

411418
(defun cider--debug-quit ()
@@ -693,9 +700,9 @@ TARGET is inside it. The returned list is suitable for use in
693700
;; `unwind-protect' clause.
694701
(goto-char starting-point)))))
695702

696-
(defun cider-debug-move-here ()
703+
(defun cider-debug-move-here (&optional force)
697704
"Skip any breakpoints up to point."
698-
(interactive)
705+
(interactive (list (cider--uppercase-command-p)))
699706
(unless cider--debug-mode
700707
(user-error "`cider-debug-move-here' only makes sense during a debug session"))
701708
(let ((here (point)))
@@ -716,8 +723,9 @@ TARGET is inside it. The returned list is suitable for use in
716723
(comment-forward (point-max))
717724
;; Find the coordinate and send it.
718725
(cider-debug-mode-send-reply
719-
(format "{:response :here, :coord %s}"
720-
(cider--debug-find-coordinates-for-point here))))))
726+
(format "{:response :here, :coord %s :force? %s}"
727+
(cider--debug-find-coordinates-for-point here)
728+
(if force "true" "false"))))))
721729

722730

723731
;;; User commands

0 commit comments

Comments
 (0)