VSCode / Calva.


I have used mostly IntelliJ IDEA with Cursive in my Clojure programming. In my previous editor related blog post Comparing Clojure IDEs - Emacs/Cider vs IDEA/Cursive I wanted to see if I’m able to configure Emacs with Cider to have as much look-and-feel and developer experience as my IntelliJ/Cursive setup.

In this new blog post I’m experimenting if I’m able to configure VSCode with Calva to have the same look-and-feel and developer experience as my IntelliJ/Cursive and Emacs/Cider setups.

Versions used in this blog post:

My workstation is Ubuntu 2022.

VSCode and Calva

VSCode has been around about 7 years (since 2015). It is based on the Electron framework and is a pretty lightweight editor but at the same time being very powerful and configurable editor. I have nowadays used VSCode when programming infrastructure code: Pulumi with Typescript (see: my previous blog post: Pulumi Input / Output Business)

Calva provides an integrated development environment for Clojure programming using VSCode. In that sense it serves the same role as Cider for Emacs - Cider actually has been a major inspiration for Peter Strömberg, the main Calva developer (see the Calva Github repo for all Calva developers). You might be interested to listen to Peter Strömberg - Cognicast Episode 167 podcast episode, in which Peter Strömberg tells more about Calva.


The Calva documentation says:

Consider using Jack in to inform yourself on how to start your REPL to Calva’s satisfaction.

Reading this I was a bit confused - do I miss something in my developer experience if I connect to a running REPL as I have used to do with IntelliJ/Cursive and Emacs/Cider? Luckily Peter Strömberg, replied to my question in Clojurians Slack - you can either use the Jack in or connect to a running REPL - the developer experience is the same. BTW: I had a feeling that Peter is pretty active in Clojurians - if you start using VSCode/Calva, do not hesitate to ask for help in the Clojurians Slack #calva channel.

You need to have certain dependencies in your deps.edn file for Calva to work properly. See command Calva: Copy Jack-in Command to Clipboard for which dependencies needs to be there. E.g. for me it says:

clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"1.0.0"},cider/cider-nrepl {:mvn/version,"0.28.5"}}}' -M:common:backend:test:dev -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"

So, I like to start my REPL in command line. I have a Justfile recipe for it:

    clj -M:dev:test:common:backend:calva:kari  -i -C

… and in my deps.edn I have:

           :backend {:extra-paths ["src/clj"]
                     :extra-deps {nrepl/nrepl {:mvn/version "1.0.0"}
           ;; Calva specific
           :calva {:extra-deps {cider/cider-nrepl {:mvn/version,"0.28.5"}}
                   :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

So: I have the dependencies in my aliases :backend and :calva.

Using Calva you connect to the running REPL process with command Connect to a Running REPL Server in the Project.

See the main picture for a Calva view, which shows the editor, output window and problems view. You can evaluate your code in the editor just as with Emacs/Cider or IntelliJ/Cursive.

Remember to check this configuration in your VSCode settings.json file:

"calva.evaluationSendCodeToOutputWindow": true,

This way you can have the REPL output window to echo when you evaluate your Clojure source code in the editor.

Clj-kondo integrates out-of-the-box with Calva and shows the issues in your code (as the Unresolved symbol: a in the example).

Color Customizations

This was a bit difficult for me since I’m not a VSCode specialist. But after some googling I figured it out. I installed Jymeng Leuven Theme as a basis. And then using VSCode Semantic Highlight Guide I changed some editor colors to have the same look as in my Emacs and IntelliJ setup. In VSCode’s

Hint. In VSCode give command: Developer: Inspect Editor Tokens and Scopes. Using this tool you can inspect the Clojure code. E.g. keyword :doc shows like:

VSCode Inspect Editor Tool

So, the textmate scope is constant.keyword.clojure. In settings.json, you can add a custom color for this editor entity type:

VSCode settings.json

… and look in my VSCode looks like:

VSCode Clojure look

… which is pretty much the same as I have in IntelliJ:

IntelliJ look

Hotkeys for Slurping and Barfing

To understand my slurping and barfing hotkeys the reader needs to read my previous blog post Dygma Raise Keyboard Reflections Part 1 first. In that blog post, I explain how I have configured the CapsLock key to function as AltGr key in order to use it to get the various parentheses without twisting my right thumb. Then the reader needs to understand the two layers I have configured in my Dygma Raise. I really recommend Dygma Raise - the best keyboard I have ever used - a perfect keyboard for a programmer.

You can edit your Calva Paredit experience pretty much the same as you can configure it using Emacs/Cider or IntelliJ/Cursive.

One extra configuration. I use Emacs keymappings and you need to add this configuration to settings.json file in order to copy the kill sexp to the clipboard in VSCode (to paste it somewhere else in your code).

"calva.paredit.killAlsoCutsToClipboard": true,

An example how I configured barfing to be the same hotkey as in my IntelliJ and Emacs setup:

VSCode / Calva Barfing

(LeftArrow in my Linux keympap is CapsLock+J, so: i, j, k and l are arrow keys with CapsLock in my setup.)


You can configure VSCode/Calva pretty much with the same look-and-feel and developer experience as IDEA/Cursive and Emacs/Cider. All three are great editors for Clojure programming - it is up to taste which one you want to use. If you are a complete Clojure newbie and you have used VSCode as your main editor before, I recommend VSCode/Calva.

The writer is working at Metosin using Clojure in cloud projects. If you are interested to start a Clojure project in Finland or you are interested to get Clojure training in Finland you can contact me by sending email to my Metosin email address or contact me via LinkedIn.

Kari Marttila

Kari Marttila’s Home Page in LinkedIn: https://www.linkedin.com/in/karimarttila/