Fork me on GitHub
#calva
<
2020-06-26
>
Markus Str17:06:03

Hi! It's my first week of learning clojure. I just switched from cursive to vscode+calva. I'm trying to have my setup for a lein+figwheel project but somehow the Calva REPL doesn't have state (like functions I defined) from namespaces (also the app isn't on localhost port). In my terminal (outside Vscode) I can run lein figwheel and see my app in localhost. I can also (ns somenamespace) and it has the variables from there. Doesn't work with canva repl tho. Any suggestions?

Markus Str17:06:55

Eval current form and load current namespace vscode commands also don't work

pez18:06:20

It looks like the problem is that the app isn't started as it should. You should have a cljs repl, but that is a clj one... How do you start the project?

Markus Str18:06:45

I do "Calva: Start a Project REPL and Connect aka (jack-in)"

Markus Str18:06:30

and then I chose leiningen + figwheel main (bc in iTerm I can just type lein figwheel -- which works for it)

Markus Str19:06:48

This is the boilerplate I use: https://github.com/mkstra/kbasegen I copied the deps.edn from some forum

Markus Str19:06:04

@U0ETXRFEW found your post here: https://github.com/BetterThanTomorrow/calva/issues/81 will try but don't know if still relevant

Markus Str19:06:35

ok didn't work...

bringe19:06:24

Hi @US22FPMPX, I cloned that repo you linked above and ran calva's jack-in command with the lein + figwheel option and the :dev profile, and I get this error upon startup.

bringe19:06:53

You may need to add a figwheel build file. And like @U0ETXRFEW said, in your screenshot you have a clj repl window open. I believe the lein + fighweel jack-in may start both a clj and cljs repl and may automatically connect to the clj repl first.

bringe19:06:00

You would need to run "Calva: Connec to a Running REPL Server in Project" and choose localhost:<port-of-cljs-repl>, which probably would be somewhere in terminal output if figwheel started one.

bringe19:06:32

Calva can only be connected to a single repl at a time per vs code window. So you can only connect to either the clj repl or the cljs repl in a given vs code window

bringe19:06:11

I'm not super familiar with fighweel or that startup profile (lein + fighweel) to give more detailed instructions, but maybe the info above can help you.

Markus Str19:06:22

ok so I added a deps.cljs.edn file in root with {:main <projectname>.core} in it (as mentioned here: https://figwheel.org/docs/create_a_build.html) Then I try jack-in: CLJ repl yes, CLJS fail

Markus Str19:06:28

The other approach - connecting to existing session: when I press enter for localhost:3449 nothing happens. But localhost:7002 is a new thing where it says:

Creating cljs repl session...
Connecting cljs repl: Leiningen + Figwheel Main...
Could not locate figwheel/main/api__init.class, figwheel/main/api.clj or figwheel/main/api.cljc on classpath.
Failed starting cljs repl

Markus Str19:06:51

They say that's bc I don't have deps.edn but I do ... trying to figure it out

Markus Str20:06:01

Ok couldn't find anything relevant or recent that worked. I'm not sure if deps.edn is redundant if I have figwheel dependencies in my project.clj . Apparently it's a classpath issue (I did this https://figwheel.org/docs/classpaths.html and updated deps.edn:

{:deps {org.clojure/clojure {:mvn/version "1.9.0"}
        org.clojure/clojurescript {:mvn/version "1.10.773"}
        com.bhauman/figwheel-main {:mvn/version "0.2.9"}
        com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
 ;; add "target" path here
 :paths ["src" "src-cljs" "resources" "target"]}
 :aliases
 {:fig {:main-opts ["-m" "figwheel.main"]
  :nrepl-server {:extra-deps {org.clojure/tools.nrepl {:mvn/version "0.2.13"}
                              cider/cider-nrepl {:mvn/version "0.19.0-SNAPSHOT"}
                              refactor-nrepl {:mvn/version "2.3.1"}}
                 :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}
  :nrepl-client {:extra-deps {org.clojure/tools.nrepl {:mvn/version "0.2.13"}
                              cider/cider-nrepl {:mvn/version "0.19.0-SNAPSHOT"}
                              refactor-nrepl {:mvn/version "2.3.1"}}
                 :main-opts ["-m" "nrepl.cmdline" "--connect" "--host" "localhost" "--port"]}
  }}

Markus Str20:06:34

I got no idea what all this means. It reminds me of my webpack days which I've sworn to never revisit. I've put the new repo here: https://github.com/mkstra/site2 . Maybe @U0ETXRFEW can take another look and the classpath issue is easy to fix

Markus Str20:06:28

seems project.clj and deps.edn are redundant but it gets recommended to have deps.edn everywhere idk

pez20:06:10

I'll have a look. I think you are brave in not giving up easily. This is probably mostly about figuring a few things out about how things are wired together. brb

pez20:06:40

OK. So I got it working. This is a lein-figwheel project. In Calva Jack-in, it is called Legacy Figwheel, because the maintained version of figwheel is Figwheel Main. Anyway, if you choose Legacy Figwheel as project type at Jack-in, and then the dev profile Calva will start the project correctly.

pez20:06:00

I recommend using Calva settings to not open the REPL Windows, and instead use the REPL from inline evaluation. Like what is suggested here: https://calva.io/eval-tips/#current-top-level-form

pez20:06:04

Anyway, the project is using Leiningen as both the build tool and for dependencies, so no need for a deps.edn file. And, when reading Figwheel docs, make sure it is lein-figwheel that is described. Figwheel Main is a different thing (even if it does very similar things). It is no big deal switching to Figwheel Main later, so you don't need to worry about that right now I think. Legacy Figwheel will serve you well as you get acquainted with ClojureScript development. The #beginners channel is full of awesome and friendly people, btw. I have got tons of help there.

Markus Str22:06:12

Wow. It was just Legacy not Main ... yes those names are confusing. Thanks @U0ETXRFEW!

👍 6