Skip to content

Commit feed9f2

Browse files
committed
[IMP] server: check presence of required field in record (wip)
1 parent 8adfe8b commit feed9f2

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

server/src/core/python_arch_eval_hooks.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ impl PythonArchEvalHooks {
868868
"related",
869869
"compute",
870870
"delegate",
871+
"required",
872+
"default",
871873
];
872874
contexts_to_add.extend(
873875
context_arguments.into_iter()
@@ -887,6 +889,9 @@ impl PythonArchEvalHooks {
887889
if let Some(boolean) = maybe_boolean {
888890
context.insert(S!(arg_name), ContextValue::BOOLEAN(boolean));
889891
}
892+
if arg_name == "default" {
893+
context.insert(S!("default"), ContextValue::BOOLEAN(true)); //set to True as the value is not really useful for now, but we want the key in context if one default is set
894+
}
890895
}
891896
}
892897

server/src/core/python_odoo_builder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ impl PythonOdooBuilder {
9797
end: 1,
9898
}),
9999
xml_id: Some(xml_id_model_name),
100-
fields: vec![]
100+
fields: vec![],
101+
range: std::ops::Range::<usize> {
102+
start: self.symbol.borrow().range().start().to_usize(),
103+
end: self.symbol.borrow().range().end().to_usize(),
104+
}
101105
}));
102106
});
103107
session.sync_odoo.models.insert(model_name.clone(), Rc::new(RefCell::new(model)));

server/src/core/xml_arch_builder_rng_validation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ impl XmlArchBuilder {
218218
file_symbol: Rc::downgrade(&self.xml_symbol),
219219
model: (oyarn!("{}", node.attribute("model").unwrap()), node.attribute_node("model").unwrap().range()),
220220
xml_id: found_id.clone().map(|id| oyarn!("{}", id)),
221-
fields: vec![]
221+
fields: vec![],
222+
range: std::ops::Range::<usize> {
223+
start: node.range().start as usize,
224+
end: node.range().end as usize,
225+
}
222226
};
223227
for child in node.children().filter(|n| n.is_element()) {
224228
if let Some(field) = self.load_field(session, &child, diagnostics) {

server/src/core/xml_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct XmlDataRecord {
2121
pub model: (OYarn, Range<usize>),
2222
pub xml_id: Option<OYarn>,
2323
pub fields: Vec<XmlDataField>,
24+
pub range: Range<usize>,
2425
}
2526

2627
#[derive(Debug, Clone)]

server/src/core/xml_validation.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cell::RefCell, collections::HashMap, hash::Hash, path::PathBuf, rc::Rc
33
use lsp_types::{Diagnostic, Position, Range};
44
use tracing::{info, trace};
55

6-
use crate::{constants::{BuildSteps, SymType, DEBUG_STEPS, EXTENSION_NAME}, core::{entry_point::{EntryPoint, EntryPointType}, file_mgr::FileInfo, model::Model, odoo::SyncOdoo, symbols::symbol::Symbol, xml_data::{XmlData, XmlDataActWindow, XmlDataDelete, XmlDataMenuItem, XmlDataRecord, XmlDataReport, XmlDataTemplate}}, threads::SessionInfo, S};
6+
use crate::{constants::{BuildSteps, SymType, DEBUG_STEPS, EXTENSION_NAME}, core::{entry_point::{EntryPoint, EntryPointType}, evaluation::ContextValue, file_mgr::FileInfo, model::Model, odoo::SyncOdoo, symbols::symbol::Symbol, xml_data::{XmlData, XmlDataActWindow, XmlDataDelete, XmlDataMenuItem, XmlDataRecord, XmlDataReport, XmlDataTemplate}}, threads::SessionInfo, S};
77

88

99

@@ -89,9 +89,30 @@ impl XmlValidator {
8989
dependencies.push(main_sym.borrow().get_file().unwrap().upgrade().unwrap());
9090
}
9191
let all_fields = Symbol::all_fields(&main_symbols[0], session, Some(module.clone()));
92+
let mut mandatory_fields: Vec<String> = vec![];
93+
// for (field_name, field_sym) in all_fields.iter() {
94+
// for (fs, deps) in field_sym.iter() {
95+
// if deps.is_none() {
96+
// let has_required = fs.borrow().evaluations().unwrap_or(&vec![]).iter()
97+
// .any(|eval|
98+
// eval.symbol.get_symbol_as_weak(session, &mut None, diagnostics, None)
99+
// .context.get("required").unwrap_or(&ContextValue::BOOLEAN(false)).as_bool()
100+
// );
101+
// let has_default = fs.borrow().evaluations().unwrap_or(&vec![]).iter()
102+
// .any(|eval|
103+
// eval.symbol.get_symbol_as_weak(session, &mut None, diagnostics, None)
104+
// .context.contains_key("default")
105+
// );
106+
// if has_required && !has_default {
107+
// mandatory_fields.push(field_name.clone());
108+
// }
109+
// }
110+
// }
111+
// }
92112
for field in &xml_data_record.fields {
93113
let declared_field = all_fields.get(&field.name);
94114
if let Some(declared_field) = declared_field {
115+
mandatory_fields.retain(|f| f != &field.name);
95116
//TODO Check type
96117
} else {
97118

@@ -106,6 +127,17 @@ impl XmlValidator {
106127
));
107128
}
108129
}
130+
// if mandatory_fields.len() > 0 {
131+
// diagnostics.push(Diagnostic::new(
132+
// Range::new(Position::new(xml_data_record.range.start.try_into().unwrap(), 0), Position::new(xml_data_record.range.end.try_into().unwrap(), 0)),
133+
// Some(lsp_types::DiagnosticSeverity::ERROR),
134+
// Some(lsp_types::NumberOrString::String(S!("OLS30452"))),
135+
// Some(EXTENSION_NAME.to_string()),
136+
// format!("Some mandatory fields are not declared in the record: {:?}", mandatory_fields),
137+
// None,
138+
// None
139+
// ));
140+
// }
109141
}
110142

111143
fn validate_menu_item(&self, session: &mut SessionInfo, module: &Rc<RefCell<Symbol>>, xml_data_menu_item: &XmlDataMenuItem, diagnostics: &mut Vec<Diagnostic>, dependencies: &mut Vec<Rc<RefCell<Symbol>>>, model_dependencies: &mut Vec<Rc<RefCell<Model>>>) {

0 commit comments

Comments
 (0)