cider icon indicating copy to clipboard operation
cider copied to clipboard

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

Open meditans opened this issue 3 years ago • 2 comments

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

meditans avatar May 28 '22 15:05 meditans

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:

  • make cider.el pass the file as part of the nrepl message, if not already done accurately, for all ops described in the issue
    • has to have the correct format, similar to other :file metadata
  • make cider-nrepl bind *file* if such a piece of data is received.

vemv avatar May 28 '22 16:05 vemv

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)

vemv avatar May 28 '22 16:05 vemv