@@ -16,15 +16,12 @@ pub struct Function {
16
16
/// The line number the function starts and ends on
17
17
pub ( crate ) lines : ( usize , usize ) ,
18
18
/// The lifetime of the function
19
- // TODO: make a tpye for this
20
19
pub ( crate ) lifetime : Vec < String > ,
21
20
/// The generic types of the function
22
- /// TODO: make a type for this
23
21
pub ( crate ) generics : Vec < String > ,
24
22
/// The arguments of the function
25
23
pub ( crate ) arguments : Vec < String > ,
26
24
/// The return type of the function
27
- // TODO: make a type for this
28
25
pub ( crate ) return_type : Option < String > ,
29
26
/// The functions atrributes
30
27
pub ( crate ) attributes : Vec < String > ,
@@ -56,8 +53,7 @@ impl Function {
56
53
} ,
57
54
} ,
58
55
} ;
59
- if self . function . is_empty ( ) {
60
- } else {
56
+ if !self . function . is_empty ( ) {
61
57
for i in & self . function {
62
58
match previous {
63
59
None => write ! ( f, "{}\n ...\n " , i. top) ?,
@@ -76,8 +72,7 @@ impl Function {
76
72
}
77
73
78
74
write ! ( f, "{}" , self . contents) ?;
79
- if self . function . is_empty ( ) {
80
- } else {
75
+ if !self . function . is_empty ( ) {
81
76
for i in & self . function {
82
77
match next {
83
78
None => write ! ( f, "\n ...{}" , i. bottom) ?,
@@ -109,18 +104,25 @@ impl Function {
109
104
}
110
105
111
106
/// 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 > {
113
108
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 ( ) ) ;
117
112
if let Some ( block) = & self . block {
118
- map. insert ( "block" . to_string ( ) , format ! ( "{}" , block. block_type) ) ;
113
+ map. insert ( "block" , format ! ( "{}" , block. block_type) ) ;
119
114
}
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
+ } ;
124
126
map
125
127
}
126
128
@@ -168,10 +170,8 @@ pub struct FunctionBlock {
168
170
/// The line number the function starts and ends on
169
171
pub ( crate ) lines : ( usize , usize ) ,
170
172
/// The lifetime of the function
171
- // TODO: make a tpye for this
172
173
pub ( crate ) lifetime : Vec < String > ,
173
174
/// The generic types of the function
174
- /// TODO: make a type for this
175
175
pub ( crate ) generics : Vec < String > ,
176
176
/// The arguments of the function
177
177
pub ( crate ) arguments : Vec < String > ,
@@ -191,6 +191,17 @@ impl FunctionBlock {
191
191
map. insert ( "lines" . to_string ( ) , format ! ( "{:?}" , self . lines) ) ;
192
192
map. insert ( "signature" . to_string ( ) , self . top . clone ( ) ) ;
193
193
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
+ } ;
194
205
map
195
206
}
196
207
}
@@ -209,7 +220,6 @@ pub struct Block {
209
220
/// The line number the function starts and ends on
210
221
pub ( crate ) lines : ( usize , usize ) ,
211
222
/// The lifetime of the function
212
- // TODO: make a tpye for this
213
223
pub ( crate ) lifetime : Vec < String > ,
214
224
/// The generic types of the function
215
225
pub ( crate ) generics : Vec < String > ,
@@ -230,6 +240,10 @@ impl Block {
230
240
map. insert ( "lines" . to_string ( ) , format ! ( "{:?}" , self . lines) ) ;
231
241
map. insert ( "signature" . to_string ( ) , self . top . clone ( ) ) ;
232
242
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 ( "," ) ) ;
233
247
map
234
248
}
235
249
}
@@ -345,6 +359,16 @@ impl File {
345
359
pub fn get_functions_mut ( & mut self ) -> & mut Vec < Function > {
346
360
& mut self . functions
347
361
}
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
+ }
348
372
}
349
373
350
374
impl Iterator for File {
@@ -546,6 +570,8 @@ impl FunctionHistory {
546
570
return ;
547
571
}
548
572
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 ;
549
575
}
550
576
551
577
/// this will move to the previous commit if possible
@@ -554,6 +580,8 @@ impl FunctionHistory {
554
580
return ;
555
581
}
556
582
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 ;
557
585
}
558
586
559
587
/// this will move to the next file in the current commit if possible
0 commit comments