Snap for 11142129 from 157ad63d05ba9a5ac1ec749688d92550cf6b5c46 to 24Q1-release

Change-Id: I91382c026b7bc4902766f7ecb73c0ef532a2883d
tree: aab9afc7cdb1b88ac756d68386384cbc46be6210
  1. .github/
  2. benches/
  3. examples/
  4. src/
  5. tests/
  6. .cargo_vcs_info.json
  7. .gitignore
  8. .travis.yml
  9. Android.bp
  10. Cargo.toml
  11. Cargo.toml.orig
  12. cargo_embargo.json
  13. CHANGELOG.md
  14. LICENSE-APACHE
  15. LICENSE-MIT
  16. METADATA
  17. MODULE_LICENSE_APACHE2
  18. OWNERS
  19. README.md
README.md

annotate-snippets

annotate-snippets is a Rust library for annotation of programming code slices.

crates.io build status Coverage Status

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 ()

Documentation

Usage

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);
}

Local Development

cargo build
cargo test

When submitting a PR please use cargo fmt (nightly).