Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move form refactoring doesn't follow symlinks #142

Closed
scramjet opened this issue Feb 9, 2016 · 7 comments · Fixed by #368
Closed

move form refactoring doesn't follow symlinks #142

scramjet opened this issue Feb 9, 2016 · 7 comments · Fixed by #368

Comments

@scramjet
Copy link

scramjet commented Feb 9, 2016

Hello, I'm trying to move a function to a new namespace ("move one or more forms to another namespace, :refer any functions"), but getting the exception below (note that this is from Emacs' *Messages* buffer and includes the fact that the file it's complaining about actually exists).

The function is moved and the target namespace has some new require's added, but nothing else referring to it is updated.

I'm using clj-refactor 2.0 and the latest stable CIDER.

Any ideas, or things I should try?

Wrote /Users/matt/Development/basis/src/basis/network/core.clj
cljr--get-error-value: Error in nrepl-refactor: java.io.FileNotFoundException: src/basis/network/core.clj (No such file or directory)
 at java.io.FileInputStream.open0 (FileInputStream.java:-2)
    java.io.FileInputStream.open (FileInputStream.java:195)
    java.io.FileInputStream.<init> (FileInputStream.java:138)
    java.io.FileInputStream.<init> (FileInputStream.java:93)
    java.io.FileReader.<init> (FileReader.java:58)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
    sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance (Constructor.java:422)
    clojure.lang.Reflector.invokeConstructor (Reflector.java:180)
    refactor_nrepl.core$read_ns_form.invokeStatic (core.clj:234)
    refactor_nrepl.core$read_ns_form.invoke (core.clj:234)
    refactor_nrepl.ns.clean_ns$clean_ns.invokeStatic (clean_ns.clj:46)
    refactor_nrepl.ns.clean_ns$clean_ns.invoke (clean_ns.clj:38)
    refactor_nrepl.middleware$clean_ns_reply.invokeStatic (middleware.clj:75)
    refactor_nrepl.middleware$clean_ns_reply.invoke (middleware.clj:74)
    refactor_nrepl.middleware$wrap_refactor$fn__18008.invoke (middleware.clj:123)
    clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__721.invoke (middleware.clj:22)
    cider.nrepl.middleware.pprint$wrap_pprint$fn__7533.invoke (pprint.clj:51)
    clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__721.invoke (middleware.clj:22)
    clojure.tools.nrepl.middleware.pr_values$pr_values$fn__908.invoke (pr_values.clj:22)
    clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__721.invoke (middleware.clj:22)
    cider.nrepl.middleware.test$wrap_test$fn__7815.invoke (test.clj:240)
    clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__721.invoke (middleware.clj:22)
    clojure.tools.nrepl.middleware.session$session$fn__1056.invoke (session.clj:192)
    clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__721.invoke (middleware.clj:22)
    cider.nrepl.middleware.track_state$wrap_tracker$fn__8357.invoke (track_state.clj:206)
    clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__721.invoke (middleware.clj:22)
    clojure.tools.nrepl.server$handle_STAR_.invokeStatic (server.clj:19)
    clojure.tools.nrepl.server$handle_STAR_.invoke (server.clj:16)
    clojure.tools.nrepl.server$handle$fn__1129.invoke (server.clj:28)
    clojure.core$binding_conveyor_fn$fn__4676.invoke (core.clj:1938)
    clojure.lang.AFn.call (AFn.java:18)
    java.util.concurrent.FutureTask.run (FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    java.lang.Thread.run (Thread.java:745)
@expez
Copy link
Member

expez commented Feb 10, 2016

Ths is clean-ns failing. Does that command work on it's own when you're visiting the network/core.clj file?

If not, I'd love a copy of the message being sent down to the middleware (you can find this is in the nrepl-messages buffer if nrepl-log-messages is t)

@scramjet
Copy link
Author

So I had tossed out the environment generating that error. Recreating it and trying again, it worked. It moved the fn and generated a :refer correctly, but it did fail to add the correct :import statements in the new namespace, meaning that some type hints in the code caused compile errors (which I'm not too surprised about, since that's a pretty hard problem). Clean namespace was fine.

So, might have been some sort of bad state the REPL environment and/or Emacs was in? Anyway, sorry to waste your time. Will re-open if I can get it to happen again.

@scramjet
Copy link
Author

I think I've found why I couldn't repro this: src/basis/network/core.clj is from an external library project symlinked in the lein checkouts directory. The refactor worked fine when REPL'd into the library project, but failed when in the context of the project using it. Presumably because it can't resolve the path against the project's root directory.

It would be very handy to support this kind of refactor, since it would allow me to change things in the library project and the project using it simultaneously.

@scramjet scramjet reopened this Mar 24, 2016
@expez expez changed the title File not found when using move form refactoring move form refactoring doesn't follow symlinks Mar 24, 2016
@expez
Copy link
Member

expez commented Mar 24, 2016

Sure, I can see how that can come in handy and it's probably harmless to fix this.

@scramjet
Copy link
Author

Great! Thanks

@scramjet
Copy link
Author

scramjet commented Aug 6, 2019

Just to keep this open (since I still run into it fairly often!): I can confirm that this is still a problem as of cli-refactor 2.4.0

@vemv
Copy link
Member

vemv commented Feb 10, 2022

This one turned out to be a bug in clj-refactor.el, not refactor-nrepl. clj-refactor.el should handle symlinks better.

I've closed the issue since now at least refactor-nrepl will fail more informatively.

(refactor-nrepl 3.3.2 / clj-refactor.el 3.3.2)

Will try to fix the bug clj-refactor.el side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants