Skip to content

Commit 1f63373

Browse files
grammatibbatsov
authored andcommitted
Debugger: step-in (#1660)
This is the front-end part of step-in for the debugger. See: clojure-emacs/cider-nrepl#335 There are two changes here: - Attempt to find the source file when debugging, rather than popping up a debug buffer. This is because with step-in, we can no longer assume that functions being debugged have been opened and manually instrumented by the user - Expect the list of debugger commands, which is sent as `input-type`, to be an nrepl-dict mapping keys to commands, rather than a list of commands.
1 parent 7f5464a commit 1f63373

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features
66

7+
* Debugger now supports step-in.
78
* Improve CIDER's menu-bar menu:
89
- Thoroughly reorganize it and split it into 3 separate menus;
910
- Add custom-written `:help` strings to some items, and automatically add help strings to the rest;

cider-debug.el

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ This variable must be set before starting the repl connection."
185185

186186

187187
;;; Minor mode
188-
(defvar-local cider--debug-mode-commands-alist nil
189-
"Alist from keys to debug commands.
188+
(defvar-local cider--debug-mode-commands-dict nil
189+
"An nrepl-dict from keys to debug commands.
190190
Autogenerated by `cider--turn-on-debug-mode'.")
191191

192192
(defvar-local cider--debug-mode-response nil
@@ -214,16 +214,18 @@ Each element of LOCALS should be a list of at least two elements."
214214
locals ""))
215215
""))
216216

217-
(defun cider--debug-prompt (command-list)
218-
"Return prompt to display for COMMAND-LIST."
217+
(defun cider--debug-prompt (command-dict)
218+
"Return prompt to display for COMMAND-DICT."
219219
;; Force `default' face, otherwise the overlay "inherits" the face of the text
220220
;; after it.
221-
(format (propertize "%s" 'face 'default)
222-
(concat
223-
(mapconcat (lambda (x) (put-text-property 0 1 'face 'cider-debug-prompt-face x) x)
224-
command-list
225-
" ")
226-
"\n")))
221+
(format (propertize "%s\n" 'face 'default)
222+
(cider-string-join
223+
(nrepl-dict-map (lambda (char cmd)
224+
(when-let ((pos (cl-search char cmd)))
225+
(put-text-property pos (1+ pos) 'face 'cider-debug-prompt-face cmd))
226+
cmd)
227+
command-dict)
228+
" ")))
227229

228230
(defvar-local cider--debug-prompt-overlay nil)
229231

@@ -299,10 +301,6 @@ In order to work properly, this mode must be activated by
299301
;; A debug session is an ongoing eval, but it's annoying to have the
300302
;; spinner spinning while you debug.
301303
(when spinner-current (spinner-stop))
302-
;; `inspect' would conflict with `inject', so there's no key for it.
303-
(setq input-type (seq-difference input-type '("inspect")))
304-
(nrepl-dict-put cider--debug-mode-response "input-type" input-type)
305-
306304
(setq-local tool-bar-map cider--debug-mode-tool-bar-map)
307305
(add-hook 'kill-buffer-hook #'cider--debug-quit nil 'local)
308306
(add-hook 'before-revert-hook #'cider--debug-quit nil 'local)
@@ -313,13 +311,13 @@ In order to work properly, this mode must be activated by
313311
(apply-partially #'cider--debug-lexical-eval
314312
(nrepl-dict-get cider--debug-mode-response "key")))
315313
;; Set the keymap.
316-
(let ((alist (mapcar (lambda (k) (cons (string-to-char k) (concat ":" k)))
317-
;; `here' needs a special command.
318-
(seq-difference input-type '("here")))))
319-
(setq cider--debug-mode-commands-alist alist)
320-
(dolist (it alist)
321-
(define-key cider--debug-mode-map (vector (upcase (car it))) #'cider-debug-mode-send-reply)
322-
(define-key cider--debug-mode-map (vector (car it)) #'cider-debug-mode-send-reply)))
314+
(nrepl-dict-map (lambda (char cmd)
315+
(unless (string= char "h") ; `here' needs a special command.
316+
(define-key cider--debug-mode-map char #'cider-debug-mode-send-reply))
317+
(when (string= char "o")
318+
(define-key cider--debug-mode-map (upcase char) #'cider-debug-mode-send-reply)))
319+
input-type)
320+
(setq cider--debug-mode-commands-dict input-type)
323321
;; Show the prompt.
324322
(cider--debug-mode-redisplay)
325323
;; If a sync request is ongoing, the user can't act normally to
@@ -331,7 +329,7 @@ In order to work properly, this mode must be activated by
331329
(user-error (substitute-command-keys "Don't call this mode manually, use `\\[universal-argument] \\[cider-eval-defun-at-point]' instead"))
332330
(error "Attempt to activate `cider--debug-mode' without setting `cider--debug-mode-response' first")))
333331
(setq cider-interactive-eval-override nil)
334-
(setq cider--debug-mode-commands-alist nil)
332+
(setq cider--debug-mode-commands-dict nil)
335333
(setq cider--debug-mode-response nil)
336334
;; We wait a moment before clearing overlays and the read-onlyness, so that
337335
;; cider-nrepl has a chance to send the next message, and so that the user
@@ -394,12 +392,15 @@ message."
394392
(if (symbolp last-command-event)
395393
(symbol-name last-command-event)
396394
(ignore-errors
397-
(cdr (assq (downcase last-command-event)
398-
cider--debug-mode-commands-alist))))
395+
(nrepl-dict-get cider--debug-mode-commands-dict
396+
(downcase (string last-command-event)))))
399397
nil
400398
(ignore-errors
401399
(let ((case-fold-search nil))
402400
(string-match "[[:upper:]]" (string last-command-event))))))
401+
(unless (or (string-prefix-p ":" command)
402+
(string-prefix-p "{" command))
403+
(setq command (concat ":" command)))
403404
(cider-nrepl-send-unhandled-request
404405
(append (list "op" "debug-input" "input" (or command ":quit")
405406
"key" (or key (nrepl-dict-get cider--debug-mode-response "key")))
@@ -566,10 +567,12 @@ is a coordinate measure in sexps."
566567
(let ((out))
567568
;; We prefer in-source debugging.
568569
(when-let ((buf (and file line column
569-
(find-buffer-visiting file))))
570+
(ignore-errors
571+
(cider--jump-to-loc-from-info response)
572+
(current-buffer)))))
570573
;; The logic here makes it hard to use `with-current-buffer'.
571574
(with-current-buffer buf
572-
;; This is for retoring point inside buf.
575+
;; This is for restoring point inside buf.
573576
(save-excursion
574577
;; Get to the proper line & column in the file
575578
(forward-line (- line (line-number-at-pos)))

test/cider-tests.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
(ert-deftest test-debug-prompt ()
4141
(should (equal-including-properties
42-
(cider--debug-prompt '("a" "b" "c"))
42+
(cider--debug-prompt (nrepl-dict "a" "a" "b" "b" "c" "c"))
4343
#("a b c\n"
4444
0 1 (face cider-debug-prompt-face)
4545
1 2 (face default)
@@ -48,14 +48,14 @@
4848
4 5 (face cider-debug-prompt-face)
4949
5 6 (face default))))
5050
(should (equal-including-properties
51-
(cider--debug-prompt '("a" "bc"))
52-
#("a bc\n"
51+
(cider--debug-prompt (nrepl-dict "a" "abc" "b" "cba"))
52+
#("abc cba\n"
5353
0 1 (face cider-debug-prompt-face)
54-
1 2 (face default)
55-
2 3 (face cider-debug-prompt-face)
56-
3 5 (face default))))
54+
1 5 (face default)
55+
5 6 (face cider-debug-prompt-face)
56+
6 8 (face default))))
5757
(should (equal-including-properties
58-
(cider--debug-prompt '("abc"))
58+
(cider--debug-prompt (nrepl-dict "a" "abc"))
5959
#("abc\n" 0 1 (face cider-debug-prompt-face) 1 4 (face default)))))
6060

6161
(ert-deftest test-debug-move-point ()

0 commit comments

Comments
 (0)