dissect icon indicating copy to clipboard operation
dissect copied to clipboard

Line numbers are inaccurate

Open sjl opened this issue 9 years ago • 1 comments

The line numbers reported by dissect are inaccurate when multiple newlines are present. Example:

screenshot

(defun dump-stack (stack)
  (loop :for frame :in stack
        :do (format t "~A in ~A line ~D~%"
                    (dissect:call frame)
                    (dissect:file frame)
                    (dissect:line frame))))


(defun foo ()
  (dump-stack (dissect:stack)))



;; lots of newlines and a comment or two...



(defun bar ()
  (dump-stack (dissect:stack)))


;; Run
(dissect:with-truncated-stack ()
  (foo))

(dissect:with-truncated-stack ()
  (bar))

This outputs:

FOO in /Users/sjl/src/cl-nrepl/scratch.lisp line 7
BAR in /Users/sjl/src/cl-nrepl/scratch.lisp line 11

Which is not quite right. It's pointing at the beginning of the whitespace that comes before the actual form.

I'm pretty sure this is because find-definition-in-file records the file position in its loop https://github.com/sjl/dissect/blob/master/toolkit.lisp#L60 and then calls read-toplevel-form which might chew off more from the stream before it reads a top level form.

Maybe read-toplevel-form should return the position of the form it read as a secondary file, then find-definition-in-file could use that as pos.

sjl avatar Aug 21 '16 15:08 sjl

The line detection mechanism in general is pretty awkward because of the different ways in which the implementations actually record the source location and the kludgy way in which dissect attempts to translate that into a file position, so I'm not surprised that it fails in some ways.

Unfortunately I don't have the time to look into this right now and experiment with it, so I'll have to leave this open for a while unless someone else decides to be generous enough to donate their time to it.

Shinmera avatar Aug 21 '16 22:08 Shinmera