Tracking source form positions in eval
Description
Environment
Attachments
Activity

Chas Emerick September 16, 2015 at 11:54 AM
On master now, will be cutting a release shortly.

import June 17, 2015 at 12:38 AM
Comment made by: brunchboy
This would make my development life significantly more pleasant if it could be merged.

Bozhidar Batsov April 1, 2015 at 7:03 PM
Fantastic work!
Btw, I'll once again mention here that it's probably time to drop compatibility with Clojure pre-1.5. Supporting old (and pretty much unused) versions forever is bad for both the project and the community (sometimes people have to be nudged in the right direction).
Michael Griffiths April 1, 2015 at 6:46 PM
The attached patch, 0001-NREPL-59-Tracking-source-form-positions-in-eval.patch, adds optional file
, line
and column
slots to the eval
op. As discussed in the above-mentioned gist, reflection is used to set the line and column numbers of LineNumberingPushbackReader
.
The version-sniffing in the test is because support for column number metadata was only added in Clojure 1.5.
The reflection stuff is clearly non-idiomatic, but doing it this way lets us retain compatibility back to Clojure 1.2. FWIW the below crude benchmark suggests the performance impact is negligible, but we could presumably do some of it (resolving the _columnNumber
and in
fields) at load-time instead to further mitigate it.
Before:
After:
Feedback most welcome!

Chas Emerick March 27, 2015 at 9:38 AM
This is now much easier, insofar as piggieback implements its own handling of eval
, not depending upon interruptible-eval
's at all.
Progress appears here: https://gist.github.com/cichli/163b8549d72ccbfc3645
Dev tools writers using nREPL's eval op face the following problem - using the `eval` op you cannot pass information regarding the filename and the file position of the form you're evaluating and therefore afterwards you can't use find its definition. Because of this most CIDER users reload their source buffers all the time with `load-file`. Another implication of this problem is that exception backtraces have meaningless information about the position of the problem (usually something like `NO_FILE:1`). I've noticed that LightTable has a custom middleware for this, ritz used to have one as well, probably others too. Now I'm contemplating doing something similar for CIDER, but it seems to me this is basic functionality that should be supported out-of-the-box.
I'd like to propose that the default eval middleware be augmented to support some form of source form tracking to spare tool writers from having to reinvent the wheel.