Fork me on GitHub
#calva
<
2022-08-19
>
seancorfield04:08:37

So I'm trying to help out a beginner with a ClojureScript/Figwheel Q and tried jacking into a lein/figwheel-main project per the docs and after it starts the clj REPL stuff, it is failing to connect to the cljs part:

; Starting cljs repl for: Leiningen + Figwheel Main...
; Execution error (ArityException) at user/eval14544 (form-init6151943759672209425.clj:1).
Wrong number of args (0) passed to: figwheel.main.api/start
; Failed starting cljs repl

seancorfield04:08:49

This is the jack-in command it says it is running:

lein update-in :dependencies conj '[nrepl,"0.9.0"] '-- update-in :dependencies conj '[cider/piggieback,"0.5.3"] '-- update-in :plugins conj '[cider/cider-nrepl,"0.28.5"] '-- update-in '[:repl-options,:nrepl-middleware] 'conj '["cider.nrepl/cider-middleware"] '-- update-in '[:repl-options,:nrepl-middleware] 'conj '["cider.piggieback/wrap-cljs-repl"] '-- repl :headless

seancorfield05:08:04

(given my complete lack of familiarity with cljs tooling and my now lack of use of lein since I stopped using it in 2015, I'm not sure how to debug/progress here)

seancorfield05:08:44

These are the commands I ran to create/setup the project:

$ lein new figwheel-main hello-world.core -- +npm-bundle --reagent
$ cd hello-world.core/
$ npm install

seancorfield05:08:06

If I do lein fig:build I get a cljs REPL and a browser pointed to localhost:9500 and I can change code and it hot-reloads... but then I can't figure out how to connect to that REPL from Calva (according to the docs, that doesn't seem like the right workflow).

seancorfield05:08:40

If I jack-in as above, hot-reloading on saving changes works but there doesn't appear to be any way to eval code into that connected REPL?

seancorfield05:08:37

I recreated the project with +deps and now I'm using deps + figwheel-main and everything is working as I would have expected. Very slick!

pez06:08:54

Thanks for sharing. I'll try this out myself and see if there is something broken in Calva with the lein project type.

seancorfield06:08:26

I just added re-frame to this scratch Reagent project (added the dep and copied in code from generating a basic re-frame template) and now I have a re-frame app running with Calva happily connected to both REPLs. This is a lot smoother than when I last attempted to do any cljs about a year ago.

pez06:08:26

Is there a reason figwheel main is used instead of shadow-cljs?

seancorfield06:08:41

The OP had problems with shadow-cljs and Emacs/CIDER -- and I preferred figwheel over shadow when I was looking at cljs again last year (after a seven year break from cljs).

seancorfield06:08:11

Given what seems to be working, I don't know why I would switch to shadow at this point?

seancorfield06:08:30

(it's mildly annoying that saving a file causes recompilation + reloading such that my app state is blown away... but I suspect I can find good ways around that or a workflow where the "db" state is easy to cache/restore in such situations)

pez06:08:44

Me neither. I'm not suggesting that you switch. Was curious about the reasons. shadow-cljs is so freaking good I wondered why use something else. 😃

pez06:08:53

You can probably disable the hot-reload-on-save. I often do that and use custom repl commands to reload things myself at will.

seancorfield07:08:01

Shadow being a "parallel cljs" env (i.e., its own compiler fork) and leaning so heavily on npm makes me... nervous... Figwheel seems so much simpler...

pez07:08:26

This worked for me: 1. lein new figwheel-main hello-world.core -- +npm-bundle --reagent 2. cd hello-world.core/ 3. npm i 4. code . 5. Jack-in Leiningen + Figwheel Main: a. No alias b. Launch dev profile c. Start dev and test build d. Browser opened starting the cljs app e. Back in Calva connect to the dev build 6. REPL away

pez07:08:28

I had a REPL running in less than 3 minutes.

seancorfield07:08:39

Fair enough... the tooling is pretty impenetrable to me right now so it's hard to know whether I'm doing something wrong or the docs are confusing or what.

pez07:08:49

Now I wanna try the +deps option. Wasn't aware about that one.

seancorfield07:08:10

I'm trying to figure out how to get tests to run with zero success right now...

pez07:08:59

Calva and cljs tests... Rough.

pez07:08:02

I use a custom repll command like so:

{
            "name": "run-tests",
            "snippet": "(cljs.test/run-tests)",
            "repl": "cljs",
            "key": "t"
        },

pez07:08:11

And I call the current top level form to run individual tests:

{
            "name": "Call Current Top Level Form",
            "key": "c",
            "snippet": "($top-level-form)"
        },

seancorfield07:08:33

Got it working with auto-testing but had to do a bit of editing of the test.html page -- and it seemed to be relying on the dev build, not the test build so that aspect is pretty confusing too...

pez07:08:39

It's probably because auto-testing is meant for the dev workflow when you want to be using the dev build.

seancorfield07:08:18

Apparently so... and therefore it's completely confusing to me that there even is a :test build...?

pez07:08:14

The test build is for running tests from the repl. Like my snippets there do.

pez07:08:02

And also maybe for running tests in CI. I'm not sure.

seancorfield07:08:05

Ah, and auto-testing is a dev thing for displaying them in a browser, if you have the right div/`id` and JS include in it...

pez07:08:15

Neat. Didn't know about that. With shadow I have the jack-in output visible while coding and see the tests run on save.

pez07:08:17

Looks like so when hacking on Calva:

seancorfield07:08:48

clojure -M:fig:test opens a browser window with test results displayed -- not very conducive to CI but works locally (the auto-test thing seems better).

seancorfield07:08:28

Ah, figured out how to have both the app and its auto-run test output on the same page and they both hot-reload: nice!

metal 1
seancorfield07:08:31

After midnight. I should stop tinkering and go to bed. But it is progress.

💤 1
Gabriel Kovacs18:08:52

Hi! Could you please share your steps for using calva in a deps.edn + Figwheel Main project? I was not able to make it work.

seancorfield18:08:54

I don't remember specifics and I've since deleted the project since it was just scratch work to help someone else out. I reported all the steps in this thread tho' so you could probably reconstruct it from that...?

Gabriel Kovacs19:08:18

Not really. I crated the project as described here:https://www.learn-clojurescript.com/section-1/lesson-5-bootstrapping-a-clojurescript-project/ I already tried to start the project and start calva afterwards and vice versa but it did not work for me. I am probably missing something :)

pez19:08:20

I'll have a look and see if I can help in any way.

👍 1
pez19:08:20

Did you create the project using clj-new or manually?

Gabriel Kovacs19:08:35

$ clj -X:new :template figwheel-main :name learn-cljs/weather :args '["+deps" "--reagent"]'
having in ~/.clojure/deps.edn

Gabriel Kovacs19:08:42

{:aliases
 {:new {:extra-deps {seancorfield/clj-new
                     {:mvn/version "1.1.243"}}
        :exec-fn clj-new/create
        :exec-args {}}}}

pez19:08:32

OK. So these steps worked for me. 1. create project with clj-new 2. open the weather folder in VS Code 3. Issue Jack-in command 4. Select deps.edn + Figwheel Main project type 5. Select figalias to launch with 6. Select to start the fig and test builds 7. The repl started ... 8. After a while the browser opened with the app 9. Calva asked for which build to connect, I select fig 10. I have a REPL Speculating here that maybe you did not choose the fig alias?

seancorfield19:08:12

(what caught me out was specifying :fig and :build as the aliases for Jack-In to launch with -- which you would use to start the REPL outside Calva but doesn't work for Jack-In!)

Gabriel Kovacs19:08:11

Thank you both! It works somewhat but it is still not working properly. I do keep getting some errors. At the moment this is not so critical as I am still learning more or less basic stuff. And yes I also skipped over the alias as well as choose :fig and :build 😄.

Gabriel Kovacs19:08:52

Instead of executing the steps on my initial project I created a new one and everything worked like a charm. I probably broke something in my initial project.

pez19:08:58

Thanks for reporting back, @U02AMR8032L . At least now you know that there is a base from which it works and you'll notice if you break something. 😃

❤️ 1
pez19:08:35

Not following about your comment about outside Calva and doesn't work for jack-in, @U04V70XH6? Can you elaborate a bit?

seancorfield20:08:20

@U0ETXRFEW The docs/readme for figwheel/template say to start the repl with :fig:build as I recall but if you specify both for Jack-In it doesn't work (because :build introduces :main-opts -- which Calva warns about, as I recall?)

pez21:08:35

Ah, then I'm following. It is indeed not easy to figure out what to select for the various options. Maybe I should have a look at those template docs and see if they could have a section for CIDER-ish editors. Or maybe a section for Calva even.

seancorfield21:08:42

Well, the docs are pretty explicit not to use aliases that include :main-opts so that was definitely "my bad" but the "normal" way to run Figwheel Main from the command-line is to use :fig:build in order for those :main-opts to kick in and start the whole watch/reload process off along with the REPL 🙂

thomas08:08:01

I'm (accidentally) running a long command in the repl.... is there a way to stop it? something like crtl-c ?

thomas08:08:02

I found it...

thomas09:08:05

but now I have about 0.5m lines in my repl and it has become kinda slow. restarting it? or is there a way to clear it all?

kstehn09:08:35

Do you mean the output.calva-repl? If So you can just select everything and delete the content. At least That is what i Do when its too much.

👍 1
👋 1
thomas10:08:39

good idea... let me try that

Lukas Domagala15:08:41

Notebooks handling rich comments as their own cells: https://output.circle-artifacts.com/output/job/17557611-9e87-48a5-a76f-13577e35a9a6/artifacts/0/tmp/artifacts/calva-2.0.294-feature-notebook-rich-comments-511ef43e.vsix It’s still very rough and will destroy your comment formatting, but otherwise it seems to do the trick 🥳

🥳 1
Lukas Domagala16:08:47

Whitespace handling is fixed now: https://output.circle-artifacts.com/output/job/b1543e3b-35f4-4b3d-8855-19288aa3d64e/artifacts/0/tmp/artifacts/calva-2.0.294-feature-notebook-rich-comments-fb35441d.vsix For new cells that get created in the middle of the comment I had to make some arbitrarily whitespace decisions: use spaces, indent the same as the block above, and have a free line between forms. I think this might actually be done for now and unless there are major flaws here I’ll switch to markdown comments and LSP integration.

Drew Verlee16:08:10

paredit is installed and on my default with clava right?

Drew Verlee16:08:38

i want to "raise expresions" which the docs say is ctrl-alt-r or -p and it's doing nothing.

seancorfield18:08:33

ctrl+alt+p followed by ctrl+alt+r -- it's two chords, one after the other.

seancorfield18:08:23

(you can hold down ctrl and alt and then press p and then r)

👀 1
1
pez21:08:55

The latter way is how I do it. Less finger bending with my keyboard layout.