summaryrefslogtreecommitdiffstats
path: root/src/bin/annotaterust.rs
blob: 8a85563c450c9389676dab1bf17db5542a313f5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::{env, io};
use std::fs::File;
use std::io::Read;
use std::process;
use std::collections::HashMap;

use annotate_rust::{git, annotate::Annotation};

fn main() {
    let mut args = env::args();
    let _ = args.next(); // executable name

    let filename = match (args.next(), args.next()) {
        (Some(filename), None) => filename,
        _ => {
            eprintln!("Usage: dump-syntax path/to/filename.rs");
            process::exit(1);
        }
    };

    let mut file = File::open(&filename).expect("Unable to open file");

    let mut src = String::new();
    file.read_to_string(&mut src).expect("Unable to read file");

    let syntax = syn::parse_file(&src).expect("Unable to parse file");
    println!("{:#?}", syntax);

    let output = git::crawl_git_tree(".").expect("git");
    let blobs = git::parse_ls_tree_output(&output).expect("parse");

    let mut annotations = HashMap::new();
    annotations.entry(blobs[0].object).or_insert(Vec::new()).push(Annotation::Markdown {
        lineno: 1,
        title: "Title".to_string(),
        content: "content".to_string()
    });
    annotations.entry(blobs[0].object).or_insert(Vec::new()).push(Annotation::Link {
        lineno: 1,
        colno: 0,
        len: 5,
        to: "asdf".to_string(),
        title: None,
        color: None
    });

    let stdout = io::stdout();
    serde_json::to_writer_pretty(stdout, &annotations).expect("json");
}