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

Indented code cannot be debugged in-source #2852

Closed
yuhan0 opened this issue Jun 5, 2020 · 7 comments · Fixed by clojure-emacs/cider-nrepl#677 or #2855
Closed

Indented code cannot be debugged in-source #2852

yuhan0 opened this issue Jun 5, 2020 · 7 comments · Fixed by clojure-emacs/cider-nrepl#677 or #2855

Comments

@yuhan0
Copy link
Contributor

yuhan0 commented Jun 5, 2020

Expected behavior

Executing cider-debug-defun-at-point (C-u C-M-x) should work in source for forms in an indented comment block when clojure-toplevel-inside-comment-form is true.

(comment
  (inc (inc 0))
  )

More generally, this occurs when evaluating any indented form tagged with #dbg

(do
  #dbg (str (inc 0)) ;; cider-eval-last-sexp here
  ...)

Actual behavior

The source "cannot be found" and a temporary debug buffer is created.

Steps to reproduce the problem

place cursor at | and eval last sexp

(do
  #dbg (str (inc 0)) | 
  ...)

Solution

After some detective work I found the underlying issue to be the difference in column indexing between Emacs (0-indexed) and Clojure (1-indexed).

The outgoing conversion to 1-indexing happens in cider-interactive-eval, using the function cider-column-number-at-pos, so nrepl messages are sent as 1-indexed columns.

(defun cider-column-number-at-pos (pos)

However for incoming responses, this line in cider-nrepl causes only toplevel forms (column = 1) to be converted to 0-indexing , and no further processing is done client-side.
clojure-emacs/cider-nrepl@7660eb7#diff-0d65c570bef3dbf4640690a252e06f28R340

When column != 1 this causes an off-by-one error and the cider-debug code thinks the source has been edited.

I think the proper solution to this would be to remove the above line in cider-nrepl and offset the 1-indexed response in Emacs. This may break other clients, in particular Calva.

Environment & Version information

CIDER version information

;; CIDER 0.25.0snapshot, nREPL 0.7.0
;; Clojure 1.10.1, Java 14.0.1

Emacs version

26.3

Operating system

macOS 10.14

@yuhan0
Copy link
Contributor Author

yuhan0 commented Jun 6, 2020

if the above solution looks alright I can open PRs in both repos to fix it.

@bbatsov
Copy link
Member

bbatsov commented Jun 6, 2020

Yeah, I think the proposed solution is reasonable.

@bbatsov
Copy link
Member

bbatsov commented Jun 7, 2020

//cc @PEZ

@PEZ
Copy link

PEZ commented Jun 7, 2020

Thanks for the heads-up! I'll consult with @bpringe about wether Calva is vulnerable, and how we can mitigate. When will the change in cider-nrepl be released?

bbatsov pushed a commit to clojure-emacs/cider-nrepl that referenced this issue Jun 7, 2020
@bbatsov
Copy link
Member

bbatsov commented Jun 7, 2020

I did it already - 0.25.2.

@bpringe
Copy link
Contributor

bpringe commented Jun 8, 2020

I believe I accounted for this in Calva already, maybe even accidentally 😄. I tested Calva with this scenario with cider-nrepl before 0.25.2 and with it and it works as expected. 🎉

@bbatsov
Copy link
Member

bbatsov commented Jun 8, 2020

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants