From 2630b8dde7000c4bc63312cc0de9eda599748634 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Tue, 9 Jul 2019 08:30:20 +1000 Subject: Add Visitor --- src/annotate.rs | 10 ++++++++++ src/bin/annotaterust.rs | 47 ++++++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/annotate.rs b/src/annotate.rs index a11d9b7..9e1e831 100644 --- a/src/annotate.rs +++ b/src/annotate.rs @@ -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); + } +} diff --git a/src/bin/annotaterust.rs b/src/bin/annotaterust.rs index 8a85563..3ecc023 100644 --- a/src/bin/annotaterust.rs +++ b/src/bin/annotaterust.rs @@ -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"); } -- cgit v1.2.3