@@ -57,11 +57,13 @@ impl ReferenceFeature {
5757 /// TODO: All files within workspace
5858 /// TODO: Odoo specific (XML field refs, string-based model refs)
5959 pub fn get_references ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , file_info : & Rc < RefCell < FileInfo > > , line : u32 , character : u32 ) -> Option < Vec < Location > > {
60- let offset = file_info. borrow ( ) . position_to_offset ( line, character) ;
60+ let offset = file_info. borrow ( ) . position_to_offset ( line, character, session . sync_odoo . encoding ) ;
6161
62- let ( analyse_ast_result, _range, _call_expr) = AstUtils :: get_symbols ( session, file_symbol, file_info, offset as u32 ) ;
62+ let file_info_ast_clone = file_info. borrow ( ) . file_info_ast . clone ( ) ;
63+ let file_info_ast_ref = file_info_ast_clone. borrow ( ) ;
64+ let ( analyse_ast_result, _range, _expr, _call_expr) = AstUtils :: get_symbols ( session, & file_info_ast_ref, file_symbol, offset as u32 ) ;
6365
64- if analyse_ast_result. evaluations . is_empty ( ) {
66+ if analyse_ast_result. evaluations . len ( ) != 1 {
6567 return None ;
6668 }
6769
@@ -71,15 +73,45 @@ impl ReferenceFeature {
7173
7274 let symbol_name = target_symbol_rc. borrow ( ) . name ( ) . to_string ( ) ;
7375
76+ let mut locations = Vec :: new ( ) ;
77+ locations. extend ( ReferenceFeature :: references_in_files ( session, file_symbol, file_info, & symbol_name, & target_symbol_rc) ) ;
78+
79+ //take arch and arch_eval dependents
80+ for dep in file_symbol. borrow ( ) . dependents ( ) [ 0 ] . iter ( ) . take ( 2 ) {
81+ if let Some ( dep_set) = dep {
82+ for dep_symbol_rc in dep_set. iter ( ) {
83+ let Some ( Some ( file) ) = dep_symbol_rc. borrow ( ) . get_file ( ) . map ( |x| x. upgrade ( ) ) else { //to be sure we are on a file
84+ continue ;
85+ } ;
86+ let Some ( dep_file_info) = session. sync_odoo . get_file_mgr ( ) . borrow ( ) . get_file_info ( & file. borrow ( ) . paths ( ) [ 0 ] ) else {
87+ continue ;
88+ } ;
89+ locations. extend ( ReferenceFeature :: references_in_files ( session, & dep_symbol_rc, & dep_file_info, & symbol_name, & target_symbol_rc) ) ;
90+ }
91+ }
92+ }
93+
94+ if locations. is_empty ( ) {
95+ None
96+ } else {
97+ Some ( locations)
98+ }
99+ }
100+
101+ pub fn references_in_files ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , file_info : & Rc < RefCell < FileInfo > > , symbol_name : & String , target_symbol_rc : & Rc < RefCell < Symbol > > ) -> Vec < Location > {
74102 // find all Name expressions with the same name
75103 let file_info_ast = file_info. borrow ( ) . file_info_ast . clone ( ) ;
76104 let file_info_ast_borrow = file_info_ast. borrow ( ) ;
77- let stmts = file_info_ast_borrow. get_stmts ( ) ?;
105+ let stmts = file_info_ast_borrow. get_stmts ( ) ;
106+ let stmts = match stmts {
107+ Some ( s) => s,
108+ None => return Vec :: new ( ) ,
109+ } ;
78110
79- let name_matches = NameFinderVisitor :: find_all_names ( stmts, & symbol_name) ;
111+ let name_matches = NameFinderVisitor :: find_all_names ( stmts, symbol_name) ;
80112
81113 if name_matches. is_empty ( ) {
82- return None ;
114+ return Vec :: new ( ) ;
83115 }
84116
85117 let file_path = file_symbol. borrow ( ) . paths ( ) [ 0 ] . clone ( ) ;
@@ -106,12 +138,7 @@ impl ReferenceFeature {
106138 } ) ;
107139 }
108140 }
109-
110- if locations. is_empty ( ) {
111- None
112- } else {
113- Some ( locations)
114- }
141+ locations
115142 }
116143
117144 pub fn get_references_xml ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , file_info : & Rc < RefCell < FileInfo > > , line : u32 , character : u32 ) -> Option < Vec < Location > > {
0 commit comments