The Calva Journey Continues - Please Jack In

Calva, an easy to start with, and easy to use, environment for productive Clojure and ClojureScript coding, was just updated with features significant enough for me to sometimes refer to it as Calva 2. In fact, up to now, it couldn’t really be said that it was easy to get started with Calva.

Please install the new version and say goodbye to soul crushing, getting started issues, with the Jack-in command. And say hello to the brand new REPL Window. Calva also has a friendly new logo, thanks to @eccentric_j

Calva logo

The goal with Calva is to leverage the ease of use of Visual Studio Code to provide an environment where starting with, and using, Clojure is as smooth as possible.

Jack-in

We have brought the Getting Started story from reading pages of instructions and trial-and-horror with your profiles and/or project files, possibly giving up, to a simple command: Calva Jack-in. Inspiration is taken from CIDER.

Calva Jack-in starts your project and injects the dependencies Calva needs to power your work. It supports Leiningen, shadow-cljs and clj/deps. (Boot support to be added.) ClojureScript support is an important part of Calva and a lot of effort has been put into making the Jack-in help here. Calva will, via prompting, inject any necessary shadow-cljs, Figwheel or Figwheel Main dependencies.

We hope Calva with Jack-in will help make Clojure and ClojureScript more accessible to new users.

The new REPL Window Improves Support for Interactive Programming

Calva REPL Window Screenshot

Experienced Clojurians, as well as new users of the language, are now much better served in their interactive development. Some of the features of the new REPL Window are:

  • A sweet code editor:
    • Smooth Clojure code formatting
    • Structural editing powered by Paredit
    • Syntax highlighting
    • Code completion
    • Command history
  • Deep integration with the rest of Calva:
    • Commands for using the REPL Window to evaluate code in the edited files.
      • Automatic and temporary switching of the REPL window namespace when evaluating forms in editor files.
    • Keeping the predictable switching between Clojure and ClojureScript REPLs that the Calva powered file editors introduced.
  • Much improved results reporting:
    • Syntax highlighted
    • Pretty printed
    • Clear differentiation of evaluation results, output, and errors.
    • Stack traces with deep links into the code.

This is quite huge. Yes, certainly in terms of increased value to the Clojure developer using VS Code, but also in terms of what it actually took to bring this UI into VS Code, which lacks all the native UI building blocks to support this, except for WebViews.

This meant that the REPL window and its code editor had to be written completely from scratch. Think something like the essentials of Code Mirror. I can only take partial credit for this, as I would never have been able to code this myself. Most of the coding is the work of Matt Seddon, where I have been acting the product owner, first line tester, bug fixer, and now maintainer.

The Paredit powering the new REPL window is also written from scratch, by the way. This means we will be able to improve a lot on the Current Paredit implementation in Calva, which relies on an abandoned project. And the new Paredit is powered by careful Clojure code lexing, opening up for more predictable and precise code analysis and editing than before.

In summary, the new REPL window delivers more value today, and its underpinnings promises we can more easily deliver even more value in the coming releases.

Get Started with Clojure on VS Code.

It really is super easy:

  1. Install VS Code.
  2. Install Calva (via the Extensions pane).
  3. Open a Clojure(Script) file in the root of your project.
  4. Issue the command Start a project REPL and connect (aka Jack-in), ctrl+alt+c ctrl+alt+j

Besides REPL power, Calva includes code formatting, Paredit, and some little Parinfer support, so you are quite set. It also bundles Clojure Warrior which brings in rainbow parens and highlighting of unmatched parens. Clojure Warior brings sane highlighting of matching parens, and Calva therefore disables VS Code’s confusing/broken paren highlighting.

See the Calva README and Wiki for more information on usage. And of course, feel warmly welcome to join the #calva-dev channel on the Clojurians Slack to get support, discuss Calva ideas, or just to cheer us on.

The Future of Calva

The new REPL window and Jack-in enables the awesome VS Code editor to be much more useful for Clojure work. It is far from at par with Cider and Cursive, still, but we are moving along, trying to make Calva a viable option for people who like to keep using VS Code.

Now starts a period where most Calva development will be directed at supporting the new-to-Clojure users. We have received some great feedback lately, so we know about many of the things that trip new users up, and we plan to contribute to Clojure by making Calva ease the path.

However, do not expect lightning speed. Calva is maintained mostly by me (Peter Strömberg a.k.a. PEZ) alone. I have a demanding day job and can only devote so much time to Calva.

It is a blessing that some other people have done lots of the hard work to make the building blocks of Calva, I don’t want to risk forgetting anyone by starting to mention projects, but I must mention The Orchard, which is where Calva finds most of the Cider it is distilled from. Thanks, @bbatsov, you rock! I’d like to also express my gratitude to @thheller who not only provides shadow-cljs, which is an important part of the Calva development toolchain, but also for his patience with my stupid questions.

:heart: Happy Clojure and ClojureScript Coding! :heart:

40 Likes

Congratulations on the big milestone! The new logo is pretty awesome as well!

7 Likes

Congratulations. Much awaited release. Thank you very much.

2 Likes

Thank you for the update, Peter, this is truly excellent news. I am about to return to Clojure development at a new job and am currently evaluating the different environment options available.

Have you tried Calva with the new remote development feature of VS Code at all? How well do you think it could work? Details in case you are not familiar with it: https://code.visualstudio.com/docs/remote/remote-overview

When I was actively using Clojure for work I used to be a Cursive user. One feature I really missed from Calva the last time I tried it was that its Paredit mode wasn’t strict enough - in Cursive normal backspacing or deleting a bracket would simply not work while in Paredit mode. This helped a lot with keeping the parens balanced in case of accidental key presses. Calva did not enforce this when I tried it and allowed editing the file as normal. Is this something that it supports now? If not, is it something that might be added later, or is it something that is hard to do in VS Code?

2 Likes

No, never heard of it until now, even. :smile: Please give that a try and let me know how you fare.

As for stricter Paredit, there is some support for that now, through a setting that enables some key bindings. It’s far from perfect, but anyway.

I certainly will give it a go. I find that remote dev thing in VS code very impressive and I’m really hoping I can use it with Calva.

It appears to be working although I haven’t done a lot in it. These are the steps I took:

  1. Windows 10 Home
  2. Enable WSL
  3. Install Ubuntu in WSL
  4. Install java in WSL
  5. Install latest clojure in wsl
  6. Install the Remote - WSL extension in VS Code
  7. Launch remote window
  8. Install Calva (gets installed into the WSL instance)
  9. Work away

Nice!!!

Edit: removed part about java 8 vs 11 as I couldn’t repro the error I had gotten earlier

3 Likes

Great to hear! Can you make a page about it on the Calva wiki?

What I see here is @PEZ showing us how we can beat the Lisp curse in the Clojure community: don’t just explore the space of ideas, but care about the community effort, care about the product quality; and then do the work. Congratulations on the release!

5 Likes

Here you go: https://github.com/BetterThanTomorrow/calva/wiki/VS-Code-Remote-Development

2 Likes

Thanks! That is awesome.

Do you have the error messages you get with Java 11? If so that would be good to have filed as an issue.

Looks great! I’ll soon have to try it out. Even though I doubt something can persuade me away from Emacs now, I’m always looking for something easy to start people with, yet powerful enough for them to learn the full REPL workflow and realize Clojure actually has great IDE features.

So thank you for all the work on Calva, Clojure really needs an easy yet full featured IDE to start with and I think VS Code is best positioned to be that.

2 Likes

I encourage everyone to try it out with the “would I want to introduce Clojure too someone with this?” hat on. I’d love the feedback and welcome the suggestions on what needs focus.

Will do!

I also have to say. I didn’t start with Emacs myself. And I doubt I could have. Being new to Lisp, Clojure and Functional Programming and adding Emacs on top all at once would have been too much I feel.

I started with Eclipse CounterClockWise. Which surprisingly is still one of the easiest Clojure IDE I’ve seen. The features were simple and intuitive, very easy to get started with, and very well featured. I especially loved the bindings.

Unfortunately, the project is abandoned, and it now only works with a very old Eclipse, and hasn’t kept up with Clojure that well.

I really hope Calva can take its place as an entry level but even just an alternative for people who don’t like Emacs.

Actually, it could be a good idea to check out CounterClockWise UX. Of all the editors I’ve seen people start off learning Clojure with, it’s the one people groked the quickest. Some of the highlights are:

Ctrl+Enter evals the s-expr around the cursor. I haven’t seen anything else do this, and in my opinion, this is still the best way. Instead of last-sexp, its sexp under point, but not top level. Also Ctrl+Enter is a great binding, it really brings repl eval front and center.

Mouse over and cursor over symbols would show the doc.

Ctrl+mouse over would show macro-expansion-1. And Ctrl+Shift+mouse over macroexpand all. Really useful feature.

Ctrl+space for autocomplete selection

F3 for goto definition

Paredit by default, Alt+D to switch between strict and non strict. Esc to escape the next keystroke if on strict mode.

Auto-indent on enter.

Shift+Alt up/down/left/right to expand sexpr selection up/down/left/right. This is amazing. You almost don’t need slurp/barf etc. with these.

Alt+R raise over parent. Probably the .most common structural edit I use.

Alt+S to split

Alt+J to join

Ctrl+; to toggle line comments.

Tab to reindent line

(,[,{," all wrap round selection. If unelected, they move cursor to nearest parens of the given type. Same for their closing equivalent.

Ctrl+Alt+S load file in repl.
Ctrl+Alt+N switch repl to file namespace.

And right clicking in any file had a menu where all commands were listed and available.

Of course, it had REPL window with history and formatting and a button to display the full error *e.

I know those aren’t the conventional Cider bindings, but in my opinion, they are 100% better for people starting out. And honestly, I’ve actually rebound some of them over to Emacs as well because of how good I like them :ok_hand:

Being in Eclipse, you also got full Java support. I wonder how well Calva works with Java LSP mode in VS Code?

4 Likes

Tried to repro without success so I’m removing the references to it. Seems to be working with java 11 now, will file a bug if I find anything.

1 Like

Thanks for that summary, @didibus! I’ll be using it as a well of inspiration. As it happens, Calva has taken much of the same path, but is yet quite bare bones compared to CounterClockwise, it seems.

How is this wiki page linked to https://github.com/BetterThanTomorrow/calva/wiki/Using-with-WSL

I was not clear on the below line

  1. The useWSL option must be set to true and you must add a valid WSL path to the jokerPath option.

set this option where? where to set jokerPath? Do I have to use joker ?

Thanks. That certainly needs to be clarified. (WSL support was initially a thing only for the Joker linter.)

To answer your questions.

  • There is a Calva setting for using WSL.
  • You do not need to use Joker unless you want Calva to help you with linting.

Also, for linting I recommend you use @marcomorain’s clojure-lint extension instead, because I will soon remove the linting support from Calva.

If you are using the remote development extension to work on wsl, you can have joker etc. installed in your wsl instance and should not need these flags.

1 Like

I am not a Windows user (and my old Mac does not really allow me to run Windows virtualized either) so these wiki pages are a bit outside the territories charted by me. Feel invited to tend them and make them make sense. :smile: