cider
cider copied to clipboard
Use the `cider--display-interactive-eval-result` for more cases of compilation errors
An overlay is displayed through cider--display-interactive-eval-result
when a compilation error happens, but only when doing interactive evaluation.
(Note that that is the intended design, and fully makes sense: we use something named cider--display-interactive-eval-result)
However, from a user point of view, it is desirable to show this overlay under more use cases, which may not go under the cider-interactive-eval-handler
(the part responsible for calling cider--display-interactive-eval-result
)
- ~cider-load-buffer~ (done)
- cider-refresh
For both cases, besides from the display of an overlay, the jumping to the right line, as introduced in https://github.com/clojure-emacs/cider/pull/3492 should also be offered. It might be more tricky for cider-refresh, since the cause of the error may reside in another file (possibly without a corresponding open buffer).
I would be willing to give this a shot, but am not familiar enough with the inner workings of CIDER to know where to begin. If I could get a few pointers, where to start looking, what sorts of things to look out for, I could see if I can figure something out.
cider-eval.el features a series of 'handler' defuns, please grep for: defun.*cider.*handler
in that file.
Then, it's a matter of locating the relevant handler for cider-load-buffer, and modify it such that cider--display-interactive-eval-result
is invoked, when adequate.
As noted in the OP we also want to reliably jump to the relevant line. That is accomplished with the cider-handle-compilation-errors
function as can be seen in https://github.com/clojure-emacs/cider/pull/3492/files
Probably we want to only jump if the line:col is not 0:0 (some compilation errors are reported like that).
Hope it helps!
Thanks for the info, @vemv! It turns out cider-load-buffer
is handled by cider-load-file-handler
which it turns out already has this feature via cider-handle-compilation-errors
. Its docstring says:
"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'."
The question then becomes why it doesn't seem to work. Debugging reveals that it is unable to find the location from the error. It looks like the regex being used does not match the syntax error message. The pattern matches this:
Syntax error compiling at
but my error message is
Syntax error reading source at
Adding this to the cider-clojure-1.10-error
pattern does fix this to a certain degree, even if it does not use the cool new overlay. Instead it will add a squiggly red line with the message visible when hovering over the squiggly.
Any thoughts on further steps from here?
I'd say that the problem is that cider-handle-compilation-errors takes care of the squiggly and the jumping, but the overlay is provided via this separate call:
(let ((cider-result-use-clojure-font-lock nil))
(cider--display-interactive-eval-result
err end 'cider-error-overlay-face))
You can see both in action here
I think cider-pprint-eval-last-sexp
also qualifies. Current behavior is to open a blank *cider-result*, no message in minibuffer, no overlay.
(@vemv edit: fixed in cider 1.10)