~wezm/annotate-rust

2630b8dde7000c4bc63312cc0de9eda599748634 — Wesley Moore 10 months ago 034d15a
Add Visitor
2 files changed, 40 insertions(+), 17 deletions(-)

M src/annotate.rs
M src/bin/annotaterust.rs
M src/annotate.rs => src/annotate.rs +10 -0
@@ 1,4 1,6 @@
use serde::Serialize;
use syn::visit::Visit;
use syn::FnDecl;

#[derive(Serialize)]
#[serde(tag = "type")]


@@ 21,3 23,11 @@ pub enum Annotation {
        content: String,
    },
}

pub struct FnVisitor;

impl<'ast> Visit<'ast> for FnVisitor {
    fn visit_fn_decl(&mut self, i: &'ast FnDecl) {
        dbg!(i);
    }
}

M src/bin/annotaterust.rs => src/bin/annotaterust.rs +30 -17
@@ 1,10 1,13 @@
use std::{env, io};
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use std::process;
use std::collections::HashMap;
use std::{env, io};

use syn::visit::Visit;

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

fn main() {
    let mut args = env::args();


@@ 26,24 29,34 @@ fn main() {
    let syntax = syn::parse_file(&src).expect("Unable to parse file");
    println!("{:#?}", syntax);

    // Visit function invocations
    let mut visitor = FnVisitor;
    visitor.visit_file(&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
    });
    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");
    serde_json::to_writer(stdout, &annotations).expect("json");
}