|
| 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(¶meter.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 | +} |
0 commit comments