Expand description
Arborium-powered syntax highlighter for miette diagnostics.
This crate provides a MietteHighlighter that integrates arborium’s tree-sitter
based syntax highlighting into miette’s error reporting output.
§Quick Start
Install the highlighter globally and miette will automatically use it:
ⓘ
fn main() {
// Install the highlighter (call once at startup)
miette_arborium::install_global().ok();
// Now all miette errors will have syntax highlighting
// ... your code ...
}§Features
- Language detection: Automatically detects language from file extension or accepts an explicit language name
- Full arborium language support: Supports all languages enabled via Cargo features (passthrough to arborium)
- Minimal dependencies: Uses arborium’s tree-sitter-based highlighter
- ANSI terminal output: Renders highlighted code with terminal colors
§Example
ⓘ
use miette::{Diagnostic, NamedSource, SourceSpan};
use thiserror::Error;
#[derive(Error, Debug, Diagnostic)]
#[error("syntax error")]
struct SyntaxError {
#[source_code]
src: NamedSource<String>,
#[label("unexpected token here")]
span: SourceSpan,
}
fn main() -> miette::Result<()> {
miette_arborium::install_global().ok();
let source = r#"fn main() {
let x = 42
println!("{}", x);
}"#;
Err(SyntaxError {
src: NamedSource::new("example.rs", source.to_string()),
span: (32..33).into(),
})?
}Structs§
- Miette
Highlighter - A syntax highlighter for miette that uses arborium for tree-sitter based highlighting.
Functions§
- install_
global - Install the arborium highlighter as miette’s global highlighter.
- install_
global_ with_ theme - Install a custom themed highlighter as miette’s global highlighter.