Fork me on GitHub
#cider
<
2017-04-11
>
dpsutton02:04:48

i think you're in luck

dpsutton02:04:17

@jfntn because all the jack in clojure script does is set up a new client and then call some piggy back (or whatever inits your cljs repl)

dpsutton02:04:36

so all you really have to do is just jack in and then invoke whatever you want

dpsutton02:04:19

the magic happens inside cider-create-sibling-cljs-repl. All it does is read the info from the clj buffer and then create another client on the same ports

dpsutton02:04:33

the magic happens in this line: (cljs-proc (apply #'nrepl-start-client-process client-process-args)) which just creates a new client process on the same stuff. And then there's the comment that should give you the most confidence to just create clj repls and init one for cljs and leave the other alone:

dpsutton02:04:44

;; The new connection has now been bumped to the top, but it's still a
      ;; Clojure REPL!  Additionally, some ClojureScript REPLs can actually take
      ;; a while to start (some even depend on the user opening a browser).
      ;; Meanwhile, this REPL will gladly receive requests in place of the
      ;; original Clojure REPL.  Our solution is to bump the original REPL back
      ;; up the list, so it takes priority on Clojure requests.

dpsutton02:04:06

then, the remaining code is very straight forward. It sets the connection as default (by putting it at the beginning of the connection list, sends a message that the cljs repl is being created, and then the code following that just invokes whatever code is required to get your cljs repl up:

(cider-nrepl-send-request
       `("op" "eval"
         "ns" ,(cider-current-ns)
         "code" ,cljs-repl-form)
       (cider-repl-handler (current-buffer)))
      (cider--offer-to-open-app-in-browser nrepl-server-buffer)

dpsutton02:04:40

so if i remember what you are wanting to do, you want to create a clojure repl under one profile and then a clojurescript repl under another. And all you need to do is jack in with a profile and then jack in with another profile. In the one you want to be cljs, invoke whatever cljs stuff you need. For piggyback this is simply: (cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))

jfntn03:04:09

dpsutton that’s really helpful! I’ll have to get back to this tomorrow, but I think I just assumed I didn’t want to create a new client like the sibling code does, which must be why it didn’t block until the buffer was ready and the rest didn’t work. Will report back, thanks for the detailed explanation!

dpsutton03:04:50

feel free to message me tomorrow. i'll be at work but i've dug through some of this before

jfntn03:04:30

appreciate it, thanks!

bozhidar17:04:09

@qqq you might also consider filing a ticket - I don’t usually have time to follow discussions here, but I usually read tickets and respond to them

ag21:04:01

has anyone ever had problems of using cider-refresh with .cljc files that have some reader conditionals? code builds, repl starts with no problems, but then if I do cider-refresh - it complains ;(

ag21:04:55

this is probably not a bug in cider. probably I’m doing something wrong, but I can’t figure out the cause

dpsutton21:04:02

what is it complaining about?

dpsutton21:04:20

cljc support is rather spotty. just wondering

ag22:04:33

@dominicm does that mean that I should also see some problems if I manually try to use clojure.tools.namespace.repl :refer [refresh] ?

ag22:04:40

I’m not seeing any

ag22:04:16

so I’m trying to run cider-refresh, it complains that it can’t load .cljc namespace. and then apparently repl kinda breaks - I can’t switch namespaces, evaluating anything does not show anything ;(

ag23:04:01

it turn out to be cider-refresh problem after all - I can’t replicate it with :relooad-all true

rmuslimov23:04:34

@ag I’m happy with cider-refresh stuff, moreover added stuartsierra/component features there and it works great for reloading. and I believe you should fix that issue with cljc

jfntn23:04:23

@ag looks like you narrowed it down to some elisp issue? The elisp debugger should be able to get some context if you can afford the yak shave!

ag23:04:50

@jfntn it throws java error though

rmuslimov23:04:05

sorry, I missed beginning of conversation

rmuslimov23:04:36

> @ag repl starts with no problems, but then if I do cider-refresh - it complains ;(. What is the exception you’re seeing there. I’m working with cljc no issue so far

rmuslimov23:04:14

you’ve tried lein clean already, right? and restarting the repl

ag23:04:57

so I have some .cjc files with specs and generators, when I jack-in - everything is fine. If I try to use cider-refresh - it complains “error loading foo namespace” where foo is that .cljc file

rmuslimov23:04:31

and what happens if you go to that file and call C-c C-k there?

ag23:04:35

I’m not using lein it’s a boot project - but I don’t think that’s the issue

ag23:04:09

it throws

java.lang.AssertionError
   Assert failed: Second arg to such-that must be a generator (generator? gen)

           generators.cljc:  346  clojure.test.check.generators$such_that/invokeStatic
           generators.cljc:  328  clojure.test.check.generators$such_that/invoke
                  AFn.java:  160  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  646  clojure.core/apply
                  core.clj:  641  clojure.core/apply
                   gen.clj:   94  clojure.spec.gen/eval12564/such-that
               RestFn.java:  436  clojure.lang.RestFn/invoke
                  spec.clj:  272  clojure.spec/gensub
                  spec.clj:  264  clojure.spec/gensub
                  spec.clj:  288  clojure.spec/gen
                  spec.clj:  277  clojure.spec/gen
                  spec.clj:  287  clojure.spec/gen
                  spec.clj:  277  clojure.spec/gen
                  AFn.java:  154  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
             Compiler.java: 3652  clojure.lang.Compiler$InvokeExpr/eval
             Compiler.java: 3651  clojure.lang.Compiler$InvokeExpr/eval
             Compiler.java: 3651  clojure.lang.Compiler$InvokeExpr/eval
             Compiler.java:  451  clojure.lang.Compiler$DefExpr/eval
             Compiler.java: 6932  clojure.lang.Compiler/eval
             Compiler.java: 7379  clojure.lang.Compiler/load
                   RT.java:  372  clojure.lang.RT/loadResourceScript
                   RT.java:  363  clojure.lang.RT/loadResourceScript
                   RT.java:  453  clojure.lang.RT/load
                   RT.java:  419  clojure.lang.RT/load
                  core.clj: 5893  clojure.core/load/fn
                  core.clj: 5892  clojure.core/load
                  core.clj: 5876  clojure.core/load
               RestFn.java:  408  clojure.lang.RestFn/invoke
                  core.clj: 5697  clojure.core/load-one
                  core.clj: 5692  clojure.core/load-one
                  core.clj: 5737  clojure.core/load-lib/fn
                  core.clj: 5736  clojure.core/load-lib
                  core.clj: 5717  clojure.core/load-lib
               RestFn.java:  142  clojure.lang.RestFn/applyTo
                  core.clj:  648  clojure.core/apply
                  core.clj: 5774  clojure.core/load-libs
                  core.clj: 5758  clojure.core/load-libs
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  648  clojure.core/apply
                  core.clj: 5796  clojure.core/require
                  core.clj: 5796  clojure.core/require
               RestFn.java:  421  clojure.lang.RestFn/invoke
                reload.clj:   35  cider.inlined-deps.toolsnamespace.v0v3v0-alpha3.clojure.tools.namespace.reload/track-reload-one
                reload.clj:   21  cider.inlined-deps.toolsnamespace.v0v3v0-alpha3.clojure.tools.namespace.reload/track-reload-one
                reload.clj:   52  cider.inlined-deps.toolsnamespace.v0v3v0-alpha3.clojure.tools.namespace.reload/track-reload
                reload.clj:   43  cider.inlined-deps.toolsnamespace.v0v3v0-alpha3.clojure.tools.namespace.reload/track-reload
               refresh.clj:  155  cider.nrepl.middleware.refresh/refresh-reply/fn
                  core.clj: 1941  clojure.core/binding-conveyor-fn/fn
                  AFn.java:  154  clojure.lang.AFn/applyToHelper
               RestFn.java:  132  clojure.lang.RestFn/applyTo
                Agent.java:  114  clojure.lang.Agent$Action/doRun
                Agent.java:  163  clojure.lang.Agent$Action/run
   ThreadPoolExecutor.java: 1142  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  617  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  745  java.lang.Thread/run

1. Caused by clojure.lang.Compiler$CompilerException

ag23:04:29

interestingly there’s nothing wrong with the code, when evaluated the first time (before refresh) it works just fine

rmuslimov23:04:03

may be it’s just not load when you run the repl?

rmuslimov23:04:27

is test file you working with? if you run tests they work?

ag23:04:07

I think this is something to do with com.gfredericks/test.chuck

jfntn23:04:19

I’d make sure there I don’t have a faulty top-level form, but I’ve also ran into situations where some libraries make reloading impossible, seems to happen more often on cljc projects

rmuslimov23:04:47

I don’t think cljc is source of the issue here. seems like mistyping or something similar

ag23:04:36

so when I do (require ’[foo :reload-all true]) in the terminal it works just fine. If I try to do the same thing after cider-refresh - it complains ;(

ag23:04:59

it breaks, the only way to fix it - to restart the repl

ag23:04:07

which is quite annoying

jfntn23:04:46

isn’t the difference that when doing it manually you only reload foo, but cider tries to reload all namespaces?

rmuslimov23:04:35

cider just call (require '[clojure.tools.namespace.repl :refer [refresh]) (refresh). Not sure if it may help

rmuslimov23:04:25

> isn’t the difference that when doing it manually you only reload foo, but cider tries to reload all namespaces? probably, yes

ag23:04:05

that’s the thing - when I call refresh manually - nothing happens, everything works as expected. But when I do cider-refresh, it complains about that single .cljc file

ag23:04:08

¯\(ツ)

rmuslimov23:04:03

most likely way you do when I call refresh manually is not loading this cljc file. In contrast what cider-refresh do, which is also trivial and calls clojure.tools.namespace.repl :refer [refresh] function

ag23:04:06

that’s what I’m saying - if I execute clojure.tools.namespace.repl/refresh in the repl, it works just fine.