Skip to content

Commit 5dcc234

Browse files
committed
[IMP] server: check presence of required field in record (wip)
1 parent 7700db0 commit 5dcc234

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
@@ -874,6 +874,8 @@ impl PythonArchEvalHooks {
874874
"related",
875875
"compute",
876876
"delegate",
877+
"required",
878+
"default",
877879
];
878880
contexts_to_add.extend(
879881
context_arguments.into_iter()
@@ -893,6 +895,9 @@ impl PythonArchEvalHooks {
893895
if let Some(boolean) = maybe_boolean {
894896
context.insert(S!(arg_name), ContextValue::BOOLEAN(boolean));
895897
}
898+
if arg_name == "default" {
899+
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
900+
}
896901
}
897902
}
898903

server/src/core/python_odoo_builder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ impl PythonOdooBuilder {
6969
end: 1,
7070
}),
7171
xml_id: Some(xml_id_model_name),
72-
fields: vec![]
72+
fields: vec![],
73+
range: std::ops::Range::<usize> {
74+
start: self.symbol.borrow().range().start().to_usize(),
75+
end: self.symbol.borrow().range().end().to_usize(),
76+
}
7377
}));
7478
});
7579
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
@@ -244,7 +244,11 @@ impl XmlArchBuilder {
244244
file_symbol: Rc::downgrade(&self.xml_symbol),
245245
model: (oyarn!("{}", node.attribute("model").unwrap()), node.attribute_node("model").unwrap().range()),
246246
xml_id: found_id.clone().map(|id| oyarn!("{}", id)),
247-
fields: vec![]
247+
fields: vec![],
248+
range: std::ops::Range::<usize> {
249+
start: node.range().start as usize,
250+
end: node.range().end as usize,
251+
}
248252
};
249253
for child in node.children().filter(|n| n.is_element()) {
250254
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)