Skip to content

Indented code cannot be debugged in-source #2852

@yuhan0

Description

@yuhan0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions