This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-19
Channels
- # aws (2)
- # babashka (4)
- # babashka-sci-dev (7)
- # beginners (92)
- # biff (7)
- # calva (64)
- # cider (2)
- # cljsrn (14)
- # clojure (8)
- # clojure-australia (5)
- # clojure-europe (14)
- # clojure-norway (8)
- # clojure-spec (36)
- # clojurescript (19)
- # component (15)
- # cursive (1)
- # data-science (6)
- # girouette (5)
- # hyperfiddle (3)
- # juxt (5)
- # leiningen (10)
- # lsp (7)
- # malli (12)
- # nbb (90)
- # polylith (1)
- # portal (11)
- # rdf (7)
- # reagent (6)
- # reitit (40)
- # remote-jobs (1)
- # shadow-cljs (21)
- # specter (5)
- # squint (83)
- # tools-deps (17)
- # vim (7)
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
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
(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)
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
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).
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?
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!
Thanks for sharing. I'll try this out myself and see if there is something broken in Calva with the lein project type.
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.
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).
Given what seems to be working, I don't know why I would switch to shadow at this point?
(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)
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. 😃
You can probably disable the hot-reload-on-save. I often do that and use custom repl commands to reload things myself at will.
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...
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
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.
I'm trying to figure out how to get tests to run with zero success right now...
I use a custom repll command like so:
{
"name": "run-tests",
"snippet": "(cljs.test/run-tests)",
"repl": "cljs",
"key": "t"
},
And I call the current top level form to run individual tests:
{
"name": "Call Current Top Level Form",
"key": "c",
"snippet": "($top-level-form)"
},
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...
It's probably because auto-testing is meant for the dev workflow when you want to be using the dev build.
Apparently so... and therefore it's completely confusing to me that there even is a :test
build...?
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...
Neat. Didn't know about that. With shadow I have the jack-in output visible while coding and see the tests run on save.
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).
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!
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.
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...?
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 :)
clj-new
$ clj -X:new :template figwheel-main :name learn-cljs/weather :args '["+deps" "--reagent"]'
having in ~/.clojure/deps.edn
{:aliases
{:new {:extra-deps {seancorfield/clj-new
{:mvn/version "1.1.243"}}
:exec-fn clj-new/create
:exec-args {}}}}
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 fig
alias 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?
(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!)
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 😄.
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.
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. 😃
Not following about your comment about outside Calva and doesn't work for jack-in, @U04V70XH6? Can you elaborate a bit?
@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?)
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.
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 🙂
I'm (accidentally) running a long command in the repl.... is there a way to stop it? something like crtl-c ?
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?
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.
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 🥳
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.
paredit is installed and on my default with clava right?
i want to "raise expresions" which the docs say is ctrl-alt-r or -p and it's doing nothing.
ctrl+alt+p
followed by ctrl+alt+r
-- it's two chords, one after the other.