Skip to content

Commit 45f83e1

Browse files
committed
feat: added analyzer for new definition types
1 parent b2716de commit 45f83e1

8 files changed

Lines changed: 632 additions & 7 deletions

File tree

crates/cli/src/analyser/core.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use crate::diagnostics::diagnose::Diagnose;
22
use crate::diagnostics::kinds::DiagnosticKind;
33
use crate::diagnostics::reporter::Reporter;
4+
use crate::parser::ModuleConfiguration;
45
use crate::{analyser::index_identifier::IdentifierIndex, reader::Meta};
5-
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition};
6+
use tucana::shared::{
7+
DefinitionDataType, FlowType, FunctionDefinition, ModuleConfigurationDefinition,
8+
RuntimeFlowType, RuntimeFunctionDefinition,
9+
};
610

711
#[derive(Clone)]
812
pub struct AnalysableDataType {
@@ -25,12 +29,44 @@ pub struct AnalysableFunction {
2529
pub id: i16,
2630
}
2731

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+
2860
pub struct Analyser {
2961
pub reporter: Reporter,
3062
pub(crate) index: IdentifierIndex,
3163
pub data_types: Vec<AnalysableDataType>,
3264
pub flow_types: Vec<AnalysableFlowType>,
3365
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>,
3470
}
3571

3672
impl Analyser {
@@ -49,6 +85,18 @@ impl Analyser {
4985
for f in self.functions.clone() {
5086
self.analyse_runtime_function(&f);
5187
}
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+
}
52100
self.reporter.print(will_exit, true, with_warning);
53101
}
54102

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)