tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.75k stars 139 forks source link

Evaluating code when piggiebacked onto figwheel throws a "no such namespace" error #303

Open glittershark opened 6 years ago

glittershark commented 6 years ago

This is a weird one, because a couple months ago I had Piggieback onto figwheel via fireplace working fantastically - something in between updates to dependencies, moving to a different computer, and general Murphy's Law means that with a brand spanking new project, every time I evaluate code when Piggiebacked onto Figwheel I get the following error:

clojure.lang.ExceptionInfo: No such namespace: my-project.core, could not locate my_project/core.cljs, my_project/core.cljc, or JavaScript source providing "my-project.core" in file <cljs repl> {:tag :cljs/analysis-error}
        at clojure.core$ex_info.invokeStatic(core.clj:4744)
        at clojure.core$ex_info.invoke(core.clj:4744)
        at cljs.analyzer$error.invokeStatic(analyzer.cljc:697)
        at cljs.analyzer$error.invoke(analyzer.cljc:693)
        at cljs.analyzer$error.invokeStatic(analyzer.cljc:695)
        at cljs.analyzer$error.invoke(analyzer.cljc:693)
        at cljs.analyzer$analyze_deps.invokeStatic(analyzer.cljc:2122)
        at cljs.analyzer$analyze_deps.invoke(analyzer.cljc:2096)
        at cljs.analyzer$ns_side_effects.invokeStatic(analyzer.cljc:3461)
        at cljs.analyzer$ns_side_effects.invoke(analyzer.cljc:3456)
        at cljs.analyzer$analyze_STAR_$fn__4781.invoke(analyzer.cljc:3580)
        at clojure.lang.PersistentVector.reduce(PersistentVector.java:341)
        at clojure.core$reduce.invokeStatic(core.clj:6748)
        at clojure.core$reduce.invoke(core.clj:6731)
        at cljs.analyzer$analyze_STAR_.invokeStatic(analyzer.cljc:3580)
        at cljs.analyzer$analyze_STAR_.invoke(analyzer.cljc:3570)
        at cljs.analyzer$analyze.invokeStatic(analyzer.cljc:3604)
        at cljs.analyzer$analyze.invoke(analyzer.cljc:3587)
        at cljs.repl$evaluate_form$fn__9591.invoke(repl.cljc:508)
        at cljs.repl$evaluate_form.invokeStatic(repl.cljc:507)
        at cljs.repl$evaluate_form.invoke(repl.cljc:452)
        at cljs.repl$eval_cljs.invokeStatic(repl.cljc:625)
        at cljs.repl$eval_cljs.invoke(repl.cljc:618)
        at cljs.repl$repl_STAR_$read_eval_print__9730.invoke(repl.cljc:880)
        at cljs.repl$repl_STAR_$fn__9736$fn__9745.invoke(repl.cljc:922)
        at cljs.repl$repl_STAR_$fn__9736.invoke(repl.cljc:921)
        at cljs.compiler$with_core_cljs.invokeStatic(compiler.cljc:1252)
        at cljs.compiler$with_core_cljs.invoke(compiler.cljc:1241)
        at cljs.repl$repl_STAR_.invokeStatic(repl.cljc:885)
        at cljs.repl$repl_STAR_.invoke(repl.cljc:760)
        at cemerick.piggieback$run_cljs_repl.invokeStatic(piggieback.clj:169)
        at cemerick.piggieback$run_cljs_repl.invoke(piggieback.clj:155)
        at clojure.lang.AFn.applyToHelper(AFn.java:171)
        at clojure.lang.AFn.applyTo(AFn.java:144)
        at clojure.core$apply.invokeStatic(core.clj:661)
        at clojure.core$apply.invoke(core.clj:652)
        at cemerick.piggieback$evaluate.invokeStatic(piggieback.clj:259)
        at cemerick.piggieback$evaluate.invoke(piggieback.clj:255)
        at clojure.lang.Var.invoke(Var.java:381)
        at cemerick.piggieback$wrap_cljs_repl$fn__10282$fn__10284$fn__10285.invoke(piggieback.clj:291)
        at cemerick.piggieback$enqueue$fn__10268.invoke(piggieback.clj:247)
        at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__1157.invoke(interruptible_eval.clj:190)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

I did some hunting, and as far as I can tell this boils down to require not working properly from a cljs repl - this line is emitting something of the form (ns clj.user (:require my-project.core)), and if I run (require 'my-project.core) at the CLJS repl I get the exact same error.

Doing some more digging I'm guessing https://anmonteiro.com/2016/10/clojurescript-require-outside-ns/ might have something to do with it, but downgrading to a version of cljs before that patch landed didn't help.

One hack that had some impact (ie, allowed me to eval code) is the following patch:

diff --git a/plugin/fireplace.vim b/plugin/fireplace.vim
index 1799dd1..1d4fd99 100644
--- a/plugin/fireplace.vim
+++ b/plugin/fireplace.vim
@@ -263,7 +263,7 @@ function! s:repl.preload(lib) dict abort
             \ . ' (#''clojure.core/load-one '.qsym.' true true)'
             \ . ' (catch Exception e (when-not (find-ns '.qsym.') (throw e)))))'
     else
-      let expr = '(ns '.self.user_ns().' (:require '.a:lib.reload.'))'
+      let expr = "(in-ns '".a:lib.reload.')'
     endif
     try
       let result = clone.eval(expr, {'ns': self.user_ns()})

which 1. totally breaks namespace preloading 2. throws a compiler warning whenever referencing variables from the namespace and 3. breaks eval from clj, but may serve as a hook into a real solution to the problem

I'm at kind of a loss for this, and though it's entirely possible this is a bug with my config/setup and not with fireplace I'd love any advice/help you can give

Thanks for Fireplace + everything you do for Vim.

avescodes commented 6 years ago

I'm experiencing this error as well. I'll chime in if I find a solution. I might have to brush up on my viml chops..

AlexChalk commented 6 years ago

I experienced this error a few days ago—I converted my filename from kebab-case to snake_case and it went away.

Edit: I've also had luck fixing this by following up the :Piggieback command with a manual :Connect.

roper79 commented 6 years ago

+1

roper79 commented 6 years ago

Edit: I've also had luck fixing this by following up the :Piggieback command with a manual :Connect.

Does not work for me...

Zyxmn commented 5 years ago

I had similar errors , adding the src directory of the needed namespace under profiles (in my case, it was the dev profile) :source-path field did it for me . Didn't test adding it to the root :source-path field of the project.clj file though .

Even though the namespace was visible in the cljs-repl, due to the source-path settings in the respective build config for each build id.

Fireplace seems to check either profile source-path or the root source paths fields of project.clj to find the namespace.

tpope commented 5 years ago

Can anyone still reproduce this with a file that's in :source-path and that has underscores rather than hyphens in the name?