zed-extensions/zed-grainpublic Fork
⑂ main
Commits
⬇ Clone ▾
git clone https://git.rickub.com/zed-extensions/zed-grain.git
git clone ssh://git@rickub.com/zed-extensions/zed-grain.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
🛟 Updated. 0ca90cf · on main · k33g · 3h ago
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).

  1. In Zed: zed: install dev extension (command palette) and pick this zed-grain folder.
  2. Open a .gr file.

Grain binary used by the LSP

The extension looks for grain, in this order:

  1. lsp.grain-lsp.binary.path in the Zed settings,
  2. grain on the PATH,
  3. 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 the file:// URIs Zed sends are valid inside it.
  • sbx exec starts the sandbox if it's stopped.
  • Limitation: "go to definition" on the stdlib points to /snapshot/grain/stdlib/...,
    a path that only exists inside the grain binary.

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.