README.md
Grain for Zed
Zed extension for the Grain language (.gr files).
- Syntax highlighting, outline, bracket matching, indentation and text objects, using the
Kara-Zor-El/tree-sitter-grain grammar
(the highlight queries are adapted to Zed's capture names). - Markdown injection in doc comments (
/** ... */), with Grain for@example. - Language server:
grain lsp(diagnostics, hover, go to definition, formatting,
document symbols, inlay type hints, code lenses). - Tasks:
grain run,grain compile --release,grain format.
Install (dev extension)
Prerequisite: Rust installed with rustup (Zed compiles the extension itself).
- In Zed:
zed: install dev extension(command palette) and pick thiszed-grainfolder. - Open a
.grfile.
Grain binary used by the LSP
The extension looks for grain, in this order:
lsp.grain-lsp.binary.pathin the Zed settings,grainon thePATH,- otherwise it downloads the latest release from GitHub
(grain-{linux,mac,win}-{x64,arm64}.tar.gz).
// settings.json
{
"lsp": {
"grain-lsp": {
"binary": {
"path": "grain",
"arguments": [
"lsp"
]
}
}
}
}
Grain inside a Docker sandbox (sbx)
If grain only exists in an sbx sandbox (grain-toolchain kit), Zed on the host
starts the LSP through sbx exec. Put this in the project's .zed/settings.json:
{
"lsp": {
"grain-lsp": {
"binary": {
"path": "sbx", // or the absolute path from `which sbx`
"arguments": [
"exec", "-i", // -i = stdin open; NO -t (a TTY corrupts JSON-RPC)
"-w", "/path/to/the/project",
"<sandbox-name>", // sbx ls
"grain", "lsp"
]
}
}
}
}
- This works because in direct mode the workspace is mounted at the same path in the
sandbox, so thefile://URIs Zed sends are valid inside it. sbx execstarts the sandbox if it's stopped.- Limitation: "go to definition" on the stdlib points to
/snapshot/grain/stdlib/...,
a path that only exists inside thegrainbinary.
Development
cargo build --release --target wasm32-wasip2 # check that the extension compiles
To update the grammar, change rev in extension.toml and compare
languages/grain/highlights.scm with the grammar's queries/highlights.scm.