Fork me on GitHub
#calva
<
2022-06-09
>
lambdam13:06:03

Hello, I'm trying to set up Calva to onboard new people on a Clojure fullstack project (with shadow-cljs) I use Emacs and set up a long time ago the following environment: • Configure Cider to use shadow-cljs as a library (without npm): https://shadow-cljs.github.io/docs/UsersGuide.html#deps-edn (and also https://github.com/clojure-emacs/cider/issues/2812) • Launch two REPLs in the same process with cider-jack-in-clj&cljs. I'm a bit lost in the Calva documentation. Can I achieve the same thing with https://calva.io/connect-sequences/ ? Is it possible to have two REPLs in the same process with Calva ? Thanks a lot.

pez14:06:51

Is shadow-cljs configured to use deps.edn or lein for dependencies? If so jack-in using the shadow-cljs project type should work.

lambdam14:06:50

I think it is. Here is the beginning of my shadow-cljs.edn file:

{:deps true
  :builds {:app {:target :browser ...
When I choose the shadow-cljs project type, I get an error since there is no Node.js configuration in the project (no package.json and no node_modules folder). When I choose the deps.edn + shadow-cljs, the process goes well until I choose the :app build. I then get the following message :
; Creating cljs repl session...
; Connecting cljs repl: deps.edn + shadow-cljs...
;   The Calva Connection Log might have more connection progress information.
; Failed starting cljs repl for build: :app. Is the build running and connected?
   See the Output channel "Calva Connection Log" for any hints on what went wrong.

lambdam14:06:37

Apart from that, I didn't understand if it is possible with Calva to: 1. Have multiple windows for multiple REPL connections. 2. Create sibling connections with one REPL session to prevent having two JVM instances for clj and cljs REPLs. On cljc files, it is possible on Cider to choose with which REPL to evaluate an expression (cljs on the browser or clj on the JVM).

pez15:06:09

Maybe it is npx that needs package.json. Copy the jack-in command line and use it without npx from the terminal. Then use Calva Connect to connect to it. Calva will create one clj and one cljs repl session and let you choose which one should be used for cljc files.

lambdam15:06:33

I managed to connect and run shadow server with :

(defn cljs-repl
  ([]
   (cljs-repl :app))
  ([build-id]
   (server/start!)
   (shadow/watch build-id)
   (shadow/nrepl-select build-id)))
But then, I don't understand how to reach the other REPL to start my backend HTTP server. With Cider, there are two different buffers.

pez16:06:57

That's basically what Calva does if you Connect using the shadow-cljs project type. Did you try that? It will give you two sessions, one for clj and one for cljs. They share the same REPL/output window, which is considered to be a cljc file. There is a command (and a status bar button) for toggling which REPL the cljc files are using. clj files will use the clj connection and cljs files will use the cljs one.

lambdam16:06:39

I try right now.

pez16:06:16

The way you did it now doesn't really work, because Calva will get confused when the clj session is used for cljs things. (And also you won't get the two connections you need.)

pez16:06:44

I can do a screen share if you like. Easier to show you how to do it then.

lambdam16:06:58

With pleasure

lambdam17:06:37

I went to ClojureD on 2018. That was very good. That's a shame I don't go this year. Thanks again.

🙏 1
pez19:06:42

It would have been awesome to meet there. Next time!

lambdam09:06:31

Hello @U0ETXRFEW, It spent quite some time extracting a small project from the big one. But there it is : https://github.com/lambdam/clojure-fullstack-ssr-template I could reproduce the behaviour that we saw with Calva. Enjoy ClojureD.

🙏 1
metal 1
pez07:06:03

Sorry for belated answer. Looking at this now. One thing I notice is that if we start the repl using shadow-cljs shadow-cljs -d cider/cider-nrepl:0.27.4 watch :app, the shadow dependencies are never added, because the clojure aliases are not provided. If I change to :deps {:aliases [:dev :cljs]}, then jack-in using the shadow-cljs project type works. No idea why I didn't spot this when we screen shared.

lambdam09:06:50

Humm, but doing so, the command shadow-cljs -d ... uses the Node.js executable no ?

lambdam09:06:16

To use Clojure CLI with shadow-cljs as a library, the command should start with clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"0.9.0"},cider/cider-nrepl {:mvn/version,"0.27.4"}}}' -M:dev:cljs ... no ?

pez10:06:08

Yes, it uses the node executable, which shouldn't matter much if it is done via jack-in, but I was mainly noticing this because it puzzled me why the shadow-cljs project type jack-in wouldn't work.

pez10:06:31

I've gotten it to work via clojure deps too. Regular connect, without jack-in. I'll wrap some conclusions up once I've understood things better.

pez13:06:39

I've filed a PR on your example project, @U94V75LDV. Let me know if it makes sense or not. https://github.com/lambdam/clojure-fullstack-ssr-template/pull/1

lambdam09:06:34

Hello @U0ETXRFEW PR merged. Thanks a lot. I tried to use the Joyride commands (after installing Joyride). At VSCode startup I get the following message :

Requiring Calva failed: #error {:message "Could not find namespace: z-joylib.editor-utils.", :data {:type :sci/error, :line 2, :column 3, :message "Could not find namespace: z-joylib.editor-utils.", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 2, :column 3, :file "helpers.cljs", :ns #object[w2 helpers]})}], :file "helpers.cljs"}, :cause #object[Error Error: Could not find namespace: z-joylib.editor-utils.]}

lambdam09:06:39

Then I run the Joyride command : > Run Joyride: Run Workspace Script.. and select start_project.cljs, to start the project REPL. Which works

lambdam09:06:34

I then connect the project to the REPL and when I try to run the (helpers/refresh-and-restart) from Joyride, I get the following message : Could not resolve symbol: helpers/refresh-and-restart from VSCode.

lambdam09:06:59

May be I missed something on Joyride configuration and installation.

lambdam09:06:34

But in general, I can now use the reloaded workflow from VSCode. Thanks a lot !

pez15:06:05

I left some require in that's not needed. Remove it, and it should start to work, I think. I didn’t catch it because of some user script I have.

pez16:06:58

I filed a new PR, fixing the Joyride issue.

lambdam17:06:25

Sorry, I was a bit disconnected for a long week. Thanks a lot. PR merged.

lilactown17:06:57

i have a file that i want to eval forms and it not switch to user. it has no ns at the top, it's just a scratch file

👀 1
pez15:06:57

Almost missed to answer this despite @brandon.ringe’s notification help... This with scratch files is something I have long been wanting to support. It shouldn't be very hard, I think. So not switching to user ns means that you would like to have a way to stay in whatever the current ns is, I guess, @lilactown?

💯 1
chucklehead17:06:19

I use this in joyride that I think does what you're describing, except output goes to the output console instead of the normal repl output...

(defn evaluate-current-form+ []
  (p/let [result (c/repl.evaluateCode (c/repl.currentSessionKey)
                                      (second (c/ranges.currentForm))
                                      #js {:stdout #(.append (j/output-channel) %)
                                           :stderr #(.append (j/output-channel) (str "Error: " %))})]
    (.-result result)))
if evaluateCodeUpdatingUI was exposed in the api I think that would emulate the normal Calva experience?

pez18:06:24

Have you tried using evaluateCodeUpdatingUI via executeCommand, @U015879P2F8?

chucklehead18:06:12

No, I just came across it for the first time a few minutes ago 🙂 when I was trying to see how normal evaluations in calva differed from the evaluateCode method exposed in the api.

chucklehead18:06:26

I'll give it a try in a little bit

lilactown17:06:06

is there a way to do that?

Alex Miller (Clojure team)17:06:52

oh you probably mean via UI :)

lilactown18:06:45

yea sorry, i mean specifically using calva's evaluate current form command

👀 1
orestis18:06:40

Hey , look at which extension was chosen to highlight the new Sponsoring feature of VS code: https://code.visualstudio.com/updates/v1_68#_sponsoring-extensions

👏 18
calva 22
clojure-spin 12
❤️ 12
2
🎉 3
pez18:06:55

Wow, that’s awesome!

ericdallo18:06:42

Really nice!

🙏 1
seancorfield22:06:09

I just updated VS Code and came here to mention that (haven't looked at Slack today until now!). 'grats @U0ETXRFEW and team!

🙏 1
thanks3 1
pinkfrog14:06:27

This is simply awesome!

pez15:06:57

Almost missed to answer this despite @brandon.ringe’s notification help... This with scratch files is something I have long been wanting to support. It shouldn't be very hard, I think. So not switching to user ns means that you would like to have a way to stay in whatever the current ns is, I guess, @lilactown?

💯 1