Skip to content

Commit ef805c8

Browse files
authored
Restore cider--display-interactive-eval-result overlays for compilation errors (#3492)
Fixes #3487
1 parent 0477ca0 commit ef805c8

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
- [#3331](https://github.com/clojure-emacs/cider/issues/3331): `cider-eval`: never jump to spurious locations, as sometimes conveyed by nREPL.
2929
- [#3112](https://github.com/clojure-emacs/cider/issues/3112): Fix the CIDER `xref-find-references` backend to return correct filenames.
3030
- [#3393](https://github.com/clojure-emacs/cider/issues/3393): recompute namespace info on each shadow-cljs recompilation or evaluation.
31-
- [#3402](https://github.com/clojure-emacs/cider/issues/3402): fix `cider-format-connection-params` edge case for Emacs 29.
31+
- [#3402](https://github.com/clojure-emacs/cider/issues/3402): Fix `cider-format-connection-params` edge case for Emacs 29.
3232
- [#3393](https://github.com/clojure-emacs/cider/issues/3393): Recompute namespace info on each shadow-cljs recompilation or evaluation.
3333
- Recompute namespace info on each fighweel-main recompilation.
34-
- [#3250](https://github.com/clojure-emacs/cider/issues/3250): don't lose the CIDER session over TRAMP files.
34+
- [#3250](https://github.com/clojure-emacs/cider/issues/3250): Don't lose the CIDER session over TRAMP files.
3535
- [#3413](https://github.com/clojure-emacs/cider/issues/3413): Make jump-to-definition work in projects needing `cider-path-translations` (i.e. Dockerized projects).
3636
- [#2436](https://github.com/clojure-emacs/cider/issues/2436): Prevent malformed `cider-repl-history-file`s from failing `cider-jack-in`.
3737
- [#3456](https://github.com/clojure-emacs/cider/issues/3456): restore xref-based jump-to-definition in Babashka (and any nREPL clients not having cider-nrepl).

cider-eval.el

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -678,19 +678,20 @@ If location could not be found, return nil."
678678
(point))))
679679
(list begin end buffer)))))))))))))
680680

681-
(defun cider-handle-compilation-errors (message eval-buffer)
682-
"Highlight and jump to compilation error extracted from MESSAGE.
681+
(defun cider-handle-compilation-errors (message eval-buffer &optional no-jump)
682+
"Highlight and jump to compilation error extracted from MESSAGE, honor NO-JUMP.
683683
EVAL-BUFFER is the buffer that was current during user's interactive
684684
evaluation command. Honor `cider-auto-jump-to-error'."
685685
(when-let* ((loc (cider--find-last-error-location message))
686686
(overlay (make-overlay (nth 0 loc) (nth 1 loc) (nth 2 loc)))
687687
(info (cider-extract-error-info cider-compilation-regexp message)))
688688
(let* ((face (nth 3 info))
689689
(note (nth 4 info))
690-
(auto-jump (if (eq cider-auto-jump-to-error 'errors-only)
691-
(not (or (eq face 'cider-warning-highlight-face)
692-
(string-match-p "warning" note)))
693-
cider-auto-jump-to-error)))
690+
(auto-jump (unless no-jump
691+
(if (eq cider-auto-jump-to-error 'errors-only)
692+
(not (or (eq face 'cider-warning-highlight-face)
693+
(string-match-p "warning" note)))
694+
cider-auto-jump-to-error))))
694695
(overlay-put overlay 'cider-note-p t)
695696
(overlay-put overlay 'font-lock-face face)
696697
(overlay-put overlay 'cider-note note)
@@ -774,6 +775,19 @@ REPL buffer. This is controlled via
774775
(cider--make-fringe-overlay (point)))
775776
(scan-error nil)))))
776777

778+
(defun cider--error-phase-of-last-exception (buffer)
779+
"Returns the :phase of the latest exception associated to BUFFER, if any."
780+
(when cider-clojure-compilation-error-phases
781+
(when-let ((conn (with-current-buffer buffer
782+
(cider-current-repl))))
783+
(when (cider-nrepl-op-supported-p "analyze-last-stacktrace" conn)
784+
(when-let* ((result (nrepl-send-sync-request (thread-last (map-merge 'list
785+
'(("op" "analyze-last-stacktrace"))
786+
(cider--nrepl-print-request-map fill-column))
787+
(seq-mapcat #'identity))
788+
conn)))
789+
(nrepl-dict-get result "phase"))))))
790+
777791
(declare-function cider-inspect-last-result "cider-inspector")
778792
(defun cider-interactive-eval-handler (&optional buffer place)
779793
"Make an interactive eval handler for BUFFER.
@@ -796,17 +810,30 @@ when `cider-auto-inspect-after-eval' is non-nil."
796810
(cider--display-interactive-eval-result res end))
797811
(lambda (_buffer out)
798812
(cider-emit-interactive-eval-output out))
799-
(lambda (_buffer err)
813+
(lambda (buffer err)
800814
(cider-emit-interactive-eval-err-output err)
801815

802-
(when (or (not cider-show-error-buffer)
803-
(not (cider-connection-has-capability-p 'jvm-compilation-errors)))
804-
805-
;; Display errors as temporary overlays
806-
(let ((cider-result-use-clojure-font-lock nil))
807-
(cider--display-interactive-eval-result
808-
err end 'cider-error-overlay-face)))
809-
(cider-handle-compilation-errors err eval-buffer))
816+
(let ((phase (cider--error-phase-of-last-exception buffer)))
817+
(when (or
818+
;; if we won't show *cider-error*, because of configuration, the overlay is adequate because it compensates for the lack of info in a compact manner:
819+
(not cider-show-error-buffer)
820+
(not (cider-connection-has-capability-p 'jvm-compilation-errors))
821+
;; if we won't show *cider-error*, because of an ignored phase, the overlay is adequate:
822+
(and cider-show-error-buffer
823+
(member phase cider-clojure-compilation-error-phases)))
824+
;; Display errors as temporary overlays
825+
(let ((cider-result-use-clojure-font-lock nil))
826+
(cider--display-interactive-eval-result
827+
err end 'cider-error-overlay-face)))
828+
829+
(cider-handle-compilation-errors err
830+
eval-buffer
831+
;; we prevent jumping behavior on compilation errors,
832+
;; because lines tend to be spurious (e.g. 0:0)
833+
;; and because on compilation errors, normally
834+
;; the error is 'right there' in the current line
835+
;; and needs no jumping:
836+
phase)))
810837
(lambda (buffer)
811838
(if beg
812839
(unless fringed

0 commit comments

Comments
 (0)