Fork me on GitHub
#calva
<
2022-11-24
>
Dallas Surewood11:11:00

I can't get a good clojure/clojurescript config for calva. I've been trying for months. Using deps.edn and pointing shadow-cljs.edn to it for deps has been close. I run it with calvas jack in and do deps.edn + Shadow-cljs. But anytime I need to do something outside of that, the whole app configuration falls apart. I just don't understand how all these nrepls talk to each other and communicate with calva

James Pratt19:11:51

I found this video quite helpful: https://youtu.be/islMjv55cN8

🙏 1
skylize19:11:46

Try just using shadow-cljs jack-in instead of deps+shadow for the cljs side. I think that gives a better experience. (Shadow CLJS will still look to deps.edn for deps, as instructed by the shadow-cljs.edn). Then if you also need a repl for the server, open that in a separate VS Code window. Instructions https://calva.io/workspace-layouts/ to help getting the same project open in 2 windows.

🙏 1
pez19:11:19

@U042LKM3WCW can you describe more about: > anytime I need to do something outside of [calvas jack in], the whole app configuration falls apart Maybe that can give us ideas about more directed help.

James Pratt19:11:16

"There is also this article: https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/" Gonna be reading that too tomorrow. Looks very helpful, thanks!

🙏 1
Andres12:03:51

Thanks, I have been having the same problem and now I have some reading to do.

pez21:03:33

@U02DLFAV2KV Can you share a bit about the problem? I'd like to learn a bit about how this thing works out there. Especially about when it doesn't work.

Andres09:03:42

@U0ETXRFEW I am working on a repo that has the front and back together. There is a deps.edn and a shadow-cljs.edn. When we started working I would launch npx shadow-cljs watch app on the terminal and then I could either jack-in (ctr-alt +c + ctr-alt+j) to the clj repl with deps or connect (ctr-alt +c + ctr-alt+c) to the cljs repo on the running shadow-cljs. This sort of worked: I could only interact with one repl at a time, but both were running in the background and I could easily switch between them. Then about a week or two ago, that stoped working and I could no longer switch to beteew the repls. What I mean is that the only repl that would work, was the first one I connected to. If I tried to switch, the output in the output window said that I was connected, but the status bar indicator showed that I was not connected and there was no interactivity. Which meant that if I had the server running I had no cljs repl, and if I started the cljs repl, the server which was running in the clj repl, would stop working. I have tried both suggestions mentioned above in the thread and both work great. I am currently using two vs code workspaces. The colleague I work with uses cider/spacemacs, so I am waiting to see if the {:deps true} in shadow-cljs.edn works for him as that is the simplest to use. By the way, both the video and the article were very helpful and clear in explaining why I was having the problem and in giving a more complex explanation of how the calva->repl connection works. Thank you !!🎉

🙏 2
pez10:03:18

I wonder why you are using two workspaces? I would just use one, jack-in to shadow-cljs and then Calva should connect both REPLs and for .clj files use the clj repl, for .cljs files the cljs repl and for .cljc files I get to choose which repl via the toggle (I use the toolbar button for this).

Andres10:03:12

Right now I am in a transition phase. I have a branch where I have setup dps.edn and shadosw-cljs.edn to work so that I only have to one jack-in to shadow-cljs ( :deps true and all dependencies in deps.edn). In this branch I can do as you mentioned above, but I am waiting to see if that works for my colleague before pushing to main. In the meantime, main has the ’old setup with the dependencies separate in the deps and shadow-cljs, I can have both repls running, each one in its workspace, as indicated in the calva doc. I have to have and extra window open, but it works. In this setup, when I jack-in to shadow-cljs the cljrepl works, but since it does not have any of the deps.edn dependencies (because shadow-cljs does not have :deps true ), it’s not really useable. When try to evaluate anything, I get missing dependency errors. I hope it is clear 😜

pez10:03:59

Thanks! Yes, clearer. It should totally work for your CIDER wielding colleague. But we'll see, I guess. 😃

Andres10:03:26

I don’ see why it would not, it’s more about process.

pez10:03:56

Certainly. Plain manners.

James Pratt19:11:20

I'm just beginning to work with clojure on a server. And I'm stumped as to why my remote nREPL connection is not working. I've set up a web server that is responding fine to web requests. I want to connect to it with an nREPL. I have started an nREPL server in my project with the following code changes, starting a nREPL server at the same time I start the jetty server: https://github.com/jamiepratt/clj-oauth2-token-generator/compare/672b71e29db25c24f437fd84e6555804a0afdb71...deploy

James Pratt19:11:34

Then I have this in my .ssh/config to connect to the remote port and forward it as a local port:

Host **hostname is here**
  HostName **hostname is here**
  LocalForward 50001 localhost:54654

James Pratt19:11:48

I figure then that I should be able to jack-in with calva "Connect to a running REPL in your project". I tried selecting project type generic or deps.edn and then connect to localhost:50001 but neither is working. Thanks a lot for any help!

James Pratt19:11:56

I figure my next step might be to have the project running locally and see if I can jack-in locally through the exposed port.

pez19:11:34

Another next step is to remove Calva from the picture and connect to the nREPL server using something like:

clojure -Sdeps '{:deps {reply/reply {:mvn/version "0.5.1"}}}' -M -m reply.main --attach 54654 
(If that's the local port, I don't know how to interpret that forward. 😄) If you have the port in a .nrep-port file you can do:
clojure -Sdeps '{:deps {reply/reply {:mvn/version "0.5.1"}}}' -M -m reply.main --attach `< .nrepl-port
`

pez19:11:46

The VS Code Remote Extension is also very powerful. Then you run the VS Code instance on that server and your local VS Code is more of a client. A very seamless experience.

James Pratt09:11:26

For some reason I am unable to connect to the nREPL. clojure -Sdeps '{:deps {reply/reply {:mvn/version "0.5.1"}}}' -M -m reply.main --attach 8080 SocketException The transport's socket appears to have lost its connection to the nREPL server nrepl.transport/bencode/fn--716/fn--717 (transport.clj:122) nrepl.transport/bencode/fn--716 (transport.clj:122) nrepl.transport/fn-transport/fn--670 (transport.clj:50) clojure.core/binding-conveyor-fn/fn--5823 (core.clj:2047) java.util.concurrent.FutureTask.run (FutureTask.java:317) java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144) java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642) java.lang.Thread.run (Thread.java:1589) Bye for now!

James Pratt09:11:40

It seems like port forwarding is working as I would expect. I find that if I can forward port 80 from my remote server to my local computer's port 8080 using the same syntax in the ssh config and then am able to connect to the http server with my browser at localhost:8080.

pez10:11:55

Have you tried using the Remote Extension? (Given that you can install VS Code on the remote host, of course.)

pez10:11:05

Maybe some security mechanism stops ”high” port numbers from being forwarded...

pez10:11:09

You could try telnet maybe. I think it might provide better clues than that nREPL client stack trace does.

James Pratt11:11:36

telnet -4 localhost 61456
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

James Pratt11:11:08

Above is a connection to a working local nrepl

James Pratt11:11:20

that is all the output I see then it appears to be waiting for something

pez11:11:07

And what do you get with the remote server?

James Pratt11:11:52

when trying to connect to local forwarded port (now I am forwarding to 8080):

telnet localhost 8080
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

James Pratt11:11:30

I'll try a lower port number on the remote machine and see if that helps

James Pratt12:11:11

I changed to a lower port number on the remote server to see if that helped. No joy. :-(

telnet -4 localhost 8080
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host

pez12:11:27

Maybe try starting the nREPL server on port 80 and forward that?

pez12:11:04

Not as a solution, but as a diagnostics data point.

James Pratt12:11:07

Still no joy with the nrepl server listening on port 80.

❯ telnet -4  80
Trying 176.58.115.27...
telnet: connect to address 176.58.115.27: Connection refused
telnet: Unable to connect to remote host
When I local forward it to 8080 (can't forward to 80 as that is reserved) I get:
❯ telnet -4 localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

James Pratt13:11:22

But jetty is responding on 8080 where I moved it to.

James Pratt13:11:35

Time to try try the remote host VSCODE extension. I tried it before but since I have my clojure running in docker I will have to install java again outside the docker image.

pez13:11:37

> But jetty is responding on 8080 where I moved it to. Hmmm, I'm sure this is a clue as well, but I fail to understand it. 😃

James Pratt13:11:29

I have the remote extension apparently working great through ssh but still cannot jack in after installing java remotely.

James Pratt15:11:37

absolute minimal code for an embedded nrepl server explicitly included in code. It works fine on my local machine. And I can run the other code with the nrepl embedded with the web server and I can connect no problem on my local machine. https://github.com/jamiepratt/embedded-repl

James Pratt16:11:40

I've found the issue, problem with my docker syntax it seems but don't know how to fix: https://serverfault.com/questions/1116621/how-do-i-open-ports-on-a-docker-image

bringe22:11:43

Not sure if this is an issue but I see in the docker docs (and in a work project) that the ports are stated like so:

ports:
      - "8000:8000"
I see in your docker-compose this:
ports:
      - 127.0.0.1:2001:2001
Maybe that should be:
ports:
      - "2001:2001"
Just a guess though - I’m no docker expert.