Skip to content

Commit 822f472

Browse files
Merge pull request #336 from code0-tech/#333-module-structure
new module structure
2 parents e5c1aff + b9ecff4 commit 822f472

187 files changed

Lines changed: 2221 additions & 1289 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 388 additions & 410 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2024"
88
[workspace.dependencies]
99
serde = "1.0.219"
1010
serde_json = "1.0.140"
11-
tucana = "0.0.68"
11+
tucana = "0.0.69"
1212
clap = "4.5.41"
1313
colored = "3.0"
1414
tabled = "0.20"
@@ -21,3 +21,4 @@ bytes = "1.10.1"
2121
prost = "0.14.1"
2222
walkdir = "2.5.0"
2323
log = "0.4.28"
24+
tonic = "0.14.2"

crates/cli/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "code0-cli"
33
version = "0.0.0"
44
edition = "2024"
5-
description = "The cli for managing the Code0-Definitions"
5+
description = "The CLI for managing the CodeZero's definitions"
66
repository = "https://github.com/code0-tech/code0-definitions"
77
homepage = "https://code0.tech"
88
license = "Apache-2.0"
@@ -22,5 +22,6 @@ futures = { workspace = true }
2222
zip = { workspace = true }
2323
bytes = { workspace = true }
2424
prost = { workspace = true }
25-
tonic = "0.14.2"
26-
log = "0.4.28"
25+
tonic = { workspace = true }
26+
log = { workspace = true }
27+

crates/cli/src/analyser/core.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use crate::analyser::index_identifier::IdentifierIndex;
21
use crate::diagnostics::diagnose::Diagnose;
32
use crate::diagnostics::kinds::DiagnosticKind;
43
use crate::diagnostics::reporter::Reporter;
5-
use crate::parser::Meta;
6-
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition};
4+
use crate::parser::ModuleConfiguration;
5+
use crate::{analyser::index_identifier::IdentifierIndex, reader::Meta};
6+
use tucana::shared::{
7+
DefinitionDataType, FlowType, FunctionDefinition, ModuleConfigurationDefinition,
8+
RuntimeFlowType, RuntimeFunctionDefinition,
9+
};
710

811
#[derive(Clone)]
912
pub struct AnalysableDataType {
@@ -26,12 +29,44 @@ pub struct AnalysableFunction {
2629
pub id: i16,
2730
}
2831

32+
#[derive(Clone)]
33+
pub struct AnalysableRuntimeFlowType {
34+
pub original_definition: Meta,
35+
pub runtime_flow_type: RuntimeFlowType,
36+
pub id: i16,
37+
}
38+
39+
#[derive(Clone)]
40+
pub struct AnalysableFunctionDefinition {
41+
pub original_definition: Meta,
42+
pub function_definition: FunctionDefinition,
43+
pub id: i16,
44+
}
45+
46+
#[derive(Clone)]
47+
pub struct AnalysableModuleConfigurationDefinition {
48+
pub original_definition: Meta,
49+
pub module_configuration_definition: ModuleConfigurationDefinition,
50+
pub id: i16,
51+
}
52+
53+
#[derive(Clone)]
54+
pub struct AnalysableModuleDefinition {
55+
pub original_definition: Meta,
56+
pub module_definition: ModuleConfiguration,
57+
pub id: i16,
58+
}
59+
2960
pub struct Analyser {
3061
pub reporter: Reporter,
3162
pub(crate) index: IdentifierIndex,
3263
pub data_types: Vec<AnalysableDataType>,
3364
pub flow_types: Vec<AnalysableFlowType>,
3465
pub functions: Vec<AnalysableFunction>,
66+
pub runtime_flow_types: Vec<AnalysableRuntimeFlowType>,
67+
pub function_definitions: Vec<AnalysableFunctionDefinition>,
68+
pub module_configuration_definitions: Vec<AnalysableModuleConfigurationDefinition>,
69+
pub module_definitions: Vec<AnalysableModuleDefinition>,
3570
}
3671

3772
impl Analyser {
@@ -50,6 +85,18 @@ impl Analyser {
5085
for f in self.functions.clone() {
5186
self.analyse_runtime_function(&f);
5287
}
88+
for rft in self.runtime_flow_types.clone() {
89+
self.analyse_runtime_flow_type(&rft);
90+
}
91+
for f in self.function_definitions.clone() {
92+
self.analyse_function_definition(&f);
93+
}
94+
for config in self.module_configuration_definitions.clone() {
95+
self.analyse_module_configuration_definition(&config);
96+
}
97+
for module in self.module_definitions.clone() {
98+
self.analyse_module_definition(&module);
99+
}
53100
self.reporter.print(will_exit, true, with_warning);
54101
}
55102

crates/cli/src/analyser/data_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Analyser {
4747
));
4848
}
4949

50-
if dt.r#type == "" {
50+
if dt.r#type.is_empty() {
5151
self.reporter.add(Diagnose::new(
5252
dt.identifier.clone(),
5353
adt.original_definition.clone(),

crates/cli/src/analyser/flow_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Analyser {
7777
));
7878
}
7979

80-
if &flow.signature == "" {
80+
if flow.signature.is_empty() {
8181
self.reporter.add(Diagnose::new(
8282
name.clone(),
8383
original.clone(),

crates/cli/src/analyser/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Analyser {
7878
));
7979
}
8080

81-
if function.signature == "" {
81+
if function.signature.is_empty() {
8282
self.reporter.add(Diagnose::new(
8383
name.clone(),
8484
original.clone(),
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
use crate::analyser::core::{AnalysableFunctionDefinition, Analyser};
2+
use crate::diagnostics::diagnose::Diagnose;
3+
use crate::diagnostics::kinds::DiagnosticKind;
4+
5+
impl Analyser {
6+
pub fn analyse_function_definition(&mut self, afd: &AnalysableFunctionDefinition) {
7+
let name = afd.function_definition.runtime_name.clone();
8+
let function = &afd.function_definition;
9+
let original = afd.original_definition.clone();
10+
11+
for linked in function.linked_data_type_identifiers.clone() {
12+
if !self.data_type_identifier_exists(linked.as_str(), None) {
13+
self.reporter.add(Diagnose::new(
14+
name.clone(),
15+
original.clone(),
16+
DiagnosticKind::UndefinedDataTypeIdentifier {
17+
identifier: linked.clone(),
18+
},
19+
));
20+
}
21+
}
22+
23+
if function.display_icon.is_empty() {
24+
self.reporter.add(Diagnose::new(
25+
name.clone(),
26+
original.clone(),
27+
DiagnosticKind::NullField {
28+
field_name: "displayIcon".into(),
29+
},
30+
))
31+
}
32+
33+
if function.alias.is_empty() {
34+
self.reporter.add(Diagnose::new(
35+
name.clone(),
36+
original.clone(),
37+
DiagnosticKind::MissingTranslation {
38+
translation_field: "alias".into(),
39+
},
40+
));
41+
}
42+
43+
if function.display_message.is_empty() {
44+
self.reporter.add(Diagnose::new(
45+
name.clone(),
46+
original.clone(),
47+
DiagnosticKind::MissingTranslation {
48+
translation_field: "displayMessage".into(),
49+
},
50+
));
51+
}
52+
53+
if function.name.is_empty() {
54+
self.reporter.add(Diagnose::new(
55+
name.clone(),
56+
original.clone(),
57+
DiagnosticKind::UndefinedTranslation {
58+
translation_field: "name".into(),
59+
},
60+
));
61+
}
62+
if function.description.is_empty() {
63+
self.reporter.add(Diagnose::new(
64+
name.clone(),
65+
original.clone(),
66+
DiagnosticKind::UndefinedTranslation {
67+
translation_field: "description".into(),
68+
},
69+
));
70+
}
71+
if function.documentation.is_empty() {
72+
self.reporter.add(Diagnose::new(
73+
name.clone(),
74+
original.clone(),
75+
DiagnosticKind::UndefinedTranslation {
76+
translation_field: "documentation".into(),
77+
},
78+
));
79+
}
80+
81+
if function.signature.is_empty() {
82+
self.reporter.add(Diagnose::new(
83+
name.clone(),
84+
original.clone(),
85+
DiagnosticKind::NullField {
86+
field_name: "signature".into(),
87+
},
88+
));
89+
}
90+
91+
let mut param_names: Vec<String> = vec![];
92+
for parameter in &function.parameter_definitions {
93+
if parameter.name.is_empty() {
94+
self.reporter.add(Diagnose::new(
95+
name.clone(),
96+
original.clone(),
97+
DiagnosticKind::UndefinedTranslation {
98+
translation_field: "name".into(),
99+
},
100+
));
101+
}
102+
if parameter.description.is_empty() {
103+
self.reporter.add(Diagnose::new(
104+
name.clone(),
105+
original.clone(),
106+
DiagnosticKind::UndefinedTranslation {
107+
translation_field: "description".into(),
108+
},
109+
));
110+
}
111+
if parameter.documentation.is_empty() {
112+
self.reporter.add(Diagnose::new(
113+
name.clone(),
114+
original.clone(),
115+
DiagnosticKind::UndefinedTranslation {
116+
translation_field: "documentation".into(),
117+
},
118+
));
119+
}
120+
121+
if param_names.contains(&parameter.runtime_name) {
122+
self.reporter.add(Diagnose::new(
123+
name.clone(),
124+
original.clone(),
125+
DiagnosticKind::DuplicateRuntimeParameterIdentifier {
126+
identifier: parameter.runtime_name.clone(),
127+
},
128+
));
129+
}
130+
param_names.push(parameter.runtime_name.clone());
131+
}
132+
133+
if self.index.has_function_definition(&name, Some(afd.id)) {
134+
self.reporter.add(Diagnose::new(
135+
name.clone(),
136+
original.clone(),
137+
DiagnosticKind::DuplicateFunctionIdentifier { identifier: name },
138+
));
139+
}
140+
}
141+
}

crates/cli/src/analyser/index_identifier.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::collections::HashMap;
44
pub struct IdentifierIndex {
55
data_types: HashMap<String, i16>,
66
flow_types: HashMap<String, i16>,
7+
runtime_flow_types: HashMap<String, i16>,
78
functions: HashMap<String, i16>,
9+
function_definitions: HashMap<String, i16>,
10+
module_configuration_definitions: HashMap<String, i16>,
811
}
912

1013
fn normalize(s: &str) -> String {
@@ -18,9 +21,19 @@ impl IdentifierIndex {
1821
pub fn insert_flow_type(&mut self, name: &str, id: i16) -> Option<i16> {
1922
self.flow_types.insert(normalize(name), id)
2023
}
24+
pub fn insert_runtime_flow_type(&mut self, name: &str, id: i16) -> Option<i16> {
25+
self.runtime_flow_types.insert(normalize(name), id)
26+
}
2127
pub fn insert_function(&mut self, name: &str, id: i16) -> Option<i16> {
2228
self.functions.insert(normalize(name), id)
2329
}
30+
pub fn insert_function_definition(&mut self, name: &str, id: i16) -> Option<i16> {
31+
self.function_definitions.insert(normalize(name), id)
32+
}
33+
pub fn insert_module_configuration_definition(&mut self, name: &str, id: i16) -> Option<i16> {
34+
self.module_configuration_definitions
35+
.insert(normalize(name), id)
36+
}
2437

2538
pub fn has_data_type(&self, name: &str, except: Option<i16>) -> bool {
2639
self.data_types
@@ -35,4 +48,25 @@ impl IdentifierIndex {
3548
.map(|found| except.map(|e| *found != e).unwrap_or(true))
3649
.unwrap_or(false)
3750
}
51+
52+
pub fn has_runtime_flow_type(&self, name: &str, except: Option<i16>) -> bool {
53+
self.runtime_flow_types
54+
.get(&normalize(name))
55+
.map(|found| except.map(|e| *found != e).unwrap_or(true))
56+
.unwrap_or(false)
57+
}
58+
59+
pub fn has_function_definition(&self, name: &str, except: Option<i16>) -> bool {
60+
self.function_definitions
61+
.get(&normalize(name))
62+
.map(|found| except.map(|e| *found != e).unwrap_or(true))
63+
.unwrap_or(false)
64+
}
65+
66+
pub fn has_module_configuration_definition(&self, name: &str, except: Option<i16>) -> bool {
67+
self.module_configuration_definitions
68+
.get(&normalize(name))
69+
.map(|found| except.map(|e| *found != e).unwrap_or(true))
70+
.unwrap_or(false)
71+
}
3872
}

0 commit comments

Comments
 (0)