Skip to content

Commit 35eb54d

Browse files
committed
feat: added path to meta of one definition
1 parent 79bee89 commit 35eb54d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

reader/rust/src/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Parser {
6060
Parser { features }
6161
}
6262

63-
fn extract_identifier(definition: &str, meta_type: MetaType) -> String {
63+
pub fn extract_identifier(definition: &str, meta_type: MetaType) -> String {
6464
let field_name = match meta_type {
6565
MetaType::DataType | MetaType::FlowType => "identifier",
6666
MetaType::RuntimeFunction => "runtime_name",
@@ -89,6 +89,7 @@ impl Parser {
8989

9090
fn append_meta(feature: &mut Feature, meta: &crate::reader::Meta) {
9191
for definition in &meta.data {
92+
let definition = definition.definition_string.as_str();
9293
match meta.r#type {
9394
MetaType::DataType => {
9495
match serde_json::from_str::<DefinitionDataType>(definition) {

reader/rust/src/reader.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,41 @@ impl std::fmt::Display for MetaType {
2222
}
2323
}
2424

25-
#[derive(Debug)]
2625
pub 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+
3136
pub struct Meta {
3237
pub name: String,
3338
pub r#type: MetaType,
34-
pub data: Vec<String>,
39+
pub data: Vec<ParsableDefinition>,
3540
}
3641

3742
impl 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

Comments
 (0)