11 unstable releases (3 breaking)

✓ Uses Rust 2018 edition

0.6.1 Jul 23, 2019
0.6.0 Jun 26, 2019
0.5.0 Jan 5, 2019
0.1.0 May 22, 2018
0.0.1 Apr 25, 2018

#1 in #debug

Download history 4013/week @ 2019-07-18 4222/week @ 2019-08-01 6204/week @ 2019-08-08 5971/week @ 2019-08-15 5248/week @ 2019-08-22 6248/week @ 2019-08-29 6665/week @ 2019-09-05 5598/week @ 2019-09-12 5693/week @ 2019-09-19 6342/week @ 2019-09-26 6740/week @ 2019-10-03 7009/week @ 2019-10-10 6102/week @ 2019-10-17 6969/week @ 2019-10-24

33,207 downloads per month
Used in 25 crates (5 directly)

Apache-2.0/MIT

56KB
886 lines

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::snippet;

fn main() {
    let snippet = Snippet {
        title: Some(Annotation {
            label: Some("expected type, found `22`".to_string()),
            id: None,
            annotation_type: AnnotationType::Error,
        }),
        footer: vec![],
        slices: vec![
            Slice {
                source: r#"
This is an example
content of the slice
which will be annotated
with the list of annotations below.
                "#.to_string(),
                line_start: 26,
                origin: Some("examples/example.txt".to_string()),
                fold: false,
                annotations: vec![
                    SourceAnnotation {
                        label: "Example error annotation".to_string(),
                        annotation_type: AnnotationType::Error,
                        range: (13, 18),
                    },
                    SourceAnnotation {
                        label: "and here's a warning".to_string(),
                        annotation_type: AnnotationType::Warning,
                        range: (34, 50),
                    },
                ],
            },
        ],
    };

    let dl = DisplayList::from(snippet);
    let dlf = DisplayListFormatter::new(true);
    dlf.format(&dl);
}

Local Development

cargo build
cargo test

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

Dependencies

~37KB