Fork me on GitHub
#calva
<
2022-01-10
>
brendnz00:01:16

Hi @pez , Calva's custom connect sequences facility works very well for me. This is a long post, so the gist of it is the following code snippet. (assoc (cljs.repl.browser/repl-env) :launch-browser false) All the rest below is commentary. You will recall I could not start ClojureScript REPL in Calva on my Linux system (in WSL) because of the problem mentioned in https://clojurescript.org/guides/quick-start > If you are running Linux and the REPL does not start, try disabling browser auto-launch and opening http://localhost:9000 manually … The connect sequence that comes with Calva for its Clojurescript built-in for browser is as follows (ex nrepl/connectSequence.ts):

"ClojureScript built-in for browser": {
        name: "ClojureScript built-in for browser",
        buildsRequired: false,
        isStarted: true,
        connectCode: "(do (require 'cljs.repl.browser)
          (cider.piggieback/cljs-repl 
          (cljs.repl.browser/repl-env)))",
        isConnectedRegExp: "To quit, type: :cljs/quit"}
The following custom connect sequence works for me; the critical aspect being replacing the value of the :launch-browser key in the repl-env map returned from (cljs.repl.browser/repl-env)
"calva.replConnectSequences": [{
        "name": "brendnz custom sequence",
        "projectType": "deps.edn",
        "cljsType": {
            "dependsOn": "User provided",
            "connectCode": "(do (require 
               'cljs.repl.browser) (cider.piggieback/cljs-repl 
                (assoc (cljs.repl.browser/repl-env) :launch-browser false)))",
            "isConnectedRegExp": "To quit, type: :cljs/quit"}}]
By design, my custom connect sequence will halt when the output.calva-repl window says "Connecting cljs repl: brendnz custom sequence...". I then start the web browser manually from the terminal, e.g. "firefox localhost:9000", then Calva continues its jack-in process and I end up with clojurescrpt prompt cljs:user:> as wanted. If I THEN wanted to go the "Fire up the Clojurescipt Quick Start Browser REPL" route, in order to see the training pages that come with it, I would have to let the files load (tabs "index.html" and "core.cljs"), and things would work (subject to some warnings printed to the terminal), and my prompt changes to cljs:hello-world.core:>, the namespace of the core.cljs file. If I did it in REVERSE ORDER, load the training files first by using the standard connect sequence, I would have to disconnect from the repl after loading the pages and then connect to a new repl using the custom connect sequence.

🙌 1
pez08:01:13

Thanks for sharing! This might open up for a change in Calva that can avoid the bug. I will experiment a bit with it.

Pratik07:01:35

Connecting to REPL feature has suddenly stopped working for me(v2.0.233) with these errors

Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Syntax error compiling var at (/private/var/folders/yw/g6ls8kw94k3dr57_ljtsdmvm0000gp/T/form-init6850950663255155271.clj:1:9566).
Unable to resolve var: cider.nrepl/wrap-apropos in this context

Full report at:
/var/folders/yw/g6ls8kw94k3dr57_ljtsdmvm0000gp/T/clojure-16654531154009651817.edn
Error encountered performing task 'repl' with profile(s): 'base,system,user,provided,dev'
Subprocess failed (exit code: 1)
Jack-in process exited. Status: 1

pez07:01:39

Is this after jack-in or have you started the server some other way?

Pratik07:01:03

jack-in only

Pratik07:01:24

My bad, doing lein clean fixed it as mentioned in https://clojurians.slack.com/archives/C17JYSA3H/p1552583288022000 thread

pez07:01:36

Good to know about this. Thanks!

Lukas Domagala14:01:40

I’m working on https://github.com/BetterThanTomorrow/calva/pull/1459 and I’m thinking about which jars should be checked for config files. The most general version would check all classpath jars when you open the project. The problem with that is: whats the class path before you started a repl? We could choose some default or ask clojure -Spath but both options seem complicated and error prone at first. Maybe asking lsp would work here? @ericdallo The more accurate way would be to ask nrepl once it’s connected, but that would mean you only get stuff once you are jacked in, which might be ok as a starting point. Any opinions?

ericdallo15:01:44

I think you are doing the same of https://clojurians.slack.com/archives/CBE668G4R/p1641827273070900?thread_ts=1641663798.033400&amp;cid=CBE668G4R? Anyway, I just added a commit adding the classpath info on the serverInfo command of clojure-lsp, so you just need to ask to clojure-lsp this serverInfo and the classpath should be availble on the response

ericdallo15:01:59

Calva already request serverInfo/raw somewhere

Lukas Domagala15:01:17

ah not sure how i missed that thread, thank you. great work as always!

👍 1
Lukas Domagala15:01:17

and I’m doing something different, just also happen to need the classpath. I’m actually trying to load all .calva/config.edn files in all jars in the classpath, similar to lsp loading clj-kondo configs from the jars

ericdallo15:01:55

The classpath output from lsp should help you with that I think

Lukas Domagala15:01:00

yes, a lot, thank you! I’ll have a look in the lsp code to see what you choose as the classpath if the user hasn’t selected an alias yet

ericdallo15:01:28

The default dev:test

👍 1