Install

Harsh needs a Rust toolchain -- rustup -- and one cargo install. The package is harsh-lang; it installs hrs, hrs-from, hrs-remap and hrs-lsp.

cargo install harsh-lang
hrs --version

A first project

hrs new writes a project whose Cargo.toml is Cargo's, unchanged. Your sources are src/**.hrs; hrs build writes the Rust project to export/, where you can read it.

hrs new hello
cd hello
hrs run
fn main$:
    println! "Hello, world!"

The commands

hrs build      write the Rust project to export/, then cargo build there
hrs run        build and run, diagnostics on the .hrs lines
hrs test       cargo test, remapped
hrs check      cargo check, remapped
hrs lint       clippy, remapped
hrs fmt        the formatter
hrs watch      rebuild on every save
hrs -c <cmd>   cargo <cmd> in export/: hrs -c publish sends it to crates.io
hrs-from       convert a Rust file or project to Harsh

The toolset

Everything Harsh offers beside the compiler's commands, and where it stands.

VS Code

The extension harsh-lang, on the Marketplace: highlighting, indentation on Enter and Tab, formatting, and types on hover, go-to-definition and completion through rust-analyzer -- all through hrs-lsp, installed with harsh-lang above. Search Harsh in the Extensions view, or:

code --install-extension harsh-lang.harsh-lang

For VSCodium, Cursor and the other editors built on VS Code, the same extension on Open VSX is coming.

Jupyter

A Harsh kernel for notebooks: each cell is transpiled by hrs and run by evcxr, Rust's own Jupyter kernel, which it needs; an error points at the cell's own line. Then pick Harsh in Jupyter.

cargo install evcxr_jupyter
evcxr_jupyter --install
python -m pip install harsh-kernel
python -m harsh_kernel.install

Use python -m for each Python command, so pip, the kernel and Jupyter are one Python. Matrices work in notebooks too: the first cell that uses them takes a minute or two while nalgebra compiles.

Zed -- coming

A Zed extension and a tree-sitter grammar for Harsh are written and in the repository, editors/; they go to the Zed extension registry once two indentation issues in Zed are settled. Until then, Zed can open .hrs files as plain text.

Other editors

hrs-lsp is a language server: any editor that speaks LSP -- Neovim, Helix, Emacs -- can run it for formatting, indentation, and hover and go-to-definition through rust-analyzer. The tree-sitter grammar, in the repository, gives them highlighting.

Harshlings

Small exercises, broken on purpose, to learn Harsh by fixing them -- as Rustlings does for Rust. 65 of them, with hints and solutions.

git clone https://gitlab.com/bahiminin.benoit.dah.opensource/harshlings
cd harshlings
hrs run

Bringing existing Rust in

hrs-from converts a Rust file, or a whole project, to Harsh -- including a Leptos or Dioxus site, whose view! and rsx! bodies stay as written with the Rust in them turned into Harsh holes. The round trip is byte-exact: it is how the transpiler's own source is tested.