Fork me on GitHub
#calva
<
2020-01-20
>
Adriaan Callaerts16:01:50

Hi people! I'm trying to get calva to work on a fresh new project using leiningen + figwheel-main but can't seem to get the jack-in to work... I've tried looking for documentation and/or examples but can't seem to find any. Can you guys point me to something I can use to help myself out?

pez16:01:59

Can you describe the steps you are taking and where it breaks down?

Adriaan Callaerts16:01:00

I've tried to stay as close as possible to the just-out-of-the-box setup and from there started adding config... Currently I have a minimal project.clj file

(defproject dn.cp-planning "0.1.0-SNAPSHOT"
  :description "Planning application"
  :url ""
  :license {:name "Eclipse Public License"
            :url ""}

  :min-lein-version "2.7.1"

  :dependencies [[org.clojure/clojure "1.10.1"]
                 [org.clojure/clojurescript "1.10.597" :exclusions [com.google.errorprone/error_prone_annotations com.google.code.findbugs/jsr305]]
                 [reagent "0.9.1"]
                 [re-frame "0.11.0"]
                 [clj-commons/cljss "1.6.4" :exclusions [args4j]]]

  :source-paths ["src"]

  :aliases {"fig"       ["trampoline" "run" "-m" "figwheel.main"]
            "fig:build" ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"]
            "fig:min"   ["run" "-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]}

  :profiles {:dev {:dependencies [[com.bhauman/figwheel-main "0.2.3" :exclusions [args4j commons-codec]]
                                  [com.bhauman/rebel-readline-cljs "0.1.4" :exclusions [args4j]]
                                  [devcards "0.2.6" :exclusions [sablono args4j]]]
                   }})

Adriaan Callaerts16:01:41

and then I added this to my vscode project settings.json:

{
    "calva.replConnectSequences": [
        {
            "name": "Leiningen + Figwheel Main",
            "projectType": "Leiningen",
            "cljsType": "Figwheel Main",
            "menuSelections": {
                "leinAlias": "fig:build",
                "leinProfiles": [
                    ":dev"
                ]
            }
        }
    ]
}

Adriaan Callaerts16:01:20

I basically started from lein new figwheel-main dn.cp-planning -- --reagent +lein

Adriaan Callaerts16:01:24

running the default jack-in command seems to start the lein+figwheel stuff fine, but in the editor itself it seems to hang on "Launching REPL using Leiningen + Figwheel Main" (that's what it says in the status bar). I've noticed the setup doesn't write an nrepl-port file, so maybe that's what calva is waiting for?

pez20:01:04

Try without an alias. I think that is what is wrong there.

Adriaan Callaerts09:01:45

cool, that worked! thanks. If you have the time and energy, could you explain why it didn't work with the alias? I'm new to clj(s) and I'm still trying to make sense of a lot of the new info that's hitting me. The tooling is turning out to be a real head-scratcher for me, so I'm keen to learn and get a better understanding of how stuff works

pez10:01:44

I can try... 😃 This is not about ClojureScript, but rather about the tooling Calva needs for connecting to the project REPL. Central in this is that a CIDER nREPL server needs to be started that will be Calva's way to speak to your Clojure (and/or ClojureScript) program. To ensure this, Calva's jack-in command starts this server as the main of the program. But since many aliases also has a main argument Calva will, in the presence of an alias, not do it, but rather rely on that the alias starts the nREPL server. This is something that those standard Figwheel main aliases do not do (for very good reasons). Thus, using those aliases will just not work. I'm short of time right now so can't elaborate much more, but all is not lost, hopefully... I try to explain the Jack-in a bit in depth here: https://calva.readthedocs.io/en/latest/jack-in-guide.html

Adriaan Callaerts10:01:28

Ok. If I wanted to make a higher-level main function myself that would call both the main method in that alias AND the one that calva expects, what would the main argument for calva be?

pez10:01:28

If you make the alias call that higher-level function, then that would be used. Calva does not provide a main argument when there is an alias.

pez10:01:28

That said, I doubt you need an alias. Calva knows about Figwheel Main and will set things up in a similar way that the alias does.

pez10:01:19

Ah, OK I see what your question was now...

Adriaan Callaerts10:01:20

I got that. By disabling the alias I got it to work, I'm just trying to get a better grasp on things 😉

pez10:01:57

Look at the Jack-in command and you will see what the main argument is that Calva uses.

pez10:01:50

Since you are using a connect sequence you can tell Calva to not use any alias.