Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display debug-on-exception messages #3366

Merged
merged 3 commits into from
Mar 25, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

- [#3366](https://github.com/clojure-emacs/cider/pull/3366): Support display of error overlays with #dbg! and #break! reader macros.
- [#3622](https://github.com/clojure-emacs/cider/pull/3461): Basic support for using CIDER from [clojure-ts-mode](https://github.com/clojure-emacs/clojure-ts-mode).
- The `clojure-mode` dependency is still required for CIDER to function.
- Some features like `cider-dynamic-indentation` and `cider-font-lock-dynamically` do not work with `clojure-ts-mode` (yet).
Expand Down
21 changes: 13 additions & 8 deletions cider-debug.el
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,16 @@ configure `cider-debug-prompt' instead."

(defun cider--debug-response-handler (response)
"Handles RESPONSE from the cider.debug middleware."
(nrepl-dbind-response response (status id causes)
(nrepl-dbind-response response (status id causes caught-msg)
(when (member "enlighten" status)
(cider--handle-enlighten response))
(when (or (member "eval-error" status)
(member "stack" status))
;; TODO: Make the error buffer a bit friendlier when we're just printing
;; the stack.
(cider--render-stacktrace-causes causes))
(if cider-show-error-buffer
(cider--render-stacktrace-causes causes)
(cider--debug-display-result-overlay nil caught-msg)))
(when (member "need-debug-input" status)
(cider--handle-debug response))
(when (member "done" status)
Expand All @@ -154,15 +156,18 @@ configure `cider-debug-prompt' instead."
#("." 0 1 (display (left-fringe right-triangle)))
"Used as an overlay's before-string prop to place a fringe arrow.")

(defun cider--debug-display-result-overlay (value)
"Place an overlay at point displaying VALUE."
(defun cider--debug-display-result-overlay (value caught)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to mention this in the docstring to make checkdoc happy.

"Place an overlay at point displaying VALUE.
When CAUGHT is non-nil, display it as an error message overlay."
(when cider-debug-use-overlays
;; This is cosmetic, let's ensure it doesn't break the session no matter what.
(ignore-errors
;; Result
(cider--make-result-overlay (cider-font-lock-as-clojure value)
(cider--make-result-overlay (or caught (cider-font-lock-as-clojure value))
:where (point-marker)
:type 'debug-result
:prepend-face (if caught 'cider-error-overlay-face
'cider-result-overlay-face)
'before-string cider--fringe-arrow-string)
;; Code
(cider--make-overlay (save-excursion (clojure-backward-logical-sexp 1) (point))
Expand Down Expand Up @@ -652,7 +657,7 @@ is a coordinate measure in sexps."
RESPONSE is a message received from the nrepl describing the input
needed. It is expected to contain at least \"key\", \"input-type\", and
\"prompt\", and possibly other entries depending on the input-type."
(nrepl-dbind-response response (debug-value key input-type prompt inspect)
(nrepl-dbind-response response (debug-value key input-type prompt inspect caught-msg)
(condition-case-unless-debug e
(progn
(pcase input-type
Expand All @@ -674,7 +679,7 @@ needed. It is expected to contain at least \"key\", \"input-type\", and
;; flicker even if we immediately recreate the overlays.
(cider--debug-remove-overlays)
(when cider-debug-use-overlays
(cider--debug-display-result-overlay debug-value))
(cider--debug-display-result-overlay debug-value caught-msg))
(setq cider--debug-mode-response response)
(cider--debug-mode 1)))
(when inspect
Expand Down Expand Up @@ -766,7 +771,7 @@ The boolean value of FORCE will be sent in the reply."
;; Is HERE inside the sexp being debugged?
(when (or (< here (point))
(save-excursion
(forward-sexp 1)
(clojure-forward-logical-sexp 1)
(> here (point))))
(user-error "Point is outside the sexp being debugged"))
;; Move forward until start of sexp.
Expand Down
Loading