Fork me on GitHub
#calva
<
2021-02-05
>
pez17:02:41

Do you want keyword definition look-up and stuff? Time to upgrade Calva, because v2.0.160 has these changes: • https://github.com/clojure-lsp/clojure-lsp/releases/tag/2021.02.05-03.05.34https://github.com/BetterThanTomorrow/calva/issues/1016

clojure-lsp 2
🎉 1
afry19:02:03

Hey everyone, can I get a recommendation for either a Calva doc page or some other reference material? I'm pretty new to Clojure and the REPL in general. So far I've used Calva for faily basic stuff: cd into project, start repl, develop, etc. I've heard, however, that you can jack in to running REPL processes. This could be used to diagnose or do hotfixes to a production app. Another use case for jacking in to a remote REPL is for apps which are hosted in a VM (Docker, Vagrant, etc.). So ... uh, where do I start if I want to do something like that 😅

bringe20:02:51

Check this out: https://github.com/clojure/tools.nrepl#embedding-nrepl-starting-a-server You can embed an nrepl server in your application. Say it's a web server backend/api - you can run an embedded nrepl server, and then when it's running, you can use the host:<port-you-started-embedded-nrepl-server-on> with Calva's connect command to connect to it. Then you are inside your running web backend/api. You can require namespaces from it, redefine an endpoint handler, etc.

seancorfield20:02:03

@U01HMCQMBKP Something else to consider: any Clojure process can start a Socket REPL at startup just by specifying a JVM option -- which means you do not need any code or dependencies in your process at all -- and then you can connect to that socket server via telnet, nc (netcat), or from your editor if you use a plugin that understands plain socket REPLs (Clover for VS Code, Chlorine for Atom). Calva cannot currently connect to a socket REPL though.

seancorfield20:02:50

We run socket REPLs in many of our processes, even in production, because all it needs is a JVM option at startup...

seancorfield20:02:36

(at some point, nREPL should be able to be "side-loaded" over a socket REPL, and then Calva could use that approach to connect to a socket REPL and "upgrade" it)

bringe20:02:05

To give you an example usage, clojure-lsp, which Calva runs to provide some language features, starts an embedded nrepl server: https://github.com/clojure-lsp/clojure-lsp/blob/ca37bfff980c1c4bc504527aeeebdd965e6c3a0a/src/clojure_lsp/nrepl.clj#L16 If we want to poke around in the running clojure-lsp program, we can run the Calva command "LSP Server Info", take the :port value from the map returned, which is the nrepl server port, and use Calva's connect command to connect to it. Then we can navigate clojure-lsp's namespaces, check it's state, run functions ourselves to debug things, etc.

bringe20:02:04

Speaking of, this :port is now coming back as nil @UKFSJSM38 😄. It was working a while back, and I see the nrepl code was moved around at some point lately.

ericdallo20:02:00

yeah, this is on purpose, we only show the port if you compile it with lein with-profile debug bin

ericdallo20:02:49

this is to reduce image size, (also it doesn't work for graalvm compiled images, which should be the default soon)

bringe20:02:44

Ah ok, thanks!

afry20:02:51

Great, thank you everybody! I think I've got a better grasp on what I need to do now: 1. embed nrepl into project 2. connect to repl via Calva 3. ??? 4. profit

bringe20:02:12

#3. Run code to change/run project code

(require 'my-project.core)
(in-ns 'my-project.core)

(some-core-fn "test-args")

@app-state

bringe20:02:33

Something like the above. I'm not guaranteeing that is correct code lol

pez20:02:52

It's not specific to Calva, really, but we have a Connect to a REPL command. What's important for Calva then is that the host program has an nrepl server running, and even better if it has cider-nrepl middleware loaded.

pez22:02:46

Dear Calva friends. The Calva team just started AMA:s at both ClojureVerse and Reddit. Please feel invited! • Reddit: https://www.reddit.com/r/Clojure/comments/ldiafr/we_created_and_maintain_calva_ask_us_anything/ • ClojureVerse: https://clojureverse.org/t/we-created-and-maintain-calva-ask-us-anything/

calva 3