Calva Doccumentation has Moved

calva.io

How to Use Calva with Luminus

Luminus is a powerful and versitle Leiningen template for creating web development projects. It comes with built in configuration for making it easy to use Calva as your Clojure(Script) editor.


Server + shadow-cljs

Basically this is the same wokflow as with Server only. Behind the scenes there is more happening, though. Such as the ClojureScript app being built and the CLJS REPL connected once the web app is running.

  1. If you haven't created the project yet, create a new shadow-cljs Luminus project. E.g.: sh $ lein new luminus my-luminus-shadow +reagent +shadow-cljs
  2. This creates the folder my-luminus-shadow. Open it in VS Code: sh $ code my-luminus-shadow
  3. Use the Calva command Start a Project REPL and Connect (aka Jack-in): ctrl+alt+c ctrl+alt+j
  4. Select to start Server + Client – my-luminus-shadow, and wait for the Terminal Calva Jack-in output to say [:app] Build completed.
  5. Open 127.0.0.1:3000 in your web browser and start hacking.

Note: Currently Calva has troubles following the app-start with shadow-cljs, so Calva will report Jack-in done. in the Calva says output before shadow-cljs is actually done building the app. If you open the app page at that stage, you will see a message to ” Please run lein shadow watch app”. Rest assured that this is already underway. Follow the Jack-in process in the Terminal tab in VS Code for the message that the app is built, then reload the app page in the web browser.

Server Only

The workflow here is really just: Jack-in and start hacking. The first time it involves these steps, however:

  1. If you haven't created the project yet, create a new server only Luminus project. For a all-defaults setup it is like so: sh $ lein new luminus my-luminus-server
  2. This creates the folder my-luminus-server. Open it in VS Code: sh $ code my-luminus-server
  3. Use the Calva command Start a Project REPL and Connect (aka Jack-in): ctrl+alt+c ctrl+alt+j and wait for the Calva says output to say Jack-in done.
  4. Open 127.0.0.1:3000 in your web browser and start hacking.

Server + Figwheel

This is Legacy Fighwheel (lein-figwheel), so the recommendation is to use the shadow-cljs setup instead. As with the server only, the workflow here is really just: Jack-in and start hacking. The first time it involves these steps:

  1. If you haven't created the project yet, create a new server only Luminus project. E.g.: sh $ lein new luminus my-fw +reagent
  2. This creates the folder my-fw. Open it in VS Code: sh $ code my-fw
  3. Use the Calva command Start a Project REPL and Connect (aka Jack-in): ctrl+alt+c ctrl+alt+j, select Server + Client - my-fw in the Project type picker menu, and wait for the web app to pop open in your web browser.
  4. Start hacking.

If you rather open the web app yourself, open .vscode/settings.json and change "shouldOpenUrl" to false in the preconfigured Calva connect sequence. Calva will then print the URL 127.0.0.1:3000 in the output, so that you can click it open.

Etcetera

You will have three Calva Custom Command Snippets configured. Invoke them by issuing the Run Custom REPL Command, ctrl+alt+c . (that's a dot). The commands control the Luminus server:

  1. Start <project> Server
  2. Stop <project> Server
  3. Restart <project> Server

When used, Calva will open its REPL window and excute the command, if it is not already opened. You can close this window if you prefer to use the REPL directly from the Clojure files.

Calva also opens the REPL window, and starts the Luminus server, as part of the Jack-in process.