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

Tutorial on usage with shadow-cljs #2

Closed
DogLooksGood opened this issue Aug 15, 2019 · 10 comments
Closed

Tutorial on usage with shadow-cljs #2

DogLooksGood opened this issue Aug 15, 2019 · 10 comments

Comments

@DogLooksGood
Copy link

DogLooksGood commented Aug 15, 2019

It will be nice to be able to use with shadow-cljs.

@davidpham87
Copy link

Agree for shadow-cljs. Although I use it with emacs Cider, but it failed last time I tried it.

@rksm
Copy link
Member

rksm commented Aug 31, 2019

Support for shadow-cljs is now implemented. Since suitable is part of CIDER 0.22.0 it's enough to "jack-in" - completions are then computed with suitable and cljs-tooling. I leave this open until I have time to update the README and make a little demo video.

@davidpham87
Copy link

What about just connect to shadow-cljs, through cider-connect-cljs?

@rksm
Copy link
Member

rksm commented Sep 1, 2019

Yep, that should work as well. There is no setup code needed, everything will just be dealt with when the editor sends an nrepl completion message. The only reason why shadow-cljs needed special handling at all is that the internals for accessing the cljs repl and compilation environment it different.

@davidpham87
Copy link

davidpham87 commented Sep 2, 2019

hum... I could not make it work, unfortunately...

I tried

(.q js/document)

Set my cursor just after q and hit tab and got this error message:

1. Unhandled java.lang.IllegalArgumentException
   No implementation of method: :-evaluate of protocol:
   #'cljs.repl/IJavaScriptEnv found for class: nil

          core_deftype.clj:  583  clojure.core/-cache-protocol-fn
          core_deftype.clj:  575  clojure.core/-cache-protocol-fn
                 repl.cljc:  122  cljs.repl$fn__6437$G__6389__6448/invoke
                 repl.cljc:  132  cljs.repl$evaluate/invokeStatic
                 repl.cljc:  131  cljs.repl$evaluate/invoke
                  Var.java:  399  clojure.lang.Var/invoke
    complete_for_nrepl.clj:  108  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/ensure-suitable-cljs-is-loaded/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    complete_for_nrepl.clj:  106  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/ensure-suitable-cljs-is-loaded
    complete_for_nrepl.clj:  104  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/ensure-suitable-cljs-is-loaded
    complete_for_nrepl.clj:  154  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/handle-completion-msg!
    complete_for_nrepl.clj:  137  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/handle-completion-msg!
    complete_for_nrepl.clj:  169  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/complete-for-default-cljs-env
    complete_for_nrepl.clj:  162  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/complete-for-default-cljs-env
    complete_for_nrepl.clj:  201  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/complete-for-nrepl
    complete_for_nrepl.clj:  196  cider.nrepl.inlined-deps.suitable.v0v2v5.suitable.complete-for-nrepl/complete-for-nrepl
              complete.clj:   15  cider.nrepl.middleware.complete/cljs-complete
              complete.clj:   11  cider.nrepl.middleware.complete/cljs-complete
              complete.clj:   23  cider.nrepl.middleware.complete/complete
              complete.clj:   17  cider.nrepl.middleware.complete/complete
              complete.clj:   34  cider.nrepl.middleware.complete/complete-reply
              complete.clj:   33  cider.nrepl.middleware.complete/complete-reply
        error_handling.clj:  160  cider.nrepl.middleware.util.error-handling/eval30365/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
              complete.clj:   46  cider.nrepl.middleware.complete/handle-complete
              complete.clj:   45  cider.nrepl.middleware.complete/handle-complete
                  Var.java:  388  clojure.lang.Var/invoke
                 nrepl.clj:  116  cider.nrepl/wrap-complete/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
               session.clj:  326  nrepl.middleware.session/add-stdin/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  102  cider.nrepl/wrap-apropos/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
               nrepl04.clj:   58  shadow.cljs.devtools.server.nrepl04/shadow-init/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  466  cider.nrepl/wrap-xref/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  162  cider.nrepl/wrap-enlighten/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  256  cider.nrepl/wrap-ns/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
     fake_piggieback04.clj:   30  cider.piggieback/wrap-cljs-repl/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  437  cider.nrepl/wrap-tracker/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  199  cider.nrepl/wrap-inspect/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                caught.clj:   97  nrepl.middleware.caught/wrap-caught/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 print.clj:  234  nrepl.middleware.print/wrap-print/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
                 nrepl.clj:  290  cider.nrepl/wrap-out/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
               session.clj:  272  nrepl.middleware.session/session/fn
            middleware.clj:   16  nrepl.middleware/wrap-conj-descriptor/fn
               nrepl04.clj:  150  shadow.cljs.devtools.server.nrepl04/start/fn
                server.clj:   18  nrepl.server/handle*
                server.clj:   15  nrepl.server/handle*
                server.clj:   27  nrepl.server/handle/fn
                  core.clj: 2030  clojure.core/binding-conveyor-fn/fn
                  AFn.java:   18  clojure.lang.AFn/call
           FutureTask.java:  264  java.util.concurrent.FutureTask/run
   ThreadPoolExecutor.java: 1128  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  628  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  834  java.lang.Thread/run

By the way, to make it work with cider, you should also add the dependency in your .shadow-cljs.edn file.

@rksm
Copy link
Member

rksm commented Sep 2, 2019

Thanks for the report!

By the way, to make it work with cider, you should also add the dependency in your .shadow-cljs.edn file.

You mean when starting the repl not with cider but with shadow-cljs watch a la https://shadow-cljs.github.io/docs/UsersGuide.html#nREPL ? Will add this to the readme.

Regarding the bug, can you please share your setup steps? shadow-cljs watch and then connect in cider?

Thanks!

@davidpham87
Copy link

davidpham87 commented Sep 2, 2019

Dear @rksm,

You mean when starting the repl not with cider but with shadow-cljs watch a la https://shadow-cljs.github.io/docs/UsersGuide.html#nREPL ? Will add this to the readme.

This is exactly what I meant.

Regarding the bug, can you please share your setup steps? shadow-cljs watch and then connect in cider?

Exactly my set up. I choose shadow-selectas option when I connect.

@alendit
Copy link

alendit commented Jan 25, 2020

So, how do you use suitable with shadow-cljs? I tried

npx shadow-cljs -d cider/piggieback:0.4.2 -d cider/cider-nrepl:0.23.0 -d org.rksm/suitable:0.3.2  watch dev

but I doesn't appear to do anything.

EDIT: nvm, apparently it works in CIDER but not in Calva.

@rksm
Copy link
Member

rksm commented Jan 25, 2020

Sorry, for Calva I have no clue, you would need to get in touch with @PEZ

For cider I just successfully tried the following steps:

  1. npx create-cljs-project suitable-test; cd suitable-test

  2. Create / modify:

shadow-cljs.edn

{:source-paths
 ["src/dev"
  "src/main"
  "src/test"]

 :dev-http {8080 "public"}

 :dependencies
 [[cider/cider-nrepl "RELEASE"]]

 :builds
 {:frontend
  {:target :browser
   :modules {:main {:init-fn foo.main/init}}
   }}}

src/main/foo/main.cljs

(ns foo.main)

(defn init []
  (println "Hello World"))

public/index.html

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>fooo</title>
  </head>
  <body>
    <div id="root">hello</div>
    <script src="/js/main.js"></script>
  </body>
</html>
  1. shadow-cljs watch frontend

output

shadow-cljs - config: /home/robert/projects/clojure/2020-01-21_shadow_cljs_issue/suitable-test/shadow-cljs.edn  cli version: 2.8.83  node: v12.13.0
shadow-cljs - HTTP server available at http://localhost:8080
shadow-cljs - server version: 2.8.83 running at http://localhost:9630
shadow-cljs - nREPL server started on port 44617
shadow-cljs - watching build :frontend
[:frontend] Configuring build.
[:frontend] Compiling ...
[:frontend] Build completed. (135 files, 134 compiled, 0 warnings, 6.78s)
...
  1. Open browser http://localhost:8080

  2. cider-connect-cljs

-> shadow-select
-> select host localhost
-> select port 44617 (should be found by cider automatically, if not see output above)

  1. in emacs repl or buffer (js/document.|) + completion command should produce sth like

2020-01-25_suitable_shadow_cljs

Instead of running a repl manually you can also use cider-jack-in-cljs.

@rksm
Copy link
Member

rksm commented Jan 28, 2020

Closing this now, should there be other issues please reopen or file a new issue.

@rksm rksm closed this as completed Jan 28, 2020
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

4 participants