GithubHelp home page GithubHelp logo

rcoh / annotate-snippets-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rust-lang/annotate-snippets-rs

0.0 2.0 0.0 115 KB

Library for snippet annotations

License: Apache License 2.0

Rust 100.00%

annotate-snippets-rs's Introduction

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 procudes 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

extern crate annotate_snippets;

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

annotate-snippets-rs's People

Contributors

zbraniecki avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.