Fork me on GitHub
#calva
<
2022-09-25
>
Gabriel Kovacs10:09:05

If after being jacked-in I change the deps.edn how can I do a refresh/restart the project?

pez12:09:19

The easiest way is to jack-in again. This will kill the REPL and start and connect a new one. If you want to load new dependencies dynamically you could use https://github.com/clojure/tools.deps.alpha/tree/add-lib3. There is a (possibly somewhat dated) article by @U064X3EF3 about it here: https://insideclojure.org/2018/05/04/add-lib/ What I do when adding dependencies is that I have this dependency in deps.edn:

org.clojure/tools.deps.alpha {:git/url ""
                              :sha "83a477b305839c697666401508c395cfed29506a"}
Then I have a https://calva.io/custom-commands/ defined like so:
"calva.customREPLCommandSnippets": [
        {
            "key": "a",
            "name": "Add selected dependency",
            "snippet": "(require '[clojure.tools.deps.alpha.repl :refer [add-libs]])\\n(add-libs '{$selection})"
        }
    ],
With that, after I have added a dependency in deps.edn, I can select the dependency and type ctrl+alt+space a. This will download the dependency and make it available in my REPL.

❤️ 1
Gabriel Kovacs12:09:08

Thank you for the detailed explanation! Added to the saved items :)

pez12:09:29

Something closer to reloading deps.end is to use https://github.com/lambdaisland/classpath.

👍 1
Alan Birchenough19:09:55

Thanks for this @pez. I was looking for this information the other day. However, I'm trying to understand the workflow for the Lambda Island classpath approach (having read the README over there). Is it that, instead of selecting the dependency and then running the custom Calva command, instead I just save the updated deps.edn, then a file watcher invokes the classpath library to pull in the new dependency and dynamically adds it to the classpath, so no REPL restart is needed? Just trying to understand this from the user's point of view. Thanks.

pez19:09:53

I've not been using the lambdaisland/classpath solution myself, actually. I have it as one of my todo:s to explore. Maybe @U07FP7QJ0 can say yes or no on that question.

👍 1
plexus12:09:03

Yes, once the classpath watcher is running that's all you need. Any changes will be picked up when you save and be immediately available. But do note that this doesn't handle reloading namespaces that are already loaded.

metal 1
✔️ 1
plexus12:09:21

There's more also lambdaisland/launchpad which integrates with classpath to handle the reloading automatically.

💚 1