nrepl / weasel

ClojureScript browser REPL using WebSockets
The Unlicense
324 stars 35 forks source link

Unable to reference required namespaces using alias #38

Closed jacobemcken closed 9 years ago

jacobemcken commented 9 years ago

Building on the example from weasel-example I've connected to my project from a lein repl using:

user=> (require 'weasel.repl.websocket)
nil
user=> (cemerick.piggieback/cljs-repl :repl-env (weasel.repl.websocket/repl-env))
<< started Weasel server on ws://127.0.0.1:9001 >>
Type `:cljs/quit` to stop the ClojureScript REPL
nil
cljs.user=> (ns rfgs.core)

I have added the files I use in this Gist.

Now I can deref the atom which I have defined in my project namespace rfgs.core just fine:

rfgs.core=> @game-state
{}

But when I try to access a namespace I have required using its alias like the following I get an error:

rfgs.core=> (string/trim "   a  ")
"Error evaluating:" (string/trim "   a  ") :as "string.trim.call(null,\"   a  \");\n"
#<ReferenceError: string is not defined>

Using full namespace works:

rfgs.core=> (clojure.string/trim "   a  ")
"a"

Starting the REPL like the following (copy-paste from Chestnut) lets me use aliases:

(let [repl-env (weasel.repl.websocket/repl-env :ip "0.0.0.0" :port 9001)]
  (cemerick.piggieback/cljs-repl :repl-env repl-env)
  (cemerick.piggieback/cljs-eval repl-env '(in-ns 'rfgs.core) {}))

But only until the first time I change namespace...

Is this a bug?... or can you provide information on how the environment needs to be setup to overcome this annoyance? I cant figure out if this is actually related to some of the other issues :smile:

jacobemcken commented 9 years ago

I have tested again using the latest Weasel release (I also upgraded ClojureScript, Piggieback, cljsbuild), and it is still an issue.

I've also tested using Cider (instead of lein repl) and when chancing the namespace using C-c M-n referencing the other namespaces via their aliases actually works... one time :smile: Then the REPL automatically switch back to cljs.user in the prompt.

I've updated the Gist with the files used to reproduce the problem.

jacobemcken commented 9 years ago

Hmm I think I found out what I was doing wrong... I should use in-ns to change namespace instead of ns. Now the namespace aliases works.

tomjakubowski commented 9 years ago

Closing, seems to work fine with in-ns (if you're using CIDER you can simply C-c M-n as well).