Skip to content

A VS Code Extension providing commands for extra powerful things in the Clojure ecosystem

License

Notifications You must be signed in to change notification settings

BetterThanTomorrow/calva-power-tools

Repository files navigation

Calva Power Tools

A VSCode extension, and Calva companion, for Clojure and ClojureScript development that adds commands for popular Clojure libraries and tools. Including commands for dynamically loading the tool dependencies.

Usage

  1. Install the extension from the VSCode Marketplace.
  2. The commands are available from the command palette. There is a default keybinding for filtering the palette on the Calva Power Tools commands: ctrl+shift+space ctrl+shift+space.

There is a quick demo/howto here: https://youtu.be/GiWKX-0NqkM

Default keybindings included

The Calva Power Tools extension generally contributes default keybindings for the commands. They are all chained on a first chord of ctrl+shift+space, a.k.a. the Power Key. Then, generally, each tool has its key, e.g. Snitch uses the Tool Key s. You can thus execute Snitch commands with ctrl+shift+space s something.

There are also default bindings for filtering the command palette on a specific tool. Generally the ctrl+shift+space ctrl+shift+tool-key. E.g. to list the Snitch commands:

  • ctrl+shift+space ctrl+shift+s

The Tools

A hopefully growing list of power tools.

Tools-deps, add-libs

A set of commands leveraging Clojure 1.12 add-libs:

  • tools-deps: Load Dependencies...: Will prompt for and load dependencies. alt text
  • tools-deps: Load Selected Dependencies): Add one or more deps.edn dependencies coordinate that you have selected in the editor. E.g. if you have added it to your deps.edn file and want to load the dependency without restarting your REPL (or you may have some comment in the code with the dependency coordinates): Select the key-value pair(s) for the dependencies and then run this command.
  • tools-deps: Sync deps.edn Dependencies...: Sync (load any missing) dependencies in deps.edn. Prompts for aliases. alt text

Tool Key: d

Clay

Tool Key: a

Explore the Clay commands from the VS Code command palette by fuzzy searching “Clay”. Also check this intoduction out: https://www.youtube.com/watch?v=B1yPkpyiEEs

Snitch

Snitch is inline-defs on steroids. See https://github.com/AbhinavOmprakash/snitch. Search the command palette for “Snitch”.

Tool Key: s

Snitch Power Tool Commands

This menu screenshot is showing the default key bindings. I (PEZ) am on a Mac and can recommend binding the Snitch: Instrument defn command to cmd+enter.

Performance

There are commands for four important tools when chasing performance gains in Clojure. For loading dependencies as well as basic usage:

Tool Key: s. Further each “sub-tool” has a key, c/d/p/t for Criterium/clojure-java-decompiler/clj-async-profiler/time, respectively. Example: Loading the dependency for Criteriums is ctrl+shift+space p c l, to be read as Power Tools, Performance, Criterium, Load.

Command Palette search: Criterium Commands

Command Palette search: Decompiler Commands

Command Palette search: Profiler Commands

Command Palette search: time Commands

Dataspex

Dataspex is an easy to use data inspection tool/browser.

Command Palette search: Dataspex Commands

Tool Key: x

Contributing

Issues and pull requests are welcome. Please see CONTRIBUTING

Adding a new command

  1. Add the command name and title in package.json.
    • The command name should be unique and follow the format <library>.<command>.
    • The title should be a human-readable name for the command.
    • The command should be added to the contributes.commands array.
  2. Add keybindings for the command in package.json (optional).
    • The keybinding should be added to the contributes.keybindings array.
  3. Add clojure snippets they should invoke in src/calva_power_tools/tool (see src/calva_power_tools/tool/clay.cljs for an example).
    • Fully qualify symbols in snippets to avoid uninitialized namespace issues
  4. Register them in src/extension.cljs in the activate function.

Development

The paved path is:

  1. npm run watch. This starts Clojure with an nREPL server. (You can run the build task command inside VSCode).
    • Wait for it to report something like:
      nREPL server started on port 56749 on host localhost - nrepl://localhost:56749
      
  2. ctrl+alt+c ctrl+alt+c. This runs the command: Calva: Connect to a Running REPL Server in the Project
    • It will connect the Clojure REPL, start a ClojureScript (shadow-cljs) REPL, and build the extension.
    • This will compile the extension and run the tests. Wait for the Build+watch extension to show that the tests have ran, and for Calva to pop up a progress dialog about starting your ClojureScript app (which is your extension in this case).
  3. F5. This starts the VS Code Development Extension Host (because configured to do so in .vscode/launch.json)
    • The development extension host is a VS Code window where your extension under development is installed. You now need to activate it to actually start the ClojureScript app.
    • The extension auto-activates, now your ClojureScript app and its REPL is started 🎉
  4. Back in the development project you will see the progress dialog go away. Because now the development project window is connected to the Development Extension Host window's REPL.
    • Now you can hack on the extension code, which will update the app in the extension host window while it is running (a.k.a. interactive programming).

An important thing to note here is the steps where you activate your extension in the development host, starting the ClojureScript repl which Calva can connect to.

License

MIT

Free to use, modify and redistribute as you wish. 🍻🗽

Built VSC-ET, the VS Code Extension Template

About

A VS Code Extension providing commands for extra powerful things in the Clojure ecosystem

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •