Open developer2019 opened 6 years ago
Had the same issue on clj-refactor.el version: 2.3.1
.
Uninstalled it and installed clj-refactor 2.4.0-SNAPSHOT (package: 20171117.317), refactor-nrepl 2.4.0-SNAPSHOT from MELPA (i. e. latest clj-refactor). No changes and issue still occurs.
managed to reproduce this. The problem essentially is that cljr can not get the ns for the symbol to be renamed. we use these calls to resolve the ns of the symbol
(symbol (cider-symbol-at-point))
(var-info (cljr--var-info symbol))
(ns (nrepl-dict-get var-info "ns"))
this calls a cider function which only returns something if the namespace is loaded. this results in nil
because the code is not loaded at this point.
a proper fix would be to call warm-ast-cache
before trying to execute find-symbol-sync
(given that the user answered y
)
there are several workarounds:
C-c C-k
or refresh
from your cider REPL, latter loads the whole project actually). after that rename-symbol should workcljr-warn-on-eval
to nil ((setq cljr-warn-on-eval nil)
) this will result in evaluating the whole project at startup time. if you are worried to set it globally set it in a dir local for the project you are confident about that this won't cause any harmThank you, @benedekfazekas, for exploration of this bug and finding workarounds for it.
I wonder why code is not loaded if cljr have asked about evaluation before asking for a new name for the symbol and I confirmed evaluation:
To perform this op the project needs to be evaluated.
Analyzing a large project might take a while: hit C-g to abort.
(Set cljr-warn-on-eval to nil to analyze the project without warning)
Do you want to proceed? (y or n) y
Any why after (setq cljr-warn-on-eval nil)
when there are no message (see above) project evaluation happens. It seems that showing this message prevents project evaluation even when y
is entered.
load the namespace into your REPL session (either C-c C-k or refresh from your cider REPL, latter loads the whole project actually). after that rename-symbol should work
I actually need to load the whole project (not that example project) to be able to refactor symbol uses through all project files so tried to refresh
from cider REPL:
user> refresh
CompilerException java.lang.RuntimeException: Unable to resolve symbol: refresh in this context, compiling:(*cider-repl example*:1:7527)
user> (clojure.repl/refresh)
CompilerException java.lang.RuntimeException: No such var: clojure.repl/refresh, compiling:(*cider-repl example*:49:7)
Doesn't work.
it actually works for the second attempt. not really sure why that is but most likely when cljr tries to resolve the symbol to be renamed it builds an AST for the namespace and that also results in evaluating the it
Could work but haven't tried it yet.
set cljr-warn-on-eval to nil ((setq cljr-warn-on-eval nil)) this will result in evaluating the whole project at startup time. if you are worried to set it globally set it in a dir local for the project you are confident about that this won't cause any harm
This works.
Hi!
Cljr fails to rename symbol in code which is successfully compiled and run by
lein test
.Expected behavior
cd /Users/YourName/Desktop
.git clone https://github.com/developer2019/example
/Users/YourName/Desktop/example/src/anagram.clj
in Emacs.M-x cider-mode
<menu-bar> <CIDER> <Start a REPL>
anagrams-for
(line 4, symbol 10) and press M-xcljr-rename-symbol
RET. It tells that project needs to be evaluated, typey RET
.Actual behavior
cd /Users/YourName/Desktop
.git clone https://github.com/developer2019/example
/Users/YourName/Desktop/example/src/anagram.clj in Emacs
.M-x cider-mode
<menu-bar> <CIDER> <Start a REPL>
anagrams-for
(line 4, symbol 10) and press M-xcljr-rename-symbol
RET. It tells that project needs to be evaluated, typey RET
.Wrong type argument: char-or-string-p, nil
.Steps to reproduce the problem
cd /Users/YourName/Desktop
.git clone https://github.com/developer2019/example
/Users/YourName/Desktop/example/src/anagram.clj in Emacs
.M-x cider-mode
<menu-bar> <CIDER> <Start a REPL>
anagrams-for
(line 4, symbol 10) and press M-xcljr-rename-symbol
RET. It tells that project needs to be evaluated, typey RET
.Wrong type argument: char-or-string-p, nil
.Environment & Version information
lein test
compiles this code and runs successfully.clj-refactor.el version information
clj-refactor 2.4.0-SNAPSHOT (package: 20171117.317), refactor-nrepl 2.4.0-SNAPSHOT from MELPA (i. e. latest clj-refactor).
CIDER version information
Leiningen or Boot version
lein test
compiles this project and runs successfully.Emacs version
Operating system