Fork of daniellemaywood.uk/gleam — Wasm codegen work
Wasm Zed extensions#
Gleam can build Zed extensions as WebAssembly components
that implement the full zed:extension world (API 0.7.0).
This repository is the compiler. Real extension packages (e.g. Glint) live with the language project, not here.
Installable Glint extension: /home/nandi/code/glint/editors/zed
Author experience#
my_ext/
gleam.toml # target = "wasm"
extension.toml # languages, grammars, language_servers
languages/…
src/extension.gleam
pub type Worktree
pub type Command {
Command(command: String, args: List(String), env: List(#(String, String)))
}
pub fn language_server_command(
_id: String,
worktree: Worktree,
) -> Result(Command, String) {
// …
}
gleam export zed-extension
# → extension.wasm (component + zed:api-version)
What the compiler emits#
- Gleam → MIR → core Wasm for user modules (heap strings, structs,
lists,
@external(wasm, …)imports). - Guest shell for every
zed:extensionworld export:- Real
language-server-command(PATHwhich+ documented fallback) - Defaults for other callbacks (
Err("not implemented")/ empty results) cabi_reallocbump allocator and post-return no-ops
- Real
- Component packaging via
wit-componentwith vendored WIT (compiler-core/wit/zed_extension/0.7.0/). - Custom section
zed:api-version: six bytes, big-endianu16major / minor / patch for0.7.0.
Zed Install Dev Extension (today)#
Zed always runs cargo build --target wasm32-wasip2 when
[lib] kind = "Rust". It does not install a prebuilt Gleam
extension.wasm alone. Until that changes, installable extensions still
need a thin Rust guest (as in glint/editors/zed).
Grammar keys must match the tree-sitter C symbol (e.g. grammars.gleam →
tree_sitter_gleam).
Example package (out of tree)#
| Location | Role |
|---|---|
~/code/glint/editors/zed |
Installable Glint extension (Rust guest + Gleam sketch) |
~/code/gleam (this repo) |
Compiler: MIR, CABI, gleam export zed-extension |
examples/hello_wasm |
Core Wasm smoke test (not a Zed extension) |
Status / roadmap#
| Piece | Status |
|---|---|
| Full world exports + component | Done |
language-server-command CABI |
Done (guest shell) |
@external(wasm) + structs/lists |
Partial |
| Wire Gleam body into CABI exports | In progress |
| Zed prebuilt install (no cargo) | Needs Zed change or alternate install path |