MoonBit for Zed
Official MoonBit language support for the Zed editor.
This extension provides Tree-sitter-based syntax highlighting together with the native MoonBit Language Server (moon lsp).
Features
- Tree-sitter syntax highlighting
- Partial MoonBit 0.10.4 syntax support (literal Iterators and Bytes interpolation are locked by
tree-sitter-moonbitcurrent support) - Native MoonBit LSP integration (
moon lsp) - Outline support
- Bracket matching
- Indentation support
Status
Functional and actively maintained.
The extension intentionally keeps its Rust implementation minimal and delegates language intelligence to the official MoonBit Language Server while following the upstream Tree-sitter grammar.
The extension tracks the upstream MoonBit Tree-sitter grammar and native MoonBit language server.
Syntax support is limited by the currently pinned upstream grammar revision and may not yet cover every feature introduced in the latest MoonBit release.
Requirements
- Zed Editor
- MoonBit 0.10.4 or newer
Verify your installation:
moon versionThe language server is included with the MoonBit toolchain:
moon lspNo separate npm package is required.
Installation (Development)
Clone the repository:
git clone https://github.com/quirk-lab/zed-moonbit
cd zed-moonbitThen in Zed:
- Open the Command Palette
- Run:
zed: install dev extensionOfficial releases are available from:
https://github.com/quirk-lab/zed-moonbit/releases
Optional: associate moon.pkg with MoonBit
Since moon.pkg is a MoonBit package manifest rather than a source file, you may want to associate it manually:
{
"file_types": {
"MoonBit": ["moon.pkg"]
}
}Zed currently cannot associate languages with exact filenames automatically.
Development
Using Just:
just dev
just validate-queries
just test-syntax
just zed-logUsing Make:
make dev
make validate-queries
make test-syntax
make zed-logWindows:
pwsh -File scripts/dev.ps1Tree-sitter Development
Tree-sitter queries live in:
languages/moonbit/Always validate queries after making changes:
just validate-queriesor
make validate-queriesNever guess node names.
Debugging
Print the Zed log path:
just zed-log-pathTail logs:
just zed-logIf you encounter errors such as:
Invalid node type "..."verify the syntax tree using:
tree-sitter parse example.mbtand compare it with:
src/node-types.jsonProject Structure
src/lib.rs Rust extension entry point
extension.toml Extension manifest
languages/moonbit/ Tree-sitter configuration and queries
scripts/ Development utilitiesDesign Principles
- Thin extension
- Native MoonBit tooling
- Upstream-first grammar
- Minimal, maintainable queries
- Validate before testing
Roadmap
- Improve query coverage
- Refine outline support
- Improve indentation rules
- Track new MoonBit language releases
Contributing
Small, focused pull requests are preferred.
Before opening a PR, always run:
just validate-queriesTroubleshooting
Error: failed to compile grammar 'moonbit'
This is usually caused by a corrupted local Tree-sitter grammar cache.
To fix:
- Close Zed.
- Delete the local
grammars/moonbitdirectory (or the entiregrammarsdirectory). - Restart Zed.
- Reinstall the extension.
This is a local cache issue rather than an extension bug.
License
MIT