The best coding experience for Racket in VS Code
This extension adds support for Racket to VS Code. With the newly added support for language server protocol, we're proud to say that Magic Racket is the best Racket extension for VS Code.
Install Magic Racket. You can do that from the VS Code extension marketplace, or from the Open VSX Registry if you're using VS Codium.
Make sure you have raco
on your path (see section Troubleshooting)
Install the racket-langserver by running the following command in the terminal:
raco pkg install racket-langserver
Or update it using
raco pkg update racket-langserver
If don't want to use the lang-server at all, you don't have to. Just set "magicRacket.languageServer.enabled": false
in your configuration file. But note that if you do so, you won't get the “smart” features like autocomplete, formatting, etc.
If you are running VSCode on WSL or a headless Linux server, please see the Troubleshooting section below.
Magic Racket does
#lang racket
...but at the same time doesn't:
Magic Racket now supports racket-langserver. The current features are:
We're working on providing more details in this section: stay tuned!
The image shows a comparison of a testing file highlighted using a popular Racket VS Code extension (on the left) and by Magic Racket (on the right).
As you can see, Magic Racket strives to be correct and consistent — and it supports most of the language features as well. In many ways, this extension was inspired by the highlighting in DrRacket, however, in some aspects it aims to be less minimalistic.
You can load and execute files in Magic Racket by using the icons in the top right corner of your editor (see the image below), or from the commands console in VS Code. You can open the list of all commands by pressing Cmd+Shift+P
(Ctrl+Shift+P
if you're on Linux or Windows) and then search through them by typing. All of Magic Racket's commands are prefixed by Racket:
to make the searching easier.
In Magic Racket, each file will have its own REPL in which it'll load every time you use the Racket: Load file in REPL
command. You can choose to mimic this behavior also for Racket: Run file in terminal
, or you can run all files in one output terminal.
The list of commands added by Magic Racket:
Racket: Execute selection in REPL
Racket: Load file in REPL
Racket: Run file in terminal
Racket: Open the REPL for the current file
Racket: Show the output terminal for the current file
You can set the names of the REPLs and output terminals in the settings.
These aren't game-changers, but they certainly help.
lmb
or the shortcut
Option+\ (Alt+\ on Windows and Linux)Magic Racket's options can be found in the Magic Racket
section in VSCode preferences.
However, if you would like to change some VSCode option only for Racket (e.g. if you don't like the predefined editor rulers), you can do so by directly adding them into a [racket]
section in settings.json
:
"[racket]": {
"editor.rulers": [],
// some further Racket-specific configuration
}
If you're trying to use Magic Racket on Windows, especially under Docker or WSL, you might be getting some errors regarding GTK or other missing dynamic libraries. This is caused by the langserver depending on GTK to function properly, please see issue https://github.com/Eugleo/magic-racket/issues/51 for a workaround.
Similar problems can be sometimes encountered on Linux, especially if your Racket installation is sandboxed via Snap or a similar style of alternative packaging. See https://github.com/Eugleo/magic-racket/issues/109 for more info. These issues likely indicate a packaging issue, so you may want to try installing Racket without any sandboxing layers like this.
content-length
headerOn both Linux and WSL, there is sometimes error about header being required to have a content-length property. For a fix, see issue https://github.com/Eugleo/magic-racket/issues/77.
raco
properlyWe need raco to install the language server package. The good news is, raco
is automatically installed during the installation of Racket. On MacOS, it can be found in the /Applications/[Racket folder]/bin
directory, on Windows (or so I am told) it's directly in the Racket install directory.
However, after the installation, your computer doesn't know where the command raco
is, so you need to do either of the following things:
(recommended) add the directory where raco
is located (instructions for Unix, and something like this for PowerShell on Windows)
first move to the directory where raco
is located (by using cd
, for example), and then run it by prefixing the raco
command with ./
(Unix) or .\
(Windows), like this:
./raco pkg update racket-langserver
or, on Windows,
.\raco pkg update racket-langserver
Please see the changelog for the information about the latest updates.