From 8b12a0fd8e3ed205d2ece43f3cb5f7b762cdaf36 Mon Sep 17 00:00:00 2001 From: vemv Date: Fri, 29 Sep 2023 21:24:38 +0200 Subject: [PATCH 1/3] Restore `cider--display-interactive-eval-result` overlays for compilation errors Fixes https://github.com/clojure-emacs/cider/issues/3487 --- CHANGELOG.md | 4 ++-- cider-eval.el | 58 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 428b9103b..29d0ad47b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,10 +28,10 @@ - [#3331](https://github.com/clojure-emacs/cider/issues/3331): `cider-eval`: never jump to spurious locations, as sometimes conveyed by nREPL. - [#3112](https://github.com/clojure-emacs/cider/issues/3112): Fix the CIDER `xref-find-references` backend to return correct filenames. - [#3393](https://github.com/clojure-emacs/cider/issues/3393): recompute namespace info on each shadow-cljs recompilation or evaluation. -- [#3402](https://github.com/clojure-emacs/cider/issues/3402): fix `cider-format-connection-params` edge case for Emacs 29. +- [#3402](https://github.com/clojure-emacs/cider/issues/3402): Fix `cider-format-connection-params` edge case for Emacs 29. - [#3393](https://github.com/clojure-emacs/cider/issues/3393): Recompute namespace info on each shadow-cljs recompilation or evaluation. - Recompute namespace info on each fighweel-main recompilation. -- [#3250](https://github.com/clojure-emacs/cider/issues/3250): don't lose the CIDER session over TRAMP files. +- [#3250](https://github.com/clojure-emacs/cider/issues/3250): Don't lose the CIDER session over TRAMP files. - [#3413](https://github.com/clojure-emacs/cider/issues/3413): Make jump-to-definition work in projects needing `cider-path-translations` (i.e. Dockerized projects). - [#2436](https://github.com/clojure-emacs/cider/issues/2436): Prevent malformed `cider-repl-history-file`s from failing `cider-jack-in`. - [#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). diff --git a/cider-eval.el b/cider-eval.el index 69f1e68fc..11642c7b5 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -678,8 +678,8 @@ If location could not be found, return nil." (point)))) (list begin end buffer))))))))))))) -(defun cider-handle-compilation-errors (message eval-buffer) - "Highlight and jump to compilation error extracted from MESSAGE. +(defun cider-handle-compilation-errors (message eval-buffer &optional no-jump) + "Highlight and jump to compilation error extracted from MESSAGE, honor NO-JUMP. EVAL-BUFFER is the buffer that was current during user's interactive evaluation command. Honor `cider-auto-jump-to-error'." (when-let* ((loc (cider--find-last-error-location message)) @@ -687,10 +687,11 @@ evaluation command. Honor `cider-auto-jump-to-error'." (info (cider-extract-error-info cider-compilation-regexp message))) (let* ((face (nth 3 info)) (note (nth 4 info)) - (auto-jump (if (eq cider-auto-jump-to-error 'errors-only) - (not (or (eq face 'cider-warning-highlight-face) - (string-match-p "warning" note))) - cider-auto-jump-to-error))) + (auto-jump (unless no-jump + (if (eq cider-auto-jump-to-error 'errors-only) + (not (or (eq face 'cider-warning-highlight-face) + (string-match-p "warning" note))) + cider-auto-jump-to-error)))) (overlay-put overlay 'cider-note-p t) (overlay-put overlay 'font-lock-face face) (overlay-put overlay 'cider-note note) @@ -774,6 +775,21 @@ REPL buffer. This is controlled via (cider--make-fringe-overlay (point))) (scan-error nil))))) +(defun cider--error-from-ignored-phase-p (buffer) + "Returns whether the latest exception associated to BUFFER should be ignored." + (when cider-clojure-compilation-error-phases + (when-let ((conn (with-current-buffer buffer + (cider-current-repl)))) + (when (cider-nrepl-op-supported-p "analyze-last-stacktrace" conn) + (when-let* ((result (nrepl-send-sync-request (thread-last (map-merge 'list + '(("op" "analyze-last-stacktrace")) + (cider--nrepl-print-request-map fill-column)) + (seq-mapcat #'identity)) + conn)) + (phase (nrepl-dict-get result + "phase"))) + (member phase cider-clojure-compilation-error-phases)))))) + (declare-function cider-inspect-last-result "cider-inspector") (defun cider-interactive-eval-handler (&optional buffer place) "Make an interactive eval handler for BUFFER. @@ -796,17 +812,29 @@ when `cider-auto-inspect-after-eval' is non-nil." (cider--display-interactive-eval-result res end)) (lambda (_buffer out) (cider-emit-interactive-eval-output out)) - (lambda (_buffer err) + (lambda (buffer err) (cider-emit-interactive-eval-err-output err) - (when (or (not cider-show-error-buffer) - (not (cider-connection-has-capability-p 'jvm-compilation-errors))) - - ;; Display errors as temporary overlays - (let ((cider-result-use-clojure-font-lock nil)) - (cider--display-interactive-eval-result - err end 'cider-error-overlay-face))) - (cider-handle-compilation-errors err eval-buffer)) + (let ((from-ignored-phase (cider--error-from-ignored-phase-p buffer))) + (when (or + ;; 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: + (not cider-show-error-buffer) + (not (cider-connection-has-capability-p 'jvm-compilation-errors)) + ;; if we won't show *cider-error*, because of an ignored phase, the overlay is adequate: + (and cider-show-error-buffer from-ignored-phase)) + ;; Display errors as temporary overlays + (let ((cider-result-use-clojure-font-lock nil)) + (cider--display-interactive-eval-result + err end 'cider-error-overlay-face))) + + (cider-handle-compilation-errors err + eval-buffer + ;; we prevent jumping behavior on compilation errors, + ;; because lines tend to be spurious (e.g. 0:0) + ;; and because on compilation errors, normally + ;; the error is 'right there' in the current line + ;; and needs no jumping: + from-ignored-phase))) (lambda (buffer) (if beg (unless fringed From ce4ddf2e189ee6ec33124ebca9253ac760bdc165 Mon Sep 17 00:00:00 2001 From: vemv Date: Fri, 29 Sep 2023 23:37:25 +0200 Subject: [PATCH 2/3] Refine behavior --- cider-eval.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cider-eval.el b/cider-eval.el index 11642c7b5..7a0ba91a9 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -775,8 +775,8 @@ REPL buffer. This is controlled via (cider--make-fringe-overlay (point))) (scan-error nil))))) -(defun cider--error-from-ignored-phase-p (buffer) - "Returns whether the latest exception associated to BUFFER should be ignored." +(defun cider--error-phase-of-latest-exception (buffer) + "Returns the :phase of the latest exception associated to BUFFER, if any." (when cider-clojure-compilation-error-phases (when-let ((conn (with-current-buffer buffer (cider-current-repl)))) @@ -785,10 +785,8 @@ REPL buffer. This is controlled via '(("op" "analyze-last-stacktrace")) (cider--nrepl-print-request-map fill-column)) (seq-mapcat #'identity)) - conn)) - (phase (nrepl-dict-get result - "phase"))) - (member phase cider-clojure-compilation-error-phases)))))) + conn))) + (nrepl-dict-get result "phase")))))) (declare-function cider-inspect-last-result "cider-inspector") (defun cider-interactive-eval-handler (&optional buffer place) @@ -815,13 +813,14 @@ when `cider-auto-inspect-after-eval' is non-nil." (lambda (buffer err) (cider-emit-interactive-eval-err-output err) - (let ((from-ignored-phase (cider--error-from-ignored-phase-p buffer))) + (let ((phase (cider--error-phase-of-latest-exception buffer))) (when (or ;; 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: (not cider-show-error-buffer) (not (cider-connection-has-capability-p 'jvm-compilation-errors)) ;; if we won't show *cider-error*, because of an ignored phase, the overlay is adequate: - (and cider-show-error-buffer from-ignored-phase)) + (and cider-show-error-buffer + (member phase cider-clojure-compilation-error-phases))) ;; Display errors as temporary overlays (let ((cider-result-use-clojure-font-lock nil)) (cider--display-interactive-eval-result @@ -834,7 +833,7 @@ when `cider-auto-inspect-after-eval' is non-nil." ;; and because on compilation errors, normally ;; the error is 'right there' in the current line ;; and needs no jumping: - from-ignored-phase))) + phase))) (lambda (buffer) (if beg (unless fringed From e4dc68e7972ddfd9c6404573bc735ab0d88253e7 Mon Sep 17 00:00:00 2001 From: vemv Date: Sat, 30 Sep 2023 09:24:13 +0200 Subject: [PATCH 3/3] Rename --- cider-eval.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cider-eval.el b/cider-eval.el index 7a0ba91a9..8a906c3e0 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -775,7 +775,7 @@ REPL buffer. This is controlled via (cider--make-fringe-overlay (point))) (scan-error nil))))) -(defun cider--error-phase-of-latest-exception (buffer) +(defun cider--error-phase-of-last-exception (buffer) "Returns the :phase of the latest exception associated to BUFFER, if any." (when cider-clojure-compilation-error-phases (when-let ((conn (with-current-buffer buffer @@ -813,7 +813,7 @@ when `cider-auto-inspect-after-eval' is non-nil." (lambda (buffer err) (cider-emit-interactive-eval-err-output err) - (let ((phase (cider--error-phase-of-latest-exception buffer))) + (let ((phase (cider--error-phase-of-last-exception buffer))) (when (or ;; 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: (not cider-show-error-buffer)