0.1.1 |
|
---|
#9 在 #annotate
7KB
162 行
annotate-snippets包的Builder模式抽象。
use annotate_snippets_builder::{Annotation, AnnotationType, DisplayList, Slice, Snippet};
use stringx::Join;
fn main() {
let src_1 = include_str!("./lex_invalid.rym").lines().skip(2).join("\n");
let snippet = Snippet::new()
.title(
Annotation::new(AnnotationType::Error)
.id("E4320")
.label("Unexpected character"),
)
.add_slice(
Slice {
source: &src_1,
line_start: 3,
}
.origin("./lex_invalid.rym")
.annotation((3, 4), AnnotationType::Error, "invalid")
.annotation((26, 32), AnnotationType::Error, "invalid"),
)
.add_slice(
Slice {
source: "Ident::Test",
line_start: 129,
}
.origin("src/display.rs")
.annotation((0, 11), AnnotationType::Warning, "Unused"),
);
let dl = DisplayList::from(snippet);
println!("\n{}", dl.to_string());
}
如何安装。
cargo add annotate_snippets_builder
依赖项
~375–620KB