summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Moore <wes@wezm.net>2019-07-09 08:30:20 +1000
committerWesley Moore <wes@wezm.net>2019-07-09 08:30:20 +1000
commit2630b8dde7000c4bc63312cc0de9eda599748634 (patch)
tree6cd445578406d9f4131fc025ce729cd8ecbf21a5
parent034d15a1a135bda84f45c768a1786f1548fe5156 (diff)
Add Visitor
-rw-r--r--src/annotate.rs10
-rw-r--r--src/bin/annotaterust.rs47
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");
}