@codemirror/lang-rust
Rust language support for the CodeMirror 6 code editor, powered by a Lezer grammar.
Repository Health
Technical Analysis
@codemirror/lang-rust adds Rust language support to CodeMirror 6, the extensible code-editor component for the web. It plugs a Lezer-based Rust grammar into CodeMirror’s language system, giving editors accurate syntax highlighting, code folding, and indentation for Rust source files through a single rust() extension.
The package is deliberately minimal: it wraps the @lezer/rust parser in an LRLanguage definition, configures indent rules for if-expressions, statements, match arms, and attributes, and sets up code folding for blocks, lists, and block comments. Language data covers Rust’s comment syntax and bracket-closing rules for its b, r, and br string prefixes, so editors get correct behavior for byte strings and raw strings out of the box.
What You Get
- A ready-to-use
rust()extension that adds full Rust language support to any CodeMirror 6 editor instance. - Indentation rules tuned for Rust syntax, including if-expressions, match arms, statements, and attribute items.
- Code folding support for blocks, lists, and block comments via
foldNodeProp. - Correct handling of Rust’s
b,r, andbrstring prefixes for bracket-closing behavior.
Common Use Cases
- In-browser Rust playgrounds - online Rust sandboxes or WASM demo pages use it to give visitors syntax-aware editing without shipping a full IDE.
- Documentation sites with embedded editors - technical docs that let readers edit Rust code snippets inline rely on it for highlighting and indentation.
- Code review and diff tools built on CodeMirror - tools that render or edit Rust source alongside review comments use it to keep the code readable.
- Custom developer tools targeting Rust - any CodeMirror-based editor aimed at Rust developers pulls this in as the language layer instead of hand-writing a grammar.
Under The Hood
Architecture
The entire package is a single 35-line file, src/rust.ts, that defines rustLanguage via LRLanguage.define, wrapping the @lezer/rust parser and configuring it with indentNodeProp (for IfExpression, Statement/MatchArm, AttributeItem, and suppressing indent inside strings/block comments) and foldNodeProp (folding Block/List-suffixed nodes and BlockComment regions), plus a languageData object covering comment tokens, indent-on-input, and string-prefix-aware bracket closing. A single exported rust() factory wraps this into a LanguageSupport instance consumed directly by a CodeMirror extensions array. This is the standard shape shared across every @codemirror/lang-* package: no internal layering or dependency injection, just a declarative configuration object keyed directly to @lezer/rust’s grammar node names, so the only thing that would break on a core change is a rename of those node types.
Tech Stack
Written in TypeScript, published as a dual ESM/CJS package (dist/index.js and dist/index.cjs with matching .d.ts/.d.cts) via the shared @codemirror/buildhelper dev tool. Its only runtime dependencies are @codemirror/language (for LRLanguage, LanguageSupport, and the indent/fold prop helpers) and @lezer/rust (the actual grammar), both pinned to ^6.0.0/^1.0.0. There is no bundler config in this repository; building and testing are delegated entirely to cm-buildhelper and cm-runtests, scripts supplied by the shared CodeMirror tooling package rather than defined locally.
Code Quality
The TypeScript is clean and fully typed, with two /// doc comments documenting the two public exports (rust and rustLanguage) in a format the CodeMirror docs generator consumes. No test files exist in this repository — testing is delegated to a shared cm-runtests harness that lives outside this shallow package mirror, so there is no independent evidence of test coverage from this repo alone. No linter or CI config is present in the repo either; those live in the parent CodeMirror monorepo this package was extracted from.
API Design
The public surface is exactly two exports: rust() for the common case of dropping Rust support into an editor, and rustLanguage for consumers who want to extend or compose the language definition themselves (e.g. adding custom autocomplete). This mirrors the API shape of every sibling @codemirror/lang-* package, so a developer who has used any other CodeMirror language package already knows this one’s API with zero additional documentation.
Used by 8 apps in this directory
GitButler
Developer Tools · Devops · AI Development
Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.
Hook0
Devops
Open-source Webhooks-as-a-Service: deliver events to your users with auto-retry, signed payloads, and a real-time subscriber dashboard — all without building the infrastructure yourself.
LearnHouse
Learning Management · CMS
Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.
Obot
AI Agents
An open-source MCP platform for organizations — host MCP servers, run MCP registries, monitor usage, and build agents and chatbots on top of the Model Context Protocol from one self-hosted deployment.
OpenViking
Databases · AI Development
An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.
PostgresML
Databases · AI Development
Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.
Sourcebot
Search · Developer Tools · AI Code Assistants
A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.
superset
AI Code Assistants · AI Development
Orchestrate an army of AI coding agents—Claude Code, Codex, Gemini CLI, and more—running simultaneously in isolated git worktrees from a single Electron desktop app.