Skip to content

Commit c130ea0

Browse files
committed
[IMP] handle model subscripts
1 parent f77b64f commit c130ea0

File tree

2 files changed

+63
-31
lines changed

2 files changed

+63
-31
lines changed

server/src/core/evaluation.rs

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,43 +1198,68 @@ impl Evaluation {
11981198
}
11991199
_ => {}
12001200
}
1201-
if base.is_weak() && let Some(value) = &value.0 {
1202-
let base = base.upgrade_weak().unwrap();
1203-
let get_item = base.borrow().get_content_symbol("__getitem__", u32::MAX).symbols;
1204-
if get_item.len() == 1 {
1205-
let get_item = &get_item[0];
1206-
let get_item = get_item.borrow();
1207-
if get_item.evaluations().is_some() && get_item.evaluations().unwrap().len() == 1 {
1208-
let get_item_eval = &get_item.evaluations().unwrap()[0];
1209-
if let Some(hook) = get_item_eval.symbol.get_symbol_hook.as_ref() {
1210-
let parent_file_or_func = parent.clone().borrow().parent_file_or_function().as_ref().unwrap().upgrade().unwrap();
1211-
let is_in_validation = match parent_file_or_func.borrow().typ().clone() {
1212-
SymType::FILE | SymType::PACKAGE(_) | SymType::FUNCTION => {
1213-
parent_file_or_func.borrow().build_status(BuildSteps::VALIDATION) == BuildStatus::IN_PROGRESS
1214-
},
1215-
_ => {false}
1216-
};
1201+
if !base.is_weak() {
1202+
continue;
1203+
}
1204+
let base = base.upgrade_weak().unwrap();
1205+
let get_item_symbols = base.borrow().get_member_symbol(
1206+
session,
1207+
&S!("__getitem__"),
1208+
parent.borrow().find_module(),
1209+
false,
1210+
false,
1211+
true,
1212+
true,
1213+
false,
1214+
).0;
1215+
for get_item in get_item_symbols.iter() {
1216+
let get_item = get_item.borrow();
1217+
let Some(evaluations) = get_item.evaluations() else {
1218+
continue;
1219+
};
1220+
for get_item_eval in evaluations {
1221+
if let Some(hook) = get_item_eval.symbol.get_symbol_hook.as_ref() {
1222+
let parent_file_or_func = parent.clone().borrow().parent_file_or_function().as_ref().unwrap().upgrade().unwrap();
1223+
let is_in_validation = match parent_file_or_func.borrow().typ().clone() {
1224+
SymType::FILE | SymType::PACKAGE(_) | SymType::FUNCTION => {
1225+
parent_file_or_func.borrow().build_status(BuildSteps::VALIDATION) == BuildStatus::IN_PROGRESS
1226+
},
1227+
_ => {false}
1228+
};
1229+
if let Some(value) = &value.0 {
12171230
context.as_mut().unwrap().insert(S!("args"), ContextValue::STRING(value.clone()));
1218-
let old_range = context.as_mut().unwrap().remove(&S!("range"));
1219-
context.as_mut().unwrap().insert(S!("range"), ContextValue::RANGE(sub.slice.range()));
1220-
context.as_mut().unwrap().insert(S!("is_in_validation"), ContextValue::BOOLEAN(is_in_validation));
1221-
let hook_result = (hook.callable)(session, &get_item_eval.symbol, context, &mut diagnostics, Some(parent.clone()));
1222-
if let Some(hook_result) = hook_result {
1223-
match hook_result {
1224-
EvaluationSymbolPtr::WEAK(ref weak) => {
1225-
if !weak.weak.is_expired() {
1226-
evals.push(Evaluation::eval_from_ptr(&hook_result));
1227-
}
1228-
},
1229-
_ => {
1231+
}
1232+
let old_range = context.as_mut().unwrap().remove(&S!("range"));
1233+
context.as_mut().unwrap().insert(S!("range"), ContextValue::RANGE(sub.slice.range()));
1234+
context.as_mut().unwrap().insert(S!("is_in_validation"), ContextValue::BOOLEAN(is_in_validation));
1235+
let hook_result = (hook.callable)(session, &get_item_eval.symbol, context, &mut diagnostics, Some(parent.clone()));
1236+
if let Some(hook_result) = hook_result {
1237+
match hook_result {
1238+
EvaluationSymbolPtr::WEAK(ref weak) => {
1239+
if !weak.weak.is_expired() {
12301240
evals.push(Evaluation::eval_from_ptr(&hook_result));
12311241
}
1242+
},
1243+
_ => {
1244+
evals.push(Evaluation::eval_from_ptr(&hook_result));
12321245
}
12331246
}
1234-
context.as_mut().unwrap().remove(&S!("args"));
1235-
context.as_mut().unwrap().remove(&S!("is_in_validation"));
1236-
context.as_mut().unwrap().insert(S!("range"), old_range.unwrap());
12371247
}
1248+
context.as_mut().unwrap().remove(&S!("args"));
1249+
context.as_mut().unwrap().remove(&S!("is_in_validation"));
1250+
context.as_mut().unwrap().insert(S!("range"), old_range.unwrap());
1251+
}
1252+
if let EvaluationSymbolPtr::SELF = get_item_eval.symbol.get_symbol_ptr(){
1253+
// Evaluate to the base itself
1254+
// For example for models, since you get the same type of recordset when subscripted
1255+
evals.push(Evaluation{
1256+
symbol: EvaluationSymbol {
1257+
sym: EvaluationSymbolPtr::WEAK(EvaluationSymbolWeak{weak: Rc::downgrade(&base), context: HashMap::new(), instance: Some(true), is_super: false}),
1258+
get_symbol_hook: None,
1259+
},
1260+
value: None,
1261+
range: Some(sub.range())
1262+
});
12381263
}
12391264
}
12401265
}

server/src/core/python_arch_eval_hooks.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,13 @@ static arch_eval_function_hooks: Lazy<Vec<PythonArchEvalFunctionHook>> = Lazy::n
472472
func: |_odoo: &mut SyncOdoo, _entry_point: &Rc<RefCell<EntryPoint>>, symbol: Rc<RefCell<Symbol>>| {
473473
symbol.borrow_mut().set_evaluations(vec![Evaluation::new_self()]);
474474
}},
475+
PythonArchEvalFunctionHook {odoo_entry: true,
476+
tree: vec![(Sy!("0.0"), Sy!("18.1"), (vec![Sy!("odoo"), Sy!("models")], vec![Sy!("BaseModel"), Sy!("__getitem__")])),
477+
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("models")], vec![Sy!("BaseModel"), Sy!("__getitem__")]))],
478+
if_exist_only: true,
479+
func: |_odoo: &mut SyncOdoo, _entry_point: &Rc<RefCell<EntryPoint>>, symbol: Rc<RefCell<Symbol>>| {
480+
symbol.borrow_mut().set_evaluations(vec![Evaluation::new_self()]);
481+
}},
475482
PythonArchEvalFunctionHook {odoo_entry: true,
476483
tree: vec![(Sy!("0.0"), Sy!("18.1"), (vec![Sy!("odoo"), Sy!("models")], vec![Sy!("BaseModel"), Sy!("with_env")])),
477484
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("models")], vec![Sy!("BaseModel"), Sy!("with_env")]))],

0 commit comments

Comments
 (0)