Making VS Code Hackable
Modify your editor while it is running by executing ClojureScript code via the Joyride REPL and/or run scripts via keyboard shortcuts you choose. The Visual Studio Code API, as well as the APIs of its extensions, are at your command!
The video in much better quality on Youtube (CalvaTV)
Joyride is Powered by SCI (Small Clojure Interpreter).
See doc/api.md for documentation about the Joyride API.
Your feedback is highly welcome!
User and Workspace scripts
Joyride supports User and Workspace scripts:
- User scripts:
- Workspace scripts:
You can run or open the scripts using commands provided (search the command palette for Joyride):
- Joyride Run User Script..., default keybinding
- Joyride Open User Script...
- Joyride Run Workspace Script..., default keybinding
- Joyride Open Workspace Script...
Note, about namespaces: Joyride effectively has a classpath that is
user:workspace. A file
<User scripts dir>/foo_bar.cljs, will establish/use a namespace
foo-bar. As will a file
<Workspace scripts dir>/foo_bar.cljs. Any symbols in these files will be shared/overwritten, as the files are loaded and reloaded. There are probably ways to use this as a power. Please treat it as a super power, because you might also hurt yourself with it.
Quickest Start 1 - Install Joyride
Installing Joyride will also install, and run, a sample
user_activate.cljs User script. You can use this script as a base for init/activation stuff of your VS Code environment.
Joyride installs a "regular” User script as well. You can run either of these with the commands mentioned above.
Quickest Start 2 - Run some Code
- Bring up the VS Code Command Palette (
- Execute Joyride: Run Clojure Code...
- Type in some code into the prompt, e.g.
(require '["vscode" :as vscode]) (vscode/window.showInformationMessage "Hello World!")
Quickest Start 3 - Evaluate the selection
- Select some code (e.g. the code some lines above in this markdown file, even if in Preview.)
- Execute Joyride: Evaluate Selection, (ctrl+alt+j, enter)
Quick Start - Start the REPL
While developing Joyride scripts you should of course do it leveraging Interactive Programming (see this video demonstrating it).
Joyride has an nREPL server and commands for starting and stopping it. By default, the server will be bound to
127.0.0.1 on an available port. The host address can be configured via the setting
joyride.nreplHostAddress. Then connect your nREPl client (Calva, Clojure CLI, or whatever.)
Speaking of Calva. It has a command for starting the Joyride nREPL server and connect to it in one go. This video demonstrates starting from scratch, including installing Joyride.
The demo ”project” used here is only a directory with this file
hello_joyride.cljs. Here's the code, if you want to try it out yourself:
(:require ["vscode" :as vscode]
[promesa.core :as p]))
(+ 1 2 3 4 5 6 7 8 6)
"Come on, Join the Joyride!"
"Be a Joyrider")
(println "You choose to:" choice)))))
Quick Start - Start your Scripts Library
Joyride lets you bind keyboard shortcuts to its User and Workspace scripts.
- User Scripts:
- Workspace scripts:
Let's go with a Workspace script:
Create a script in your workspace, e.g
(:require ["fs" :as fs]
["path" :as path]
["vscode" :as vscode]
[clojure.string :as str]))
(defn info [& xs]
(vscode/window.showInformationMessage (str/join " " xs)))
(info "The root path of this workspace:" vscode/workspace.rootPath)
(fs/writeFileSync (path/resolve vscode/workspace.rootPath "test.txt") "written!")
This script gives one information message and writes to a file
Then in your keyboard shortcuts, add:
Now you can run the
example.cljs script by just hitting Cmd+1!
See doc/configuration.md for full configuration options.
See the examples for examples including:
- Creating an interactive Webview
- Terminal creation and control
- Fontsize manipulation
- Calva Structural Editing enhancements
- Opening and showing project files
- Workspace activation script
- The Joyride Extension API
npm dependencies (The wonderful posthtml-parser in this case)
- Using clojure.zip
- Using Hickory (well,
hickory.select, at least)
Support and feedback
You'll find us in the
#joyride channel on the Clojurians Slack
Follow the #vsjoyride hashtag on Twitter!