Fork me on GitHub
#calva
<
2023-04-14
>
seancorfield21:04:13

When jacking-in, Calva offers aliases from the project deps.edn but doesn't know about your user deps.edn -- I know you can configure Calva to offer extra aliases but is there any way it could figure out what aliases are in your user deps.edn and offer those automatically? I'm not even sure if that's a desirable feature (my user deps.edn has an enormous number of aliases)...?

pez08:04:33

It has been suggested before, but so far at least I have deemed the extra aliases to be enough. As you note, it could get a pretty crazy list.

seancorfield21:04:37

Is there an easy way to tell Calva about additional nREPL middleware when jacking-in? If I have Portal on my classpath, I would normally want the Portal middleware added, as well as the CIDER middleware.

pez08:04:20

We should add this functionality, imo.

pez08:04:01

It might be that when I’m done implementing the custom command line for Jack-in, that this is easy enough to achieve that way. So my support for the idea is general for now. It’ll depend on the definition of “easy”. 😀

seancorfield15:04:51

The real trick here is that such middleware would be conditional, based on what's on the classpath - which is why I wrote my own repl-starting main function. But if the mechanism allows both extra deps and extra middleware args to be specified, that would work.

seancorfield21:04:21

And also on the subject of jacking-in, currently, if you specify an alias that include :main-opts, Calva complains and warns that your jack-in might not work (because Calva expects to provide all the main opts). I typically start my REPL from the Terminal because I use :dev/repl (from my dot-clojure repo) which uses -e to require/resolve/call a function from a dep in that alias that starts a REPL adaptively based on what is on the classpath (Portal, CIDER, etc). It would be really nice to be able to say to Calva "Jack-in with these aliases, add nREPL/CIDER via -Sdeps please, but assume the aliases will start an nREPL for you to connect to". In other words, it would be nice to be able to jack-in from Calva but have it omit those main opts...

pez08:04:55

I’m not following completely. What stops this from working today?

seancorfield15:04:04

Because if an alias includes main opts then the -M -m stuff Calva adds is passed as additional arguments to whatever main the alias invokes, and does not invoke the nREPL cmdline.

pez15:04:48

Oh, I thought Calva wouldn’t invoke its main opts if an alias declares this. Sounds like a bug.

pez16:04:20

When I try it, Calva does not any -m stuff if I select an alias with main-opts.

pez17:04:07

For now I’ll add some docs about this, reword the warning a bit and make it point to the docs. Since this does not address your use case, please let me know if there is something you think could be done to support it.

pez17:04:37

The docs:

seancorfield17:04:14

Ah, that clarifies how it works (which wasn't quite how I thought it worked, so thank you!)... the only "wrinkle" is that :main-opts are last-one-wins so you can control that by ordering things on the command-line but Calva adds the aliases in strictly alphabetical order. If I have a project where I can run clojure -M:test, I'm likely doing that by having :main-opts in :test to specify how to run the test runner. So I can't select :test as an alias when jacking-in because it doesn't start a REPL. My alias for starting a REPL is :dev/repl -- so even if I also check that, Calva invokes clojure -Sdeps '...' -M:dev/repl:test and so that runs the tests but does not start a REPL. From the command-line I would run clojure -M:test:dev/repl and get a REPL (with tests available). So what Calva needs here is some way to select which :main-opts-bearing alias should come last so that it "wins" and therefore can be used to start a REPL. That wouldn't help with the case of just checking :test tho'...

🙏 2
seancorfield17:04:24

One thing Calva could do is: • add :aliases in the -Sdeps with, say, :calva/cider-nrepl that has the :main-opts Calva would add (`-m nrepl.cmd-line --middleware [..]`) • add :calva/cider-nrepl by default as an alias at the end of the selected alias list • unless the user selected a different alias to be the last one, whose :main-opts should win Which is a bit of a complicated UX but is very flexible...

seancorfield17:04:53

That way clojure -Sdeps '...' -M:test:calva/cider-nrepl would work, but also a user could select a different "last alias" and do clojure -Sdeps '...' -M:test:dev/repl for example...

seancorfield17:04:48

(I ran into this with HoneySQL that assumes last-one-wins in the tasks it runs in build.clj -- which fetches :main-opts from the selected aliases when running tasks -- but has :main-opts in :test for the simple command-line case too)

pez19:04:20

Thanks! Let’s ponder this and see if we come up with a way to specify this.

seancorfield03:04:37

FWIW, now that I better understand how Calva actually deals with this, I'm able to use jack-in for a lot more projects than I expected -- even including my work monorepo, using Polylith, with Portal and a bunch of other stuff, which uses an alias with -e to load my dot-clojure REPL-starting code! I had to make a small change to HoneySQL's deps.edn and build.clj files, to split the :main-opts out of :test into :runner (since Calva always adds aliases in alphabetical order) but aside from that, everything "just worked" with jack-in and the appropriate aliases.

gratitude 2
🎉 4
seancorfield21:04:50

(and, yes, I'm on vacation today and playing with Clojure 1.12 Alpha 2 and experimenting with my dev setup!)

metal 2
pez08:04:56

I’m intending to play around with 1.12 Alpha 2 today.

🎉 2
seancorfield21:04:41

For anyone using parts of my VS Code / Calva / Portal setup https://github.com/seancorfield/vscode-calva-setup I just switched the "add libs" custom REPL snippet over to use clojure.repl.deps/sync-deps (Clojure 1.12.0 Alpha 12): ctrl+alt+space a now pops up a REPL input prompt where you can type zero or more aliases and those are passed via :aliases [..] to sync-deps, so that your (updated) deps.edn is sync'd into your running REPL. This was close to my previous workflow here, where I would update the deps.edn file and then ctrl+alt+space a to call the old t.d.a branch add-libs function on the hash map enclosing the cursor (where you just added a new lib & coords).

🙌 2
pez08:04:46

That’s awesome. I think there’s a pattern here that we can build in to Calva.

👍 2
🙌 2
🚀 2
seancorfield03:04:37

FWIW, now that I better understand how Calva actually deals with this, I'm able to use jack-in for a lot more projects than I expected -- even including my work monorepo, using Polylith, with Portal and a bunch of other stuff, which uses an alias with -e to load my dot-clojure REPL-starting code! I had to make a small change to HoneySQL's deps.edn and build.clj files, to split the :main-opts out of :test into :runner (since Calva always adds aliases in alphabetical order) but aside from that, everything "just worked" with jack-in and the appropriate aliases.

gratitude 2
🎉 4