Fork me on GitHub
#shadow-cljs
<
2017-11-09
>
mitchelkuijpers08:11:44

Yeah they actually fixed that ^^

thheller08:11:50

does it work properly?

mitchelkuijpers08:11:56

In combination with shadow-cljs not so much

mitchelkuijpers08:11:13

What editor do you use btw? Just out of curiosity

mitchelkuijpers08:11:26

Our team is spacemacs and vim 😛

thheller08:11:36

what doesn’t work?

mitchelkuijpers08:11:22

Ok when I connect the cider middleware get's properly loaded because I don't get warnings anymore

mitchelkuijpers08:11:40

And connecting by using:

(shadow.cljs.devtools.api/nrepl-select :app)
works

mitchelkuijpers08:11:01

And I can try stuff out in that repl

thheller08:11:36

does is actually eval in JS?

thheller08:11:51

(js/alert "foo") or so?

mitchelkuijpers08:11:58

Yes I can do (.log js/console "hello") that works

mitchelkuijpers08:11:16

but when I do it gives me the following error:

error in process filter: nrepl--dispatch-response: [nREPL] No response handler with id 0 found
error in process filter: [nREPL] No response handler with id 0 found

mitchelkuijpers08:11:40

But it does work

thheller08:11:53

can you tell me the emacs commands you use?

mitchelkuijpers08:11:33

I use cider-connect and then localhost and then the correct port

mitchelkuijpers09:11:31

and i use cider-eval-last-sexp to run stuff or cider-eval-buffer but for the last one I get TBD log message

mitchelkuijpers09:11:53

If you want to try it out you could use spacemacs, then cider works out of the box

mitchelkuijpers09:11:13

And I got this error when trying to eval a ns:

Nov 09, 2017 9:58:51 AM clojure.tools.logging$eval454$fn__457 invoke
SEVERE: Unhandled REPL handler exception processing message {:ns user, :op eval, :code (ns cljs.user
  (:require
   [fulcro.client.core :as uc]
   [om.next :as om]

   [atlas-crm.ui.entry-points.spa :as core]
   [atlas-crm.ui.root :as root]

   [cljs.pprint :refer [pprint]]
   [fulcro.client.logging :as log]
   [clojure.spec.test.alpha :as stest]
   [clojure.spec.alpha :as s]
   [expound.alpha :as expound]))
, :file /home/mitchel/Development/atlas-crm-next/dev/client/cljs/user.cljs, :line 1, :column 1, :session 56407dcf-efa5-4ab4-8991-457ba97aa97c, :id 28}
java.lang.IllegalArgumentException: No matching clause: :repl/error
	at shadow.cljs.devtools.server.nrepl$do_cljs_eval.invokeStatic(nrepl.clj:54)
	at shadow.cljs.devtools.server.nrepl$do_cljs_eval.invoke(nrepl.clj:23)
	at shadow.cljs.devtools.server.nrepl$cljs_eval$fn__25937.invoke(nrepl.clj:139)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__25437.invoke(middleware.clj:22)
	at clojure.tools.nrepl.middleware.session$add_stdin$fn__25769.invoke(session.clj:229)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__25437.invoke(middleware.clj:22)
	at clojure.tools.nrepl.middleware.load_file$wrap_load_file$fn__25818.invoke(load_file.clj:79)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__25437.invoke(middleware.clj:22)
	at cider.nrepl$wrap_stacktrace$fn__1100.invoke(nrepl.clj:365)
	at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__25437.invoke(middleware.clj:22)
	at cider.nrepl$wrap_format$fn__1026.invoke(nrepl.clj:188)
.....

thheller09:11:40

hold on, trying to get this emacs thing running

thheller09:11:46

I think I have it connected

thheller09:11:04

how do I get an actual REPL window?

thheller09:11:26

cider-connect seemed to work but its just showing something in the status bar

mitchelkuijpers09:11:44

do you have vanilla emacs?

mitchelkuijpers09:11:55

You have to open the buffer of the repl

mitchelkuijpers09:11:28

I think haven't used emacs shortcuts in a long time

mitchelkuijpers09:11:45

spacemacs has vim shortcuts parrot

thheller09:11:17

yeah using spacemacs + vim

mitchelkuijpers09:11:41

spacebar and then b b opens your buffers

mitchelkuijpers09:11:23

if you have a clojurescript file open you can use , e e to eval the last sexp

mitchelkuijpers09:11:37

and you can use , e b to eval a buffer

thheller09:11:11

seeing the error

mitchelkuijpers09:11:11

I was thinking do I need to configure piggieback or the fake on of shadow-cljs somehow? or is that automatic?

thheller09:11:22

that should be automatic

thheller09:11:43

sec, trying to get this working so I can debug it properly

thheller09:11:00

the clojure part seems to be working?

thheller09:11:23

how do I trigger autocomplete or so?

thheller09:11:35

[10:26:55,107] nrepl-receive {:ns cljs.user, :op eval, :code (js/alert "foo")
, :file *cider-repl localhost*<2>, :line 62, :column 12, :id 42}
[10:26:56,696] nrepl-send {:id 0, :session 9aa5ab6c-1f55-4a43-bc7d-1b9ad01a3d4f, :type :repl/result, :value nil, :ns cljs.user}
[10:26:56,696] nrepl-send {:id 42, :session 9aa5ab6c-1f55-4a43-bc7d-1b9ad01a3d4f, :status #{:done}}

thheller09:11:49

alright. seems like I send the wrong :id back

thheller09:11:58

should be 42

mitchelkuijpers09:11:58

Btw autocomplete you get after typing foo/f but you need to eval the ns so that it works

thheller09:11:07

trying to make sense of this nrepl code

thheller09:11:28

for some reason it doesn’t set the id altough I pass it in

thheller09:11:12

ok .. just removed the nrepl fn and create the response myself

thheller09:11:30

sort of works now

thheller09:11:38

cljs.user> (js/console.log "foo")
"nil"

thheller09:11:46

dunno why thats quoted though?

mitchelkuijpers09:11:04

That should not be quoted 😛

thheller09:11:15

cljs.user> (+ 1 2)
"3"

thheller09:11:26

ah might be because everything I get back is a string from the browser

mitchelkuijpers09:11:48

That makes sense

thheller09:11:55

[10:44:25,122] nrepl-receive {:ns "cljs.user", :op "eval", :code "(js/console.log \"foo\")\n", :file "*cider-repl localhost*", :line 52, :column 12, :id "16"}
[10:44:25,134] nrepl-send 16 {:type :repl/result, :value "nil", :id "16", :ns "cljs.user", :session "6fe7ed2f-85a6-4076-a7dd-5dfbe4aa0928"}
[10:44:25,134] nrepl-send 16 {:status #{:done}, :id "16", :session "6fe7ed2f-85a6-4076-a7dd-5dfbe4aa0928"}

thheller09:11:19

this is the flow, seems like it doesn’t like setting value to a string

thheller09:11:24

and just encodes it again?

thheller09:11:00

user-error: 'cider-load-buffer' needs a ClojureScript REPL.
If you don't know what that means, you probably need to jack-in (', "').

thheller09:11:04

what does that mean?

mitchelkuijpers09:11:04

Then it doesnt detect that you have a clojurescript buffer

mitchelkuijpers09:11:16

It does that with some weird var

mitchelkuijpers09:11:31

I fixed it by running a command in the cljs repl and then after that it did know

thheller09:11:08

user> (shadow.cljs.devtools.api/nrepl-select :browser)
To quit, type: :repl/quit
[:selected :browser]
cljs.user> (js/console.log "foo")
"nil"
cljs.user> (js/console.log "bar")
"nil"

thheller09:11:16

that seems to work fine

thheller09:11:34

but trying any commands from the menu complains

mitchelkuijpers09:11:24

can you check cider-connection-browser?

mitchelkuijpers09:11:41

For me that shows:

REPL                           Host             Port    Project          Type

* *cider-repl localhost*         localhost         3002   atlas-crm-next   ClojureScript
  *cider-repl atlas-crm-next*    localhost        46125   atlas-crm-next   Clojure

thheller09:11:42

* *cider-repl localhost* localhost 8202 shadow-cljs Clojure

mitchelkuijpers09:11:48

ah that's the problem

mitchelkuijpers09:11:21

I did the following:

You can mute this warning by changing cljr-suppress-middleware-warnings.
user> (shadow.cljs.devtools.api/nrepl-select :app)
To quit, type: :repl/quit
[:selected :app]
JS runtime connected.
cljs.user> (.log js/console "hoi")
nil

mitchelkuijpers09:11:40

weird that that doesn't work for you

mitchelkuijpers09:11:53

is the file in the right project?

mitchelkuijpers09:11:31

Do you have incluced the middleware and cider 16 middleware? Maybe that helps

thheller09:11:50

using the config you pasted above

thheller09:11:08

WARNING: CIDER's version (0.15.0-snapshot) does not match cider-nrepl's version (0.15.1). Things will break!

thheller09:11:11

I get this on connect

thheller09:11:17

maybe I have an old cider version?

mitchelkuijpers09:11:33

yes try:

npx shadow-cljs -d cider/cider-nrepl:0.16.0-SNAPSHOT watch :app 

thheller09:11:57

but it says CIDER's version (0.15.0-snapshot)

mitchelkuijpers09:11:14

Oh wait your's wants 0.15.1

mitchelkuijpers09:11:32

how do you add cider?

mitchelkuijpers10:11:13

That is weird because mine wants:

;; Connected to nREPL server - 
;; CIDER 0.16.0snapshot (package: 20171001.112), nREPL 0.2.13

thheller10:11:55

no the slightest clue

thheller10:11:13

package-install doesn’t include cider

mitchelkuijpers10:11:53

you use spacemacs? try configuration-layer/update-packages

thheller10:11:19

what does that mean? 😛

mitchelkuijpers10:11:43

that updates all the spacemacs packages

mitchelkuijpers10:11:48

or all the emacs packages

thheller10:11:57

yes … I gathered that by the name

mitchelkuijpers10:11:59

you could also check for updates, maybe you have an old version of spacemacs

thheller10:11:02

but HOW do I try it?

thheller10:11:59

what command should I type?

mitchelkuijpers10:11:37

space space and then type it in

thheller10:11:51

SPC SPC is undefined

mitchelkuijpers10:11:05

Oh you have an old spacemacs

thheller10:11:46

very likely. how do I update?

mitchelkuijpers10:11:48

you could remove emacs.d en dan reinstall spacemacs

mitchelkuijpers10:11:09

does alt+x work?

mitchelkuijpers10:11:29

then search for spacemacs/check-for-new-version

thheller10:11:03

seems like I have a git checkout, just pull’d that

thheller10:11:26

still undefined

thheller10:11:48

(render (foo "foo") (js/SPC SPC is undefined
document.getElementById "app"))

thheller10:11:55

great … now it fucked up my buffer?

mitchelkuijpers10:11:03

? what the hell 😛

thheller10:11:20

kinda beginning to hate emacs again 😛

mitchelkuijpers10:11:39

I would just remove your emacs.d en close emacs

mitchelkuijpers10:11:48

and then do a fresh clone and start emacs

thheller10:11:13

that seems to install a bunch of stuff now at least

mitchelkuijpers10:11:16

Maybe I should learn how to fix those issue with shadow-cljs so you don't have to go through this pain 😅

thheller10:11:31

SPC SPC is undefined but it should be updated now

mitchelkuijpers10:11:55

then just use alt+x that also works

mitchelkuijpers10:11:15

I think it is probably alt+enter for you

thheller10:11:57

WARNING: CIDER's version (0.16.0-snapshot) does not match cider-nrepl's version (0.15.1). Things will break! can I make it use non-snapshot? snapshots are scary.

mitchelkuijpers10:11:55

Then you have to do some stuff with melpa, but probably all of your cider users will be using 0.16.0-snapshot

mitchelkuijpers10:11:17

But you should be able to pin the version somewhere, but not sure how that works tbh

thheller10:11:25

added the snapshot but now I get [WARNING] No nREPL middleware descriptor in metadata of null, see clojure.tools.middleware/set-descriptor!

thheller10:11:50

oh .. was using the wrong ones 😛

thheller10:11:09

man this is what I really hate about emacs .. press one wrong key and things go totally nuts

mitchelkuijpers10:11:12

What a horror this is

thheller10:11:49

user-error: 'cider-load-buffer' needs a ClojureScript REPL.
If you don't know what that means, you probably need to jack-in (', "').

thheller10:11:40

seriously .. how does anyone get any work done with emacs …

thheller10:11:04

I’m completely lost and I have used it for a while a couple years ago

thheller10:11:39

CLJS <no project>@localhost:8202 (Java 1.8.0_144, Clojure 1.9.0-beta4, nREPL 0.2.13) [2 times]

thheller10:11:48

probably the <no project>?

thheller10:11:19

seriously .. I can break everything in emacs with less than 3 clicks/keys

thheller10:11:45

I give up …

thheller10:11:54

I’ll push what I have .. and let you deal with this 😛

thheller10:11:39

[email protected] fixes the initial issue [nREPL] No response handler with id 0 found

mitchelkuijpers10:11:24

Haha sorry I was busy

thheller10:11:09

what I found but couldn’t figure out how to change

thheller10:11:18

was changing the jack-in command

thheller10:11:50

Cider Cljs Lein Repl

mitchelkuijpers10:11:06

If you cider connect you have to make sure that you are in a project file

thheller10:11:15

"(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))"

thheller10:11:36

if you change that to just (shadow.cljs.devtools.api/nrepl-select :app) it should work?

mitchelkuijpers10:11:04

damnit now I am stuck in that configuration screen

mitchelkuijpers10:11:23

you then you can connect and then run cider-sibling-cljs-repl

mitchelkuijpers10:11:26

that should work

mitchelkuijpers10:11:27

You can change Cider Cljs Lein repl with customize-group Cider

thheller10:11:48

I’m done with emacs for a while … not enough patience to figure this out

mitchelkuijpers10:11:29

Sure I'll try it out myself

mitchelkuijpers11:11:33

Could you push your changes? Then I can see where you changed stuff and play around

thheller11:11:50

ah thought I did

mitchelkuijpers11:11:51

Haha nice commit messages

mitchelkuijpers11:11:51

Sorry one more question how do you hack on this and quickly test it out in emacs? not sure how to start

thheller11:11:13

my workflow is: lein with-profiles +cljs repl in the project itself. connect to that remotely via Cursive.

thheller11:11:23

(require 'repl) (repl/go) starts the embedded server

thheller11:11:53

then used emacs to cider-connect to localhost 8202

thheller11:11:38

shadow-cljs clj-repl also works, dont need the lein repl.

thheller11:11:24

just doing that since every (repl/go) restarts the embedded server which also restarts the nrepl server. so I’m connected to that while calling (repl/go) I lose the connection.

thheller11:11:06

dunno how well emacs deals with 2 separate nrepl connections

mitchelkuijpers11:11:06

Hmm should I install all npm-packages manually? No package.json

thheller11:11:08

ah yeah its .gitignore since I put a bunch of test packages there

mitchelkuijpers11:11:19

Ah ok can you share it here?

thheller11:11:17

{
  "private": true,
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.6.0",
    "shadow-cljs": "file:packages/shadow-cljs",
    "source-map-support": "^0.4.15",
    "ws": "^3.2.0"
  },
  "dependencies": {
    "@atlaskit/navigation": "^18.0.0",
    "@blueprintjs/core": "^1.32.0",
    "@expo/vector-icons": "^5.2.0",
    "animated": "^0.2.0",
    "aws-sdk": "^2.122.0",
    "babel-core": "^6.26.0",
    "babel-plugin-external-helpers": "^6.22.0",
    "bootstrap": "4.0.0-beta.2",
    "browser-resolve": "^1.11.2",
    "browserify": "^14.4.0",
    "browserify-shim": "^3.8.14",
    "codemirror": "^5.31.0",
    "create-react-class": "^15.6.2",
    "d3": "^4.11.0",
    "envify": "^4.1.0",
    "firebase": "^4.5.1",
    "firebaseui": "^2.4.1",
    "highlight.js": "^9.12.0",
    "iconv-lite": "^0.4.19",
    "intl-messageformat": "^2.2.0",
    "jquery": "^3.2.1",
    "jquery-treetable": "^3.2.0-1",
    "js-nacl": "^1.2.2",
    "katex": "^0.9.0-alpha1",
    "leaflet": "^1.2.0",
    "material-components-web": "^0.22.0",
    "material-ui": "^0.18.7",
    "mkdirp": "^0.5.1",
    "module-deps": "^4.1.1",
    "moment": "^2.18.1",
    "node-libs-browser": "^2.0.0",
    "node-resolve": "^1.3.3",
    "parinfer": "^3.11.0",
    "parinfer-codemirror": "^1.4.1",
    "preact": "^8.2.5",
    "processing-js": "^1.6.6",
    "react": "^16.0.0",
    "react-addons-css-transition-group": "^15.6.2",
    "react-apollo": "^1.4.16",
    "react-dom": "^16.0.0",
    "react-leaflet": "^1.7.0",
    "react-vis": "^1.7.9",
    "readline-sync": "^1.4.7",
    "reqwest": "^2.0.5",
    "shortid": "^2.2.8",
    "source-map": "^0.6.1",
    "styled-components": "^2.1.1",
    "uglify-js": "^3.1.2",
    "uglifyify": "^4.0.3",
    "webpack": "^3.5.5"
  },
  "browserify-shim": {}
}

thheller11:11:38

need to remove some stuff, those are basically the pacakges I tested at one point or another

mitchelkuijpers11:11:18

Ah pretty much have it working now ^^

thheller12:11:02

debug logging should be enabled which will log all nrepl messages

mitchelkuijpers12:11:37

Yeah very usefull

mitchelkuijpers12:11:47

I am getting somewhere, when I try to eval a namespace form, here i try this one:

(ns demo.browser
  (:require-macros [demo.browser :refer (test-macro)])
  (:require ["react" :as react :refer (Component createElement)]
            ["react-dom" :as rdom :refer (render)]
            ["shortid" :as sid]
            ["jquery" :as jq]
            ["material-ui/RaisedButton" :as mui-btn :default btn]
    ;; ["@material/checkbox" :refer (MDCCheckbox MDCCheckboxFoundation)]
            ["babel-test" :as babel-test :default Shape]
            ["@material/menu/simple/foundation" :default menu]
            ["@material/menu/util" :as util]
            ["d3" :as d3]
            [clojure.pprint :refer (pprint)]
            [cljsjs.react]
            [clojure.spec.alpha :as s]
            [clojure.spec.gen.alpha :as gen]
            [shadow.api :refer (ns-ready)]
            ["circular-test" :as circ]))
I get an error with:
:cause conflict on "clojure.pprint" by "clojure.pprint" used by "cljs.pprint"

mitchelkuijpers12:11:33

I get the same for clojure.spec and cljs.spec

mitchelkuijpers12:11:19

When I remove this a lot starts working ^^

mitchelkuijpers12:11:56

Even the autocompletion

mitchelkuijpers12:11:37

Nice and I fixed the case statement which had a wrong default now I get:

[:FIXME {:type :repl/error, :message "failed to compile resource: [:shadow.build.classpath/resource \"cljs/pprint.cljs\"]", :data {:tag :shadow.build.compiler/compile-cljs, :source-id [:shadow.build.classpath/resource "cljs/pprint.cljs"], :url #object[java.net.URL 0x6ad8fa90 "jar:file:/home/mitchel/.m2/repository/org/clojure/clojurescript/1.9.946/clojurescript-1.9.946.jar!/cljs/pprint.cljs"], :file nil}, :causes ["No namespace: cljs.pprint found"]}]

thheller13:11:36

damn this aliasing code is killing me 🙂

thheller14:11:13

"No namespace: cljs.pprint found" that must be a cider error?

mitchelkuijpers14:11:02

No I think that is caused by: :cause conflict on "clojure.pprint" by "clojure.pprint" used by "cljs.pprint"

mitchelkuijpers14:11:00

So it fails to compile: clojure.lang.ExceptionInfo: failed to compile resource: [:shadow.build.classpath/resource "cljs/pprint.cljs"]

thheller14:11:26

the first one I understand, the second I don’t understand 😛

mitchelkuijpers14:11:42

I think the second one happens because of the conflict? (I am just guessing here)

thheller14:11:06

man I really hate having to combine this REPL code with watch

thheller14:11:19

so much undefined behaviour

mitchelkuijpers14:11:43

I am trying to get something like this to work, not sure if this is even possible.

(defn cljs-repl []
  (shadow-server/start!)
  (shadow/watch :app)
  (shadow/nrepl-select :app))
Something like this does work with figwheel where you can just say (fig/cljs-repl (:figwheel-system @figwheel)) not sure if you want to support this but it has a really nice workflow we have one script that starts everything and then in our emacs starts 2 repls in one jvm

mitchelkuijpers14:11:34

What kind of undefined behaviour do you get? I would think on save just reload all affected namespaces? and blow away evalled stuff?

thheller14:11:11

yeah the above should work fine

thheller14:11:15

thats what I do essentially

mitchelkuijpers14:11:34

I get: IllegalStateException Can't change/establish root binding of: *nrepl-cljs* with set clojure.lang.Var.set (Var.java:223)

thheller14:11:14

ah .. right

thheller14:11:27

well thats a bit more complicated

thheller14:11:40

since the nrepl connection you are one is not the one started by shadow-cljs

thheller14:11:03

so instead you must add the middleware to the nrepl you are using

mitchelkuijpers14:11:15

Ahh that would be easy

mitchelkuijpers14:11:20

and then no fiddling with cider middleware

thheller14:11:57

I’m not sure how to set this up though

mitchelkuijpers15:11:06

I will write a guide if I have this working ^^

thheller15:11:16

I fixed the conflict but now watch can’t load the file anymore because its on conflict with the REPL 😛

mitchelkuijpers15:11:39

Oh god all because of the stupid aliasing?

thheller15:11:40

I guess I need to remove some of my strict checks

thheller15:11:48

nah aliasing was just a bug

thheller15:11:16

but when you call (ns some.thing) in the REPL it must not touch the filesystem

thheller15:11:34

so it defines a pseudo resource, which is fine

thheller15:11:48

then you save the file, watch comes along, tries to use it

thheller15:11:02

but since the REPL resource is already in use, it conflicts with the FS resource

thheller15:11:18

I guess I’ll just allow that, no need to be strict in this case

thheller15:11:07

need to be kinda strict to ensure caching works properly

thheller15:11:15

meh … undefined is fine I guess

mitchelkuijpers15:11:10

Damn the middleware works!

mitchelkuijpers15:11:51

this is awesome, I still get this error for some reason if I run a clean build from the repl in leiningen:

-> Compile CLJS: cljs/core.cljs
------ ERROR -------------------------------------------------------------------
 File: jar:file:/home/mitchel/.m2/repository/org/clojure/clojurescript/1.9.946/clojurescript-1.9.946.jar!/cljs/core.cljs:987:14
--------------------------------------------------------------------------------
 983 | 
 984 |     (number? o)
 985 |     (if (js/isFinite o)
 986 |       (js-mod (Math/floor o) 2147483647)
 987 |       (case o
--------------------^-----------------------------------------------------------
No reader function for tag Inf

--------------------------------------------------------------------------------
 988 |         ##Inf
 989 |         2146435072
 990 |         ##-Inf
 991 |         -1048576
 992 |         2146959360))
--------------------------------------------------------------------------------

:error

But it works without leiningen so probably a dependency issue

thheller15:11:30

yep tools.reader conflict. most often core.async.

thheller15:11:56

either exlude it or add [org.clojure/tools.reader "1.1.1"] to your project

mitchelkuijpers15:11:13

awesome now it all works!

thheller15:11:18

now if I could only find a decent way so the REPL doesn’t conflict with watch in undefined ways

thheller16:11:41

@mitchelkuijpers [email protected] should hopefully resolve most ns issues

thheller16:11:31

it may still run into weird situation but the worst that should happen is that watch blows away some REPL state

mitchelkuijpers16:11:00

That is not really a problem ^^

thheller17:11:14

I started https://github.com/thheller/shadow-cljsjs in which I want to collect the cljsjs.* alias namespaces for common cljsjs packages

thheller17:11:38

so not every user has to create them

thheller17:11:46

rather have them in a central place