Fork me on GitHub
#cider
<
2022-05-28
>
Carlo14:05:40

I have a problem with the clojure.repl/source function in CIDER. Consider:

(ns omicron.core
  (:require [clojure.repl :as repl]))

(defn foo [a] (inc a))

(repl/source omicron.core/foo)
When I eval this buffer in CIDER, it will print in the repl Source not found , while if I require the file via clj it will print the source. What could the problem be?

vemv14:05:59

when you eval code interactively, especially via a repl, the source is the repl, so it makes sense for the source not to be found What specific cider ops are you using to load code? Those that are related to files should preserve source info, and those that are more 'free form', not so much

Carlo14:05:54

I am using both cider-eval-buffer and cider-eval-defun-at-point . What should I be using instead?

Carlo14:05:50

Same with cider-eval-file

👍 1
vemv14:05:32

cider-refresh is one that would almost certainly work, however if that's not your jam, I wouldn't want to suggest a change of workflow probably cider-eval-buffer/`cider-eval-defun-at-point` might be fixable although I'd imagine we cannot always guarantee that the file will be associated. cider-eval-file surprises me more, and it could make a stronger guarantee Could you create a (single) issue for this? Perhaps it's never been implemented to begin with, IDK

vemv14:05:01

One has to bind *file* as one loads code, perhaps cider forgot to do that

vemv14:05:07

Also, one additional question, does jump-to-source work in these cases?

Carlo14:05:48

Indeed, cider-ns-refresh does the right thing. Yes, jump-to-source works (but I'm not sure which function is used to get that in doom emacs+lsp, so maybe that's not CIDER's merit)

Carlo14:05:49

I find this behavior counterintuitive because:

> (meta #'omicron.core/foo)

{:arglists ([a]),
 :line 40,
 :column 1,
 :file "/home/carlo/code/clojure/omicron/src/omicron/core.clj",
 :name foo,
 :ns #namespace[omicron.core]}
so at some point we know that the var belongs to the file (and where)

Carlo14:05:43

my point being that I would like cider-eval-defun-at-point to try to associate the right informations, at least

Carlo14:05:43

opening an issue

🙌 1
vemv16:05:06

Thanks!

💯 1
vemv16:05:53

I verified and described what has to be done. I might give it a shot, however I don't have much time in my hands (and other priorities for cider dev!) so this would be both a pretty easy task and a very appreciated one. Up to you :)

Carlo17:05:19

Thank you @U45T93RA6, much appreciated 🙌