Fork me on GitHub
#cider
<
2023-06-23
>
Drew Verlee02:06:57

When i connect to my shadow-cljs apps nrepl server using calva, I can eval expressions and see the output, when i do so in emacs (cider-connect-cljs), nothing happens. No errors in the message buffer. any advice would be welcome 🙂

vemv06:06:35

Someone had a similar issue a few posts above, so I'll check if everything keeps working in a vanilla project following the official instructions

DeepReef1114:06:35

If you're talking about me, it works in the minibuffer but not in the cljs file (so it does connect properly). I think adding the dependencies as mentionned in the cider documentation in shadow-cljs.edn made cider connect work. But for me, I can't go in a cljs file and eval from there, it won't work for some reasons

DeepReef1114:06:59

In my case, it wasn't working with calva either. I mean, I was able to connect with cider to calva from vscodium, but still not able to eval from cljs file

vemv15:06:56

Yeah I was talking about you. I'll try to investigate the issue you created. Thanks for it wasn't working with calva either. Please add that to the GH issue

2
vemv21:06:30

@U0DJ4T5U1: I created https://github.com/reducecombine/shadow-cljs-cider-demo just now since I see reports like yours all the time in #cider sadly 😞 But the thing is it works! It's fairly simple/minimal, I followed cider/shadow-cljs doc and grabbed a bit from metabase's shadow-cljs. It has a simple readme. Note that I'm using cider-connect-cljs. connect* variants tend to be easier to debug.

👀 2
Drew Verlee21:06:26

Thanks, I'll take a look. If i start the nrepl server from the command line, so i need to add any nrepl middle ware or deps to run cider jack in cljs?

vemv21:06:21

You do. In my repo, the middleware is already defined in shadow-cljs.edn

Drew Verlee21:06:54

I'll go check to see if that got removed... Hmmm

Drew Verlee15:06:45

The issue, not being able to see the output of the evaling an expression, was fixed by using the shadow-cljs.edn middlware cider.nrepl/cider-middleware and refactor-nrepl.middlware/wrap-refactor. We had removed wrap-refactor at some point, but i thought it was working after that, maybe not. I think my confusion is understanding the full necessary set of deps and middlware to make shadow cljs and nrepl happy. Then understanding the ideal place to declare this. Ideally, unless someone wants to convince me otherwise, editor dependencies are up to the developer and so shouldn't make their way into the project. So that's a point against putting it in the shadow-cljs.edn. Though I'm happy to bend with the wind here, as long as my sails go in the right direction. But it looks like the shadow docs imply nprel middleware can go in the ~/.nrepl/nrepl.edn. So i'll put it there. But where else can it go? I have a .clojure deps.edn that has an alias that i have been using for shadow projects for quite a while that injects the middleware

:cider-cljs
  {:extra-deps {cider/cider-nrepl #:mvn{:version "RELEASE"},
                cider/piggieback #:mvn{:version "RELEASE"},
                nrepl/nrepl #:mvn{:version "RELEASE"},
                refactor-nrepl/refactor-nrepl #:mvn{:version "RELEASE"}},
   :main-opts
   ["-m" "nrepl.cmdline" "--middleware"
    "[shadow.cljs.devtools.server.nrepl/middleware,refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}
are all those extra deps necessary? would it be possible to use this alias to launch my shadow client from the cli? THat's what i was doing before, that plus another alias :shadow-cljs
clj -M:cider-cljs:shadow-cljs run web3.build/watch -- staging

:shadow-cljs
  {:main-opts ["-m" "shadow.cljs.devtools.cli"]}
can you even chain two main-opts values? like that?

Drew Verlee15:06:50

you can but only the last will be used, as per the docs.

vemv15:06:05

> The issue, not being able to see the output of the evaling an expression, was fixed by using the shadow-cljs.edn middlware cider.nrepl/cider-middleware and refactor-nrepl.middlware/wrap-refactor. Nice! FWIW I don't think refactor-nrepl makes a difference. But the cider middleware is of course essential. You should get a warning when it's absent - did you not? (Yesteday I that experiment. I got the expected warning) The key part is: make sure cider-nrepl is in the classpath. Actually, shadow-cljs adds the cider middleware to the middleware stack if it can find it in the classpath

vemv15:06:46

> are all those extra deps necessary? piggieback is not, beyond any doubt. I also would question nrepl/nrepl. shadow-cljs has its own repl server, so it has to depend on it refactor-nrepl... only if you intend to use it (we're currently working on very nice ,cljc completions for cljr-slash , btw)

vemv15:06:54

For your scenario, it seems nice to create a :shadow-cider alias. Then users can opt in to activate it like this: > You may also specify additional aliases via the command line using -A, eg. shadow-cljs -A:foo:bar …. (copied verbatim from https://shadow-cljs.github.io/docs/UsersGuide.html)

vemv15:06:47

The docs also talk about .nrepl.edn , that seems the expected place to define project-specific middleware. You'd gitignore that for not affecting other users

Drew Verlee19:06:51

> You should get a warning when it's absent - did you not? I got no error at the terminal or the messages buffer.

Drew Verlee19:06:00

We were on a much older version of shadow, then we updated, i thought the repl was working after the update, but maybe not.

Drew Verlee19:06:09

I think i'm confused about the role of the middleware, it seems like you have to have given some dependencies, but at the same time, i have to manage it but putting it in the nrepl.edn. What is the flexibility getting me? hmm it says shadow does add the nrepl middleware...

Drew Verlee19:06:16

maybe that doesn't happen if you use deps. Maybe i should stop using deps for this project. i'm not sure its helping, this is the first time it's been an annoyance though.

vemv19:06:56

> I got no error at the terminal or the messages buffer. It;s printed at the repl IIRC. I checked just yesterday

vemv19:06:34

> I think i'm confused about the role of the middleware, it seems like you have to have given some dependencies, but at the same time, i have to manage it but putting it in the nrepl.edn. I have trouble parsing this

Drew Verlee19:06:13

I got nothing in the repl either, but i'm not sure that's interesting. > I think i'm confused about the role of the middleware, it seems like you have to have given some dependencies, but at the same time, i have to manage it but putting it in the nrepl.edn. Sorry, that was poorly worded. Ill give an example or say nothing at all 🙂 My current headscratcher is this

clj -M:shadow-cljs-cider:shadow-cljs run web3.build/watch -- staging
[2023-06-26 14:27:30.298 - WARNING] :shadow.cljs.devtools.server.nrepl/middleware-fail - {:sym cider.nrepl/cider-middleware}
FileNotFoundException Could not locate cider/nrepl__init.class, cider/nrepl.clj or cider/nrepl.cljc on classpath.
given this alias
:shadow-cljs-cider {:extra-deps {cider/cider-nrepl {:mvn/version "RELEASE"}
                                   refactor-nrepl/refactor-nrepl {:mvn/version "RELEASE"}}}

Drew Verlee19:06:46

^^ it seems i also have the middleware key and values in my shadow-cljs.edn.

Drew Verlee19:06:11

:middleware [cider.nrepl/cider-middleware
             refactor-nrepl.middleware/wrap-refactor]

vemv19:06:42

headscratcher indeed. That enters into #shadow-cljs support territory. I've done all my testing using the shadow-cljs npm executable For emacs/cider purposes, I'd suggest using said executable and a minimal project (follow the official doc or clone https://github.com/reducecombine/shadow-cljs-cider-demo). That way you'll make sure it can work Hope it helps!