nrepl / weasel

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

Cider Namespace Problems #46

Closed martinklepsch closed 9 years ago

martinklepsch commented 9 years ago

Basically similar problems as in #26. cider-repl-set-ns properly changes the ns in the REPL but when I try to evaluate something from the buffer that contains the namespace I get:

WARNING: No such namespace: pani at line 53 /Users/martin/projects/chaf-light/src/cljs/chaf_light/firebase.cljs
WARNING: Use of undeclared Var pani/push! at line 53 /Users/martin/projects/chaf-light/src/cljs/chaf_light/firebase.cljs
WARNING: Use of undeclared Var chaf-light.firebase/fb at line 53 /Users/martin/projects/chaf-light/src/cljs/chaf_light/firebase.cljs
#<TypeError: undefined is not an object (evaluating 'pani.push_BANG_.call')>
eval code
eval@[native code]
http://localhost:3000/js/out/weasel/repl.js:25:469
http://localhost:3000/js/out/weasel/repl.js:34:4
G__20662__2@http://localhost:3000/js/out/cljs/core.js:31296:117
G__20662@http://localhost:3000/js/out/cljs/core.js:32000:24
http://localhost:3000/js/out/weasel/repl.js:153:75
fireListeners@http://localhost:3000/js/out/goog/events/eventtarget.js:285:27
dispatchEventInternal_@http://localhost:3000/js/out/goog/events/eventtarget.js:382:39
dispatchEvent@http://localhost:3000/js/out/goog/events/eventtarget.js:197:56
onMessage_@http://localhost:3000/js/out/goog/net/websocket.js:411:21
[native code]

The ns form of my namespace:

(ns chaf-light.firebase
  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [cljs.core.async :as async :refer [put! <!]]
            [pani.cljs.core :as pani]))

And what I tried to evaluate with C-c C-c:

(pani/push! fb [:messages] {:another-message "TOLO"})

Also gisted the nrepl debug messages from Cider's *nrepl-messages* buffer.

This is with Cider snapshot, weasel 0.6.0-SNAPSHOT, piggieback "0.1.6-SNAPSHOT, nrepl "0.2.7 and Cider for Emacs also just updated.

@bbatsov would you mind taking a look at the nrepl debug messages and tell me if those seem correct?

martinklepsch commented 9 years ago

@the-kenny suggested to do

(in-ns 'chad-light.firebase)
(pani/push fb [:messages] {:test "test"})

and that indeed seems to work.

tomjakubowski commented 9 years ago

I can't replicate this. C-C M-n swaps to the desired namespace in the REPL and I can access vars in that namespace from the REPL just fine.

May I ask how you got that nice debug message log? It'd be useful to compare my results with yours.

martinklepsch commented 9 years ago

@tomjakubowski does your namespace require anything and did you try evaluating a function that came with one of the required namespaces? (I'm not sure if this could make a difference, just checking)

Logging can be enabled like this

(setq nrepl-log-messages t)

https://github.com/clojure-emacs/cider#basic-configuration

tomjakubowski commented 9 years ago

I'm going to walk through what I've done step by step. Here's my namespace:

(ns weasel-example.example
  (:require [weasel.repl :as repl]))

(when-not (repl/alive?)
  (repl/connect "ws://localhost:9002"))

(defn alive? [] (repl/alive?))

(defn foo [] 5)

And here's the HTML for this application:

<html>
  <head>
    <meta charset="UTF-8">
    <title>Websocket browser-connected REPL through nREPL with Piggieback</title>
  </head>
  <body>
    <div id="content">
      <script type="text/javascript" src="out/goog/base.js"></script>
      <script type="text/javascript" src="weasel_example.js"></script>
      <input type="text" name="afield" id="afield"/>
      <script type="text/javascript">
        goog.require('weasel_example.example');
      </script>
    </div>
  </body>
</html>

After running lein cljsbuild once and piggiebacking, I open index.html in a browser and use C-c M-n to switch into the weasel-example.example namespace in CIDER. I can see a change in the namespace at my prompt. I can run (alive?) and (foo) without issue at the REPL. If I run (def bar 10), I can see that var from the REPL and also from the browser's JavaScript console.

Here's a log of my CIDER session.

martinklepsch commented 9 years ago

Thats not the issue I was describing, or tried to for that matter.

The issue I encountered was specifically related to running a function that I important from another namespace i.e. (:require [om.core :as om]) or something like this.

See previous messages for my actual ns form. Sorry for brevity I'm on the phone.

On Wednesday, February 11, 2015, Tom Jakubowski notifications@github.com wrote:

I'm going to walk through what I've done step by step. Here's my namespace:

(ns weasel-example.example (:require [weasel.repl :as repl]))

(when-not (repl/alive?) (repl/connect "ws://localhost:9002"))

(defn alive? )

(defn foo [] 5)

And here's the HTML for this application:

Websocket browser-connected REPL through nREPL with Piggieback

After running lein cljsbuild once and piggiebacking, I open index.html in a browser and use C-c M-n to switch into the weasel-example.example namespace in CIDER. I can run (alive?) and (foo) without issue at the REPL. If I run (def bar 10), I can see that var from the REPL and also from the browser's JavaScript console.

Here's a log of my CIDER session https://gist.github.com/tomjakubowski/cbdc8d4560a71af85610.

— Reply to this email directly or view it on GitHub https://github.com/tomjakubowski/weasel/issues/46#issuecomment-73931183.

— Martin http://martinklepsch.org http://martinklepsch.org?ref=email

tomjakubowski commented 9 years ago

Ah, I see, sorry! I can run (repl/alive?) from the REPL after changing into the example namespace too. See the addendum here: https://gist.github.com/tomjakubowski/cbdc8d4560a71af85610#file-addendum-txt

martinklepsch commented 9 years ago

I should be sorry, didn't see you were calling repl/alive?...

Yours:

(--->
  op  "eval"
  session  "6737b441-8f2a-4cd3-b13a-10473c81a07f"
  code  "(in-ns 'weasel-example.example)"
  id  "12"
)
[...]
(--->
  op  "eval"
  session  "6737b441-8f2a-4cd3-b13a-10473c81a07f"
  code  "(alive?)\n"
  id  "15"
)

Mine:

(--->
  op  "eval"
  session  "3bf51e12-8240-4885-811f-1807a8d7aaed"
  code  "(in-ns 'chaf-light.firebase)"
  id  "8"
)
[...]
(--->
  op  "load-file"
  session  "3bf51e12-8240-4885-811f-1807a8d7aaed"
  file  "(ns chaf-light.firebase)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(pani/push! fb [:messages] {:another-message \"TOLO\"})\n"
  file-path  "/Users/martin/projects/chaf-light/src/cljs/chaf_light/firebase.cljs"
  file-name  "firebase.cljs"
  id  "9"
)

This seems to be the difference. I'll check my versions and everything again. In the meantime maybe @bbatsov can give us a hint where that difference is coming from|?

martinklepsch commented 9 years ago

@tomjakubowski could you let me know which versions of piggieback, weasel & nrepl?

martinklepsch commented 9 years ago

@tomjakubowski is there a specific reason Weasel does not have an explicit dependency on piggieback?

bbatsov commented 9 years ago

@martinklepsch If you get this log when pressing C-x C-e you're not using the latest CIDER. Implementing eval in terms of load-file was removed about a month ago as it was causing problems with ClojureScript.

martinklepsch commented 9 years ago

@bbatsov cider-nrepl or emacs cider?

# Emacs
CIDER 0.9.0snapshot (package: 20150208.850) (Java 1.8.0_25, Clojure 1.6.0, nREPL 0.2.7)
# cider-nrepl
[cider/cider-nrepl "0.9.0-SNAPSHOT"]
martinklepsch commented 9 years ago

I stil have no idea what the issue was but rm -rf ~/.m2/repository/cider fixed it. Thanks everyone.

tomjakubowski commented 9 years ago

@martinklepsch there's no Piggieback dependency because you don't strictly need to use Piggieback to use Weasel. For example, you might want to launch a Weasel REPL from a script using (cljs.repl/repl (weasel.repl.websocket/repl-env)), or something.