clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.55k stars 646 forks source link

clojure.repl/source function and function/buffer CIDER evaluation #3210

Open meditans opened 2 years ago

meditans commented 2 years ago

Expected and Actual behavior

Consider this file in an appropriate project:

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

(defn foo [a] (inc a))

(repl/source omicron.core/foo)

I would expect both cider-eval-defun-at-point over the source invocations, and cider-eval-buffer to respond with foo's source. Instead I get:

Source not found

For reference, cider-ns-refresh correctly prints the source code. The initial conversation for this happened on slack, where @vemv pointed out that this has probably to do with the fact that *file* is maybe unbound during such calls.

I think cider-eval-buffer, cider-eval-defun-at-point and cider-eval-file should have the right bindings.

CIDER version information

;; CIDER 1.3.0 (Ukraine), nREPL 0.9.0
;; Clojure 1.11.0, Java 11.0.12
vemv commented 2 years ago

Grepping https://github.com/clojure-emacs/cider and https://github.com/clojure-emacs/cider-nrepl, *file* isn't bound anywhere (relevant to this issue).

*file* certainly should be bound whenever code is (re)loaded. tools.namespace (and therefore cider-refresh) implicitly does this (because it relies on clojure.core primitives).

Other tools like Eastwood explicitly have to bind *file* - not too long ago I added this to fix a similar bug: https://github.com/jonase/eastwood/blob/5a55eff81aff75dbca94adfb7f18e956e52fcf55/src/eastwood/analyze_ns.clj#L427

So the task to be done is:

vemv commented 2 years ago

Correction, the code that loads file is located in a separate repo: https://github.com/nrepl/nrepl/blob/e1558d7b7e1c5b50187edb92282282b87bcba998/src/clojure/nrepl/middleware/load_file.clj

(it doesn't bind *file* either)