Description
Expected behavior
Typing math/ in a CLJC file should insert the libspec [clojure.math :as math]
into the ns form.
Actual behavior
The libspec inserted is #?(:clj [clojure.math :as math])
.
Steps to reproduce the problem
Using clj-refactor in a CLJC file type math/
in a namespace with no existing alias named math.
Commentary
This is using a default cljr-magic-require-namespaces
which does not specify clojure.math as :only ("clj")
but does include it as a magic namespace. This works correctly for clojure.set :as set
and clojure.string :as str
and even clojure.walk
and clojure.zip
, which are also listed in the magic namespaces, so it's confusing that clojure.math
behaves differently. The project I'm testing with has a mixture of cljs and cljc files but has no instances where the math libspec is wrapped in a reader conditional. It does correctly return clojure.math :as math in cljs files in that project, but add the unnecessary :clj language conditional if math/
invokes cljr-slash
in a CLJC file.
Note that clojure.math is one of the CLJS namespaces that is magically mapped to the equivalent namespace in Clojure as described in https://clojurescript.org/guides/ns-forms#_clojure_namespace_aliasing. I don't know if that's related but it seems like it might be.
Environment & Version information
clj-refactor.el and refactor-nrepl version information
clj-refactor 3.11.3, refactor-nrepl 3.10.0
CIDER version information
;; CIDER 1.14.0-snapshot (package: 20240510.1436), nREPL 1.1.1
;; Clojure 1.11.1, Java 17.0.10
Emacs version
GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.18.0) of 2024-05-08
Operating system
Ubuntu 23.10
Activity
vemv commentedon May 12, 2024
Hi @dgtized , good to see you here.
Can you attach the nrepl logs as well?
Thanks - V
dgtized commentedon May 13, 2024
Not sure if this is the right log, I toggled
nrepl-toggle-message-logging
and grabbed the output that seemed related. Is that what you meant by the nrepl logs?vemv commentedon May 13, 2024
Yes, that's very useful as it includes the entire
preferred-aliases
value, besides fromlanguage-context
, etc.I'll try to give it a shot, if there are no news, feel free to nudge.
Or if you'd be willing, you can try reproducing the bug by adding that data to
refactor-nrepl/test/refactor_nrepl/ns/suggest_libspecs_test.clj
Lines 51 to 60 in 4a873ca