Expand description
Minimal tree-sitter language registry + highlight query runner.
Deliberately does NOT port Zed’s language crate (22.9kLOC) — ~70% of it
is LanguageServer/Capability/diagnostics glue for LSP, which is out of
scope for every phase of this plan (see
plans/20260705-1722-zed-ui-component-enrichment/plan.md). Only the
rope+tree-sitter binding — the ~30% actually needed for syntax
highlighting — is reproduced here, written fresh rather than extracted
from Zed’s source (that source is entangled with the LSP types being cut).
Structs§
- Default
Language Registry - The default registry: exactly the grammars compiled in via Cargo
features (see this crate’s
Cargo.toml—lang-rustis on by default as the minimal working example; every other grammar is opt-in so consumers only pay its ~200-300KB binary-size cost if they enable it). - Language
- A single language: its tree-sitter grammar plus a compiled highlight
query. Construction fails only if
highlight_query_sourcedoesn’t parse againstgrammar— a bug in the bundled query, not user input, so a caller-facingResultwould just be unwrapped everywhere; panicking here surfaces the bug immediately in development instead.
Traits§
- Language
Registry - Resolves a
Languageby file extension (no leading dot, e.g."rs"). Intentionally minimal: no shebang detection, no content sniffing — see Zed’sLanguageRegistryfor that scope, out of bounds here.
Functions§
- highlighted_
spans - Returns a flat, non-overlapping list of (byte range, tree-sitter capture
name) spans covering every highlighted region of
source. Gaps between spans are the caller’s responsibility to render in the buffer’s default text color — this never claims to cover the whole string.