@@ -16,15 +16,12 @@ pub struct Function {
1616 /// The line number the function starts and ends on
1717 pub ( crate ) lines : ( usize , usize ) ,
1818 /// The lifetime of the function
19- // TODO: make a tpye for this
2019 pub ( crate ) lifetime : Vec < String > ,
2120 /// The generic types of the function
22- /// TODO: make a type for this
2321 pub ( crate ) generics : Vec < String > ,
2422 /// The arguments of the function
2523 pub ( crate ) arguments : Vec < String > ,
2624 /// The return type of the function
27- // TODO: make a type for this
2825 pub ( crate ) return_type : Option < String > ,
2926 /// The functions atrributes
3027 pub ( crate ) attributes : Vec < String > ,
@@ -56,8 +53,7 @@ impl Function {
5653 } ,
5754 } ,
5855 } ;
59- if self . function . is_empty ( ) {
60- } else {
56+ if !self . function . is_empty ( ) {
6157 for i in & self . function {
6258 match previous {
6359 None => write ! ( f, "{}\n ...\n " , i. top) ?,
@@ -76,8 +72,7 @@ impl Function {
7672 }
7773
7874 write ! ( f, "{}" , self . contents) ?;
79- if self . function . is_empty ( ) {
80- } else {
75+ if !self . function . is_empty ( ) {
8176 for i in & self . function {
8277 match next {
8378 None => write ! ( f, "\n ...{}" , i. bottom) ?,
@@ -109,18 +104,25 @@ impl Function {
109104 }
110105
111106 /// get metadata like line number, number of parent function etc.
112- pub fn get_metadata ( & self ) -> HashMap < String , String > {
107+ pub fn get_metadata ( & self ) -> HashMap < & str , String > {
113108 let mut map = HashMap :: new ( ) ;
114- map. insert ( "name" . to_string ( ) , self . name . clone ( ) ) ;
115- map. insert ( "lines" . to_string ( ) , format ! ( "{:?}" , self . lines) ) ;
116- map. insert ( "contents" . to_string ( ) , self . contents . clone ( ) ) ;
109+ map. insert ( "name" , self . name . clone ( ) ) ;
110+ map. insert ( "lines" , format ! ( "{:?}" , self . lines) ) ;
111+ map. insert ( "contents" , self . contents . clone ( ) ) ;
117112 if let Some ( block) = & self . block {
118- map. insert ( "block" . to_string ( ) , format ! ( "{}" , block. block_type) ) ;
113+ map. insert ( "block" , format ! ( "{}" , block. block_type) ) ;
119114 }
120- map. insert (
121- "number of function" . to_string ( ) ,
122- format ! ( "{}" , self . function. len( ) ) ,
123- ) ;
115+ map. insert ( "generics" , self . generics . join ( "," ) ) ;
116+ map. insert ( "arguments" , self . arguments . join ( "," ) ) ;
117+ map. insert ( "lifetime generics" , self . lifetime . join ( "," ) ) ;
118+ map. insert ( "attributes" , self . attributes . join ( "," ) ) ;
119+ map. insert ( "doc comments" , self . doc_comments . join ( "," ) ) ;
120+ match & self . return_type {
121+ None => { }
122+ Some ( return_type) => {
123+ map. insert ( "return type" , return_type. clone ( ) ) ;
124+ }
125+ } ;
124126 map
125127 }
126128
@@ -168,10 +170,8 @@ pub struct FunctionBlock {
168170 /// The line number the function starts and ends on
169171 pub ( crate ) lines : ( usize , usize ) ,
170172 /// The lifetime of the function
171- // TODO: make a tpye for this
172173 pub ( crate ) lifetime : Vec < String > ,
173174 /// The generic types of the function
174- /// TODO: make a type for this
175175 pub ( crate ) generics : Vec < String > ,
176176 /// The arguments of the function
177177 pub ( crate ) arguments : Vec < String > ,
@@ -191,6 +191,17 @@ impl FunctionBlock {
191191 map. insert ( "lines" . to_string ( ) , format ! ( "{:?}" , self . lines) ) ;
192192 map. insert ( "signature" . to_string ( ) , self . top . clone ( ) ) ;
193193 map. insert ( "bottom" . to_string ( ) , self . bottom . clone ( ) ) ;
194+ map. insert ( "generics" . to_string ( ) , self . generics . join ( "," ) ) ;
195+ map. insert ( "arguments" . to_string ( ) , self . arguments . join ( "," ) ) ;
196+ map. insert ( "lifetime generics" . to_string ( ) , self . lifetime . join ( "," ) ) ;
197+ map. insert ( "attributes" . to_string ( ) , self . attributes . join ( "," ) ) ;
198+ map. insert ( "doc comments" . to_string ( ) , self . doc_comments . join ( "," ) ) ;
199+ match & self . return_type {
200+ None => { }
201+ Some ( return_type) => {
202+ map. insert ( "return type" . to_string ( ) , return_type. clone ( ) ) ;
203+ }
204+ } ;
194205 map
195206 }
196207}
@@ -209,7 +220,6 @@ pub struct Block {
209220 /// The line number the function starts and ends on
210221 pub ( crate ) lines : ( usize , usize ) ,
211222 /// The lifetime of the function
212- // TODO: make a tpye for this
213223 pub ( crate ) lifetime : Vec < String > ,
214224 /// The generic types of the function
215225 pub ( crate ) generics : Vec < String > ,
@@ -230,6 +240,10 @@ impl Block {
230240 map. insert ( "lines" . to_string ( ) , format ! ( "{:?}" , self . lines) ) ;
231241 map. insert ( "signature" . to_string ( ) , self . top . clone ( ) ) ;
232242 map. insert ( "bottom" . to_string ( ) , self . bottom . clone ( ) ) ;
243+ map. insert ( "generics" . to_string ( ) , self . generics . join ( "," ) ) ;
244+ map. insert ( "lifetime generics" . to_string ( ) , self . lifetime . join ( "," ) ) ;
245+ map. insert ( "attributes" . to_string ( ) , self . attributes . join ( "," ) ) ;
246+ map. insert ( "doc comments" . to_string ( ) , self . doc_comments . join ( "," ) ) ;
233247 map
234248 }
235249}
@@ -345,6 +359,16 @@ impl File {
345359 pub fn get_functions_mut ( & mut self ) -> & mut Vec < Function > {
346360 & mut self . functions
347361 }
362+
363+ /// This is will get the current function in the file
364+ pub fn get_current_function ( & self ) -> Option < & Function > {
365+ self . functions . get ( self . current_pos )
366+ }
367+
368+ /// This is will get the current function in the file (mutable)
369+ pub fn get_current_function_mut ( & mut self ) -> Option < & mut Function > {
370+ self . functions . get_mut ( self . current_pos )
371+ }
348372}
349373
350374impl Iterator for File {
@@ -546,6 +570,8 @@ impl FunctionHistory {
546570 return ;
547571 }
548572 self . current_pos += 1 ;
573+ self . commit_history [ self . current_pos ] . current_iter_pos = 0 ;
574+ self . commit_history [ self . current_pos ] . current_pos = 0 ;
549575 }
550576
551577 /// this will move to the previous commit if possible
@@ -554,6 +580,8 @@ impl FunctionHistory {
554580 return ;
555581 }
556582 self . current_pos -= 1 ;
583+ self . commit_history [ self . current_pos ] . current_iter_pos = 0 ;
584+ self . commit_history [ self . current_pos ] . current_pos = 0 ;
557585 }
558586
559587 /// this will move to the next file in the current commit if possible
0 commit comments