@@ -22,28 +22,41 @@ impl std::fmt::Display for MetaType {
2222 }
2323}
2424
25- #[ derive( Debug ) ]
2625pub struct Reader {
2726 pub meta : Vec < Meta > ,
2827}
2928
30- #[ derive( Debug ) ]
29+ #[ derive( Clone ) ]
30+ pub struct ParsableDefinition {
31+ pub path : Option < String > ,
32+ pub starting_line : i32 ,
33+ pub definition_string : String ,
34+ }
35+
3136pub struct Meta {
3237 pub name : String ,
3338 pub r#type : MetaType ,
34- pub data : Vec < String > ,
39+ pub data : Vec < ParsableDefinition > ,
3540}
3641
3742impl Meta {
3843 pub fn read_from_file < P > ( name : String , r#type : MetaType , file_path : P ) -> Result < Meta , Error >
3944 where
4045 P : AsRef < Path > ,
4146 {
47+
48+ let mut current_line = 0 ;
49+ let mut current_starting_line = 0 ;
4250 let mut inside_code = false ;
4351 let mut current_block = vec ! [ ] ;
44- let mut code_snippets = vec ! [ ] ;
52+ let mut code_snippets: Vec < ParsableDefinition > = vec ! [ ] ;
4553
46- let content = match fs:: read_to_string ( file_path) {
54+ let path = match file_path. as_ref ( ) . to_str ( ) {
55+ Some ( str) => Some ( str. to_string ( ) ) ,
56+ None => None ,
57+ } ;
58+
59+ let content = match fs:: read_to_string ( & file_path) {
4760 Ok ( content) => content,
4861 Err ( err) => {
4962 println ! ( "Error reading file: {err}" ) ;
@@ -52,18 +65,26 @@ impl Meta {
5265 } ;
5366
5467 for line in content. lines ( ) {
68+ current_line += 1 ;
5569 if line. contains ( "```" ) {
5670 inside_code = !inside_code;
5771
5872 if !inside_code {
5973 let code_snippet = current_block. join ( " " ) ;
60- code_snippets. push ( code_snippet) ;
74+ code_snippets. push (
75+ ParsableDefinition {
76+ path : path. clone ( ) ,
77+ starting_line : current_starting_line,
78+ definition_string : code_snippet,
79+ }
80+ ) ;
6181 current_block. clear ( ) ;
6282 }
6383 }
6484
6585 if inside_code {
6686 if line. starts_with ( "```" ) {
87+ current_starting_line = current_line;
6788 continue ;
6889 }
6990
@@ -81,7 +102,7 @@ impl Meta {
81102
82103/// Reader
83104///
84- /// Expecting the file system too look like:
105+ /// Expecting the file system to look like:
85106/// - <path>
86107/// - <feature>
87108/// - <flow_types>
0 commit comments