This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-14
Channels
- # ai (24)
- # announcements (36)
- # babashka (15)
- # babashka-sci-dev (8)
- # beginners (18)
- # biff (4)
- # calva (24)
- # cider (13)
- # clj-kondo (1)
- # clj-on-windows (2)
- # clojars (15)
- # clojure (120)
- # clojure-dev (13)
- # clojure-europe (69)
- # clojure-nl (1)
- # clojure-norway (8)
- # clojure-uk (2)
- # clojurescript (4)
- # core-logic (2)
- # cursive (6)
- # datomic (193)
- # dev-tooling (4)
- # emacs (1)
- # hyperfiddle (57)
- # lsp (56)
- # malli (11)
- # missionary (15)
- # nbb (61)
- # off-topic (8)
- # polylith (8)
- # practicalli (2)
- # proletarian (1)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (13)
- # spacemacs (1)
- # specter (2)
- # sql (17)
- # tools-deps (3)
- # vim (38)
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)...?
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.
Fair enough.
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.
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”. 😀
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.
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...
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.
Oh, I thought Calva wouldn’t invoke its main opts if an alias declares this. Sounds like a bug.
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.
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'...
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...
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...
(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)
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.
(and, yes, I'm on vacation today and playing with Clojure 1.12 Alpha 2 and experimenting with my dev setup!)
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).
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.