Fork me on GitHub
#calva
<
2021-12-25
>
Eugen00:12:11

hello, any ideas on how I can make Calva repl wait for an external debugger? I am trying to debug some code that calls in Java code (Apache Calcite). I have the code in Intellij and would like to: • call my clojure code in VS Code • hang execution waiting for the debugger • Connect with intellij remote debugger - with Calcite project open • set breakpoints in Java code where I care • run clojure code in Repl • see brakepoints in intellij. I think this might be a common case and might warrant documentation update to Calva https://calva.io/debugger/ . https://docs.oracle.com/cd/E19146-01/821-1828/gdabx/index.html I think what I need is to pass these options to the repl that is started by jack in:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7896

bringe03:12:45

I don’t fully understand, at least at the moment, how this would work, but if you find a way to make it work, please open a PR to explain it in the docs. Calva’s debugger works via cider-nrepl and the current repl connection. I don’t know how it would communicate with IntelliJ, at least as it is now.

Eugen10:12:34

I did find a way, will post when I get to PC. you can pass Jack in env and pass java_tools_opts env var

Eugen10:12:09

I wonder if this can be made per project

Eugen10:12:08

I also used this to change logging configuration for the java app via -D options

brendnz06:12:53

My experience to date with Calva, WSL, and ClojureScript, Dec 25th, 6:25 AM GMT i.e. my work around, re: Calva ClojureScript Quick Start Browser REPL and WSL • Comment: Assuming GUI enabled for WSL2 and WSL2 has a default browser: • Command: Fire up the ClojureScript Quick Start Browser REPL • Comment: At this stage the cljs REPL is running in the browser, but my editor is not connected to it. It is though, connected to clj nrepl on say port 41801. The status bar says the repl is type clj. • Command: Disconnect from the REPL serverCommand: reconnect to it: • Command: Connect to a Running REPL Server in the Project • Command: choose ClojureScript nREPL Server • Command: enter the same port number (above) in the dialog box and press enter. • Comment: reconnection has proved necessary for WSL; would not be necessary without WSL. • Comment: The status bar says the repl type is clj/cljs. • Comment: up to this stage the editor has been in the "output.calva-repl" tab of vsCode. Switch to the core.cljs tab. • Comment: the status bar says the repl type is cljs. • Comment: the namespace has already been loaded (when the REPL was reconnected, not the first time). • Command: evaluate each respective form. • Comment: this would not have been possible without disconnecting and reconnecting to the running REPL Server i.e. the clj REPL; but by reconnecting to nrepl, Calva also connects to the running cljs REPL in the browser this time. • Comment: the forms evaluate until we get to (js/alert "Hello from the REPL!"), whereupon we get the following error: Syntax error compiling at (src/hello_world/core.cljs:16:3). ; No such namespace: js • Comment: nothing reached the cljs REPL in the browser. The Browser Console records nothing happened after the attempt to evaluate this form. This is my current state of play (stuck at js/alert with no apparent namespace for js), but I am pleased to report I have got this far. That is, I am pleased to report the reconnection [partial] work around for using the Clojurescript Quick Start Browser REPL under WSL. I will carry on tinkering from here. Disclaimer1: how can I say I managed to get the editor to talk to the cljs REPL in the browser, when I cannot get js/alert to work? Because before now, I could not get cljs to show on the status bar, nor could I load the core.cljs namespace and evaluate any form at all. I assume I am now connected to the cljs REPL in the browser, but I will know when I manage to get js/alert to work. Disclaimer2: if you detect any newbie-ness in my writing, you are spot on (though I am old! no offence to those older than me). [Edit: Dec 25th, 12:40 PM GMT] I have changed my mind. I now think Calva still has not yet connected to the browser REPL running in firefox in WSL2. Whilst I managed to get the respective forms to evaluate in the hello-world.core.cljs namespace up to the js/alert form, I now believe this was evaluated in the clj REPL, even though the status bar said the cljs REPL was active. I would hazard a guess things went wrong when cider.piggieback/cljs-repl returned the following error at id: '7' in the below screenshot: Execution error (BindException) at http://java.net.PlainSocketImpl/socketBind (PlainSocketImpl.java:-2). Address already in use (Bind failed) Well, I assume it would have reported the above error, except it didn't. I got that error when I tried to repeat the evaluation of that code in the editor. Oh dear, is that why it was "already in use"; the repetition!

brendnz12:12:09

This is where I think things went wrong:

brendnz16:12:53

The issue (of the editor not connecting to the browser repl) may have nothing to do with WSL (nor Calva). https://clojurescript.org/guides/quick-start does not say why, but it says If you are running Linux and the REPL does not start, try disabling browser auto-launch and opening `http://localhost:9000` manually:

clj -M --main cljs.main --repl-opts "{:launch-browser false}" --compile hello-world.core --repl
I had to disable the browser auto-launch to get the prompt to show, then I had to open the browser manually to get the terminal connected to the browser repl (otherwise the no forms written at the prompt would evaluate). Notice I got the example in https://clojurescript.org/guides/quick-start to work by disabling browser auto-launch, and I have NOT made any further progress on getting Calva's quick start browser repl to work.

pez08:12:30

Some great trouble shooting there! Calva Jack-in does not add that option, so that is probably the issue. I think you can add it in your user level deps.edn. Not sure how, I'll try to figure out out.

pez10:12:24

Actually I don’t find a way to add that option in deps.edn, I’ve asked in #tools-deps about it.

brendnz10:12:00

Thanks @U0ETXRFEW . It is a little curious regular linux users have not come across this problem, if it is in fact related.

brendnz10:12:03

Ah, but then again, even that http://clojurscript.org webpage said it happens only to some linux users; maybe not to any that have used Calva to date.

pez10:12:43

It's usually Windows is users that report odd behaviour like this. I guess there had to be balance. For all Mac and Linux users experiencing bliss there has to be some Windows users that suffer greatly.

pez10:12:14

If I add --repl-opts {:launch-browser false} to the command line that launches the cljs repl, I never get a server to connect the browser to. I don't quite understand why.

brendnz11:12:02

That is is expected behaviour. You have to manually connect to localhost:9000 from the browser after having done that, then the connection is completed. I need to delay the browser opening, otherwise I would not get a prompt back.

pez21:12:07

I mean that when I manually connect to localhost:9000 there is nothing there to connect to. The web server is not started.

brendnz02:12:37

@U0ETXRFEW, oh, might you have had something in your deps.edn file for the start directory (besides the clojurescript dependency) that might have prevented it?

brendnz04:12:59

Hi @U0ETXRFEW, please take my attached speculation with a grain of salt, as I may be using words and concepts I do not understand, not to mention it is only speculation.

pez14:12:29

I’m not sure what you are speculating about, so can’t really comment. 😃 Anyway, here’s the ClojureScript Quick Start Browser REPL jack-in command line:

clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"0.9.0"},cider/cider-nrepl {:mvn/version,"0.27.3"},cider/piggieback {:mvn/version,"0.5.2"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware cider.piggieback/wrap-cljs-repl]"
Running that will start cause the browser to open and the cljs repl to start. Adding the repl option to stop the browser start, also seems to stop the http server to start:
clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"0.9.0"},cider/cider-nrepl {:mvn/version,"0.27.3"},cider/piggieback {:mvn/version,"0.5.2"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware cider.piggieback/wrap-cljs-repl]" --repl-opts '{:launch-browser false}'
At least on my Mac, maybe it behaves differently on other systems.

brendnz17:12:09

@U0ETXRFEW, you are right. For me it is not a Calva problem, nor a WSL problem, but an Ubuntu problem. The code you gave me does not work at my bash terminal, which is why it does not work in Calva, and hence it is not a Calva issue. Thank you very much for your help, but there is nothing further you can do.

pez09:12:20

Maybe it is not a Calva problem, but it gets to be a problem for Calva users. So probably we should document this somehow. I’ll have a think about where it could fit.

brendnz12:12:11

Hi @U0ETXRFEW, I took parts of what we wrote here and posted them in reply a post of Sean Corfield in #clojurescript 9 hours ago.