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

Error starting CLJS REPL with Boot project #1881

Closed
ieure opened this issue Nov 19, 2016 · 12 comments
Closed

Error starting CLJS REPL with Boot project #1881

ieure opened this issue Nov 19, 2016 · 12 comments

Comments

@ieure
Copy link

ieure commented Nov 19, 2016

Expected behavior

I should get a working CLJS REPL when I run cider-jack-in-clojurescript.

Actual behavior

I get this stack trace:


  Show: Clojure Java REPL Tooling Duplicates All  (13 frames hidden)

1. Unhandled java.lang.ClassNotFoundException
   cemerick.piggieback

       URLClassLoader.java:  381  java.net.URLClassLoader/findClass
   DynamicClassLoader.java:   69  clojure.lang.DynamicClassLoader/findClass
          ClassLoader.java:  424  java.lang.ClassLoader/loadClass
   DynamicClassLoader.java:   77  clojure.lang.DynamicClassLoader/loadClass
          ClassLoader.java:  357  java.lang.ClassLoader/loadClass
                Class.java:   -2  java.lang.Class/forName0
                Class.java:  348  java.lang.Class/forName
                   RT.java: 2154  clojure.lang.RT/classForName
                   RT.java: 2163  clojure.lang.RT/classForName
             Compiler.java: 1017  clojure.lang.Compiler$HostExpr/maybeClass
             Compiler.java:  795  clojure.lang.Compiler$HostExpr/access$600
             Compiler.java: 6662  clojure.lang.Compiler/macroexpand1
             Compiler.java: 6692  clojure.lang.Compiler/macroexpand
             Compiler.java: 6766  clojure.lang.Compiler/eval
             Compiler.java: 6745  clojure.lang.Compiler/eval
                  core.clj: 3081  clojure.core/eval
                  main.clj:  240  clojure.main/repl/read-eval-print/fn
                  main.clj:  240  clojure.main/repl/read-eval-print
                  main.clj:  258  clojure.main/repl/fn
                  main.clj:  258  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  630  clojure.core/apply
                  core.clj: 1868  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   85  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  222  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  190  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/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

The REPL itself seems to sort of work, but any CIDER commands fail with a fresh exception.

Steps to reproduce the problem

  1. Run boot -d seancorfield/boot-new new -t hoplon -n address-book
  2. Open the one CLJS file in the template project:C-x C-f address-book/cljs/index.cljs.hl
  3. Run M-x clojurescript-mode (if it isn't set up to .cljs.hl files already).
  4. Press C-c M-J

CIDER version information

;; CIDER 0.14.0 (Berlin), nREPL 0.2.12
;; Clojure 1.8.0, Java 1.8.0_51

Lein/Boot version

Boot 2.6.0

Emacs version

Emacs 25.5.1

Operating system

macOS 10.12.1 "Sierra"

@dpsutton
Copy link
Contributor

dpsutton commented Dec 1, 2016

Ok. So I'm looking into this.

(cider-nrepl-send-request
 (list "op" "eval"
       "ns" (cider-current-ns)
       "session" nrepl-session
       "code" cider-cljs-lein-repl)
 (cider-repl-handler (current-buffer)))

This is the code in the callback function that begins the clojurescript repl. It gets the var cider-cljs-lein-repl var from the assoc list, but already the variable name is telling us what's wrong: its tied to lein.

You set a default value for how to conjure up a clojurescript repl, and I've never really liked this style. And here, we aren't using lein and we must know how to crank up a repl. Apparently the thing we want is from a library called boot-cljs-repl. And since we don't have this, there doesn't seem to be an easy way to get a clojurescript repl from this project.

I'm new to boot and cljs, but apparently the standard way to interact with this is to jack-in and then run (dev), one of the defined tasks. This will crank up the watcher and compile files, etc.

@dpsutton
Copy link
Contributor

dpsutton commented Dec 1, 2016

If boot tasks can be counted on to always have a task called dev, we could determine that we are in a boot project and launch the dev task. Otherwise, if these tasks are arbitrarily named, I'm not sure how we could reliably launch anything with boot.

@dpsutton
Copy link
Contributor

dpsutton commented Dec 1, 2016

And there's this from a boot library

The cljs-repl-env task

There is a cljs-repl-env task that doesn't start a new nREPL server which you can use via cider-jack-in. An example is shown below.

(deftask dev []
  (comp (watch)
        (cljs-repl-env) ; order is important!!
        (cljs)))
M-x cider-jack-in
boot.user=> (def p (future (boot (dev))))
...
boot.user=> (start-repl)

and I'm not totally sure how to interpret that

@Malabarba
Copy link
Member

I had a scheme that worked for this (with boot) back when I did a bit of cljs. I used the same library you're using. I'll try to dig it up.

As for trying to be smart, the best we can do is have a separate variable for boot and let the user decide what code gets run. Cljs repls are way too numerous (and quite a bit of manual) for us to provide a catch all solution. That's why we wrote that original lein-cljs-repl variable. We people instructions on how we know it can work, but we can't promise it will fit into every ad-hoc method out there.

@bbatsov
Copy link
Member

bbatsov commented Dec 18, 2016

I think @Malabarba is right - probably we need a boot-cljs-repl variable as well. @dpsutton if you'd like you can implement this - should be pretty straightforward.

@dpsutton
Copy link
Contributor

I'm not sure that I really like the variables. With the current one for lein, I've run into issues. For instance, I set it to the one I most often use. I clone a project which uses a different repl type. My interaction isn't seamless. I try to use a directory local var but don't really know them that well.

I like when it works smoothly but it seems to commit you to a certain type of repl for all projects. But I agree it works for the most part. Thoughts?

@bbatsov
Copy link
Member

bbatsov commented Dec 28, 2016

I like when it works smoothly but it seems to commit you to a certain type of repl for all projects. But I agree it works for the most part. Thoughts?

Well, that's the Emacs way - you come up with some sensible defaults and use dir-local variables for projects that don't adhere to the defaults. I definitely don't want us to start inspecting the project files to figure out what would be the best way to start a cljs repl.

@arichiardi
Copy link
Contributor

Ran into this problem and I can work around it by using the following .dir-locals.el:

((nil . ((cider-boot-parameters . "dev-web")
         (cider-cljs-lein-repl . "((eval 'adzerk.boot-cljs-repl/start-repl))"))))

Of course it would best to have a better name and defcustom for boot (and grandle?) builds.
I actually so like .dir-locals.el configuration, it is good because you can have different ones for each src subfolder: one for src/my-lein-prj and one for my-boot-prj.

@arichiardi
Copy link
Contributor

On second read, it looks like the problem above is different, about the rename, the commit is this: 313a0df

And probably we should add a clause for adzerk.boot-cljs-repl/start-repl in there.

@arichiardi
Copy link
Contributor

The problem with the template is exactly that it does not launch or even hints at boot-cljs-repl, see here: https://github.com/hoplon/hoplon-template/blob/master/src/leiningen/new/hoplon/build.boot

My dev-web task does:

(deftask dev-web []
  (init-web)
  (comp (serve)
        (watch)
        (cljs-devtools)
        (reload :client-opts {:debug true})
        (cljs-repl :nrepl-opts {:port 5088})
        (cljs :source-map true
              :optimizations :none
              :compiler-options {:external-config
                                 {:devtools/config {:features-to-install [:formatters :hints]
                                                    :fn-symbol "λ"
                                                    :print-config-overrides true}}})))

@arichiardi
Copy link
Contributor

If we wanted to be really fancy here, we could inject [adzerk/boot-cljs-repl "0.3.3" :scope "test"] as dependency and then call the init as per above.

@arichiardi
Copy link
Contributor

Actually, not solved, it is still calling the rhino repl:

org.mozilla.javascript.EcmaError: ReferenceError: "console" is not defined. (rhino.clj#41)

arichiardi added a commit to arichiardi/cider that referenced this issue Jan 25, 2017
…boot-cljs-repl`

This patch firstly adds two more defcustoms, `cider-cljs-boot-repl` and
`cider-cljs-gradle-repl`, that will be queried by the
`cider-cljs-repl-form` function on `cider-jack-in-clojurescript`

Secondly, it adds a clause in `cider--cljs-repl-types` that allows to
automatically call `adzerk.boot-cljs-repl/start-repl` in case `boot` is
the project type.
arichiardi added a commit to arichiardi/cider that referenced this issue Jan 26, 2017
…boot-cljs-repl`

This patch firstly adds two more defcustoms, `cider-cljs-boot-repl` and
`cider-cljs-gradle-repl`, that will be queried by the
`cider-cljs-repl-form` function on `cider-jack-in-clojurescript`

Secondly, it adds a clause in `cider--cljs-repl-types` that allows to
automatically call `adzerk.boot-cljs-repl/start-repl` in case `boot` is
the project type.
arichiardi added a commit to arichiardi/cider that referenced this issue Jan 26, 2017
…boot-cljs-repl`

This patch firstly adds two more defcustoms, `cider-cljs-boot-repl` and
`cider-cljs-gradle-repl`, that will be queried by the
`cider-cljs-repl-form` function on `cider-jack-in-clojurescript`

Secondly, it adds a clause in `cider--cljs-repl-types` that allows to
automatically call `adzerk.boot-cljs-repl/start-repl` in case `boot` is
the project type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants