commit | 84523f86372aec17a750af2e2f0181fc4fcfeb25 | [log] [tgz] |
---|---|---|
author | Matthew Maurer <mmaurer@google.com> | Tue Jun 27 01:09:17 2023 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Tue Jun 27 01:09:17 2023 +0000 |
tree | 50d4d0aef8b14c307e51c929625ebd2aee69adf1 | |
parent | 4c49440bff652a0db5a86752e0fc5e9d94d43f89 [diff] | |
parent | 2fbb93cba1eef92d537356feeb2a40404d6ea5b2 [diff] |
Add initial c2a configuration. am: f2a65af3c6 am: 14d5ed960a am: e13d4da608 am: eca4baf37e am: 1699a54055 am: 2fbb93cba1 Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/annotate-snippets/+/2638615 Change-Id: Ie625dac2b2dcea65412c77cf9ff9010bc94b7f20 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
annotate-snippets
is a Rust library for annotation of programming code slices.
The library helps visualize meta information annotating source code slices. It takes a data structure called Snippet
on the input and produces a String
which may look like this:
error[E0308]: mismatched types --> src/format.rs:52:1 | 51 | ) -> Option<String> { | -------------- expected `Option<String>` because of return type 52 | / for ann in annotations { 53 | | match (ann.range.0, ann.range.1) { 54 | | (None, None) => continue, 55 | | (Some(start), Some(end)) if start > end_index => continue, ... | 71 | | } 72 | | } | |_____^ expected enum `std::option::Option`, found ()
use annotate_snippets::{ display_list::{DisplayList, FormatOptions}, snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}, }; fn main() { let snippet = Snippet { title: Some(Annotation { label: Some("expected type, found `22`"), id: None, annotation_type: AnnotationType::Error, }), footer: vec![], slices: vec![Slice { source: r#" annotations: vec![SourceAnnotation { label: "expected struct `annotate_snippets::snippet::Slice`, found reference" , range: <22, 25>,"#, line_start: 26, origin: Some("examples/footer.rs"), fold: true, annotations: vec![ SourceAnnotation { label: "", annotation_type: AnnotationType::Error, range: (187, 189), }, SourceAnnotation { label: "while parsing this struct", annotation_type: AnnotationType::Info, range: (34, 50), }, ], }], opt: FormatOptions { color: true, ..Default::default() }, }; let dl = DisplayList::from(snippet); println!("{}", dl); }
cargo build cargo test
When submitting a PR please use cargo fmt
(nightly).