Editor Setup
Polar ships a VS Code extension for syntax highlighting, and a formatter you can run from any editor.
VS Code
The extension lives in the repository at editor/vscode.
It highlights zone names, keywords, comments, strings with
#{…} interpolation, numbers, operators, and type and
constructor names in .px files.
The quickest way to install it is to link the folder into your extensions directory. Run this from the repository root, then reload the VS Code window:
$ ln -s "$PWD/editor/vscode" ~/.vscode/extensions/polar-lang
Or package it and install the result:
$ cd editor/vscode
$ npx @vscode/vsce package
$ code --install-extension polar-lang-0.0.1.vsix
Formatting
Polar has one standard layout, and polar fmt applies
it. You don't have to argue about style or configure anything.
$ polar fmt src # rewrite files in place
$ polar fmt --check src # only report files that would change
--check exits with an error when a file isn't
formatted, which makes it handy in CI.
Tip: The formatter keeps short
expressions on one line and splits long ones. If you're unsure how
to lay something out, write it any way that parses and let
polar fmt decide.
Errors on save
Keep a terminal open next to your editor with:
$ polar check --watch
Every time you save, Polar re-checks the project and prints any errors. Each error points at the exact code, says what's wrong, and often suggests a fix:
error[POLAR0501]: mismatched types
--> mismatch.px:9:20
|
4 | greet(name: String) -> String {
| ------------ expected because of this
...
9 | Log.info(greet(42))
| ^^ expected `String`, found `Int`
That's the setup done. Now let's write some Polar, starting with Hello World.