diff --git a/server/src/core/python_arch_eval_hooks.rs b/server/src/core/python_arch_eval_hooks.rs index ef5b7b8d..ee9b4884 100644 --- a/server/src/core/python_arch_eval_hooks.rs +++ b/server/src/core/python_arch_eval_hooks.rs @@ -511,8 +511,9 @@ static arch_eval_function_hooks: Lazy> = Lazy::n (Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("models")], vec![Sy!("BaseModel"), Sy!("search")]))], if_exist_only: true, func: |odoo: &mut SyncOdoo, _entry_point: &Rc>, symbol: Rc>| { - let mut search: std::cell::RefMut = symbol.borrow_mut(); - let func = search.as_func_mut(); + symbol.borrow_mut().set_evaluations(vec![Evaluation::new_self()]); + let search = symbol.borrow(); + let func = search.as_func(); if func.args.len() > 1 { if let Some(arg_symbol) = func.args.get(1).unwrap().symbol.upgrade() { if arg_symbol.borrow().name().eq(&Sy!("domain")) { diff --git a/server/tests/test_hooks.rs b/server/tests/test_hooks.rs new file mode 100644 index 00000000..457480cc --- /dev/null +++ b/server/tests/test_hooks.rs @@ -0,0 +1,37 @@ +use std::env; +use std::path::PathBuf; + +use odoo_ls_server::core::odoo::SyncOdoo; +use odoo_ls_server::utils::PathSanitizer; + +mod setup; +mod test_utils; + +#[test] +fn test_search_eval_hook() { + let (mut odoo, config) = setup::setup::setup_server(true); + let mut session = setup::setup::create_init_session(&mut odoo, config); + + let test_file = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("tests/data/addons/module_1/models/base_test_models.py") + .sanitize(); + + let Some(file_symbol) = + SyncOdoo::get_symbol_of_opened_file(&mut session, &PathBuf::from(&test_file)) + else { + panic!("Failed to get file symbol for {}", test_file); + }; + + let file_mgr = session.sync_odoo.get_file_mgr(); + let file_info = file_mgr.borrow().get_file_info(&test_file).unwrap(); + + // Hover over closing parenthesis in call to `search` to verify its return type + let hover_text = test_utils::get_hover_markdown(&mut session, &file_symbol, &file_info, 33, 60) + .expect("Should get hover text for return type of search"); + + assert!( + hover_text.contains("BaseTestModel"), + "Hover over 'search' return type should show 'BaseTestModel' class. Got: {}", + hover_text + ); +}