@@ -2,7 +2,7 @@ use std::{cell::RefCell, collections::HashMap, ops::Range, rc::Rc};
2
2
3
3
use roxmltree:: Node ;
4
4
5
- use crate :: { constants:: OYarn , core:: { evaluation:: ContextValue , symbols:: symbol:: Symbol , xml_data:: XmlData } , threads:: SessionInfo , Sy , S } ;
5
+ use crate :: { constants:: OYarn , core:: { evaluation:: ContextValue , symbols:: { module_symbol :: ModuleSymbol , symbol:: Symbol } , xml_data:: XmlData } , threads:: SessionInfo , Sy , S } ;
6
6
7
7
pub enum XmlAstResult {
8
8
SYMBOL ( Rc < RefCell < Symbol > > ) ,
@@ -29,61 +29,65 @@ pub struct XmlAstUtils {}
29
29
30
30
impl XmlAstUtils {
31
31
32
- pub fn get_symbols ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , root : roxmltree:: Node , offset : usize ) -> ( Vec < XmlAstResult > , Option < Range < usize > > ) {
32
+ pub fn get_symbols ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , root : roxmltree:: Node , offset : usize , on_dep_only : bool ) -> ( Vec < XmlAstResult > , Option < Range < usize > > ) {
33
33
let mut results = ( vec ! [ ] , None ) ;
34
34
let from_module = file_symbol. borrow ( ) . find_module ( ) ;
35
35
let mut context_xml = HashMap :: new ( ) ;
36
36
for node in root. children ( ) {
37
- XmlAstUtils :: visit_node ( session, & node, offset, from_module. clone ( ) , & mut context_xml, & mut results) ;
37
+ XmlAstUtils :: visit_node ( session, & node, offset, from_module. clone ( ) , & mut context_xml, & mut results, on_dep_only ) ;
38
38
}
39
39
results
40
40
}
41
41
42
- fn visit_node ( session : & mut SessionInfo < ' _ > , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) ) {
42
+ fn visit_node ( session : & mut SessionInfo < ' _ > , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) , on_dep_only : bool ) {
43
43
if node. is_element ( ) {
44
44
match node. tag_name ( ) . name ( ) {
45
45
"record" => {
46
- XmlAstUtils :: visit_record ( session, & node, offset, from_module. clone ( ) , ctxt, results) ;
46
+ XmlAstUtils :: visit_record ( session, & node, offset, from_module. clone ( ) , ctxt, results, on_dep_only ) ;
47
47
}
48
48
"field" => {
49
- XmlAstUtils :: visit_field ( session, & node, offset, from_module. clone ( ) , ctxt, results) ;
49
+ XmlAstUtils :: visit_field ( session, & node, offset, from_module. clone ( ) , ctxt, results, on_dep_only ) ;
50
50
}
51
51
_ => {
52
52
for child in node. children ( ) {
53
- XmlAstUtils :: visit_node ( session, & child, offset, from_module. clone ( ) , ctxt, results) ;
53
+ XmlAstUtils :: visit_node ( session, & child, offset, from_module. clone ( ) , ctxt, results, on_dep_only ) ;
54
54
}
55
55
}
56
56
}
57
57
} else if node. is_text ( ) {
58
- XmlAstUtils :: visit_text ( session, & node, offset, from_module, ctxt, results) ;
58
+ XmlAstUtils :: visit_text ( session, & node, offset, from_module, ctxt, results, on_dep_only ) ;
59
59
}
60
60
}
61
61
62
- fn visit_record ( session : & mut SessionInfo < ' _ > , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) ) {
62
+ fn visit_record ( session : & mut SessionInfo < ' _ > , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) , on_dep_only : bool ) {
63
63
for attr in node. attributes ( ) {
64
64
if attr. name ( ) == "model" {
65
65
let model_name = attr. value ( ) . to_string ( ) ;
66
66
ctxt. insert ( S ! ( "record_model" ) , ContextValue :: STRING ( model_name. clone ( ) ) ) ;
67
67
if attr. range_value ( ) . start <= offset && attr. range_value ( ) . end >= offset {
68
68
if let Some ( model) = session. sync_odoo . models . get ( & Sy ! ( model_name) ) . cloned ( ) {
69
- results. 0 . extend ( model. borrow ( ) . all_symbols ( session, from_module. clone ( ) , false ) . iter ( ) . filter ( |s| s. 1 . is_none ( ) ) . map ( |s| XmlAstResult :: SYMBOL ( s. 0 . clone ( ) ) ) ) ;
69
+ let from_module = match on_dep_only {
70
+ true => from_module. clone ( ) ,
71
+ false => None ,
72
+ } ;
73
+ results. 0 . extend ( model. borrow ( ) . all_symbols ( session, from_module, false ) . iter ( ) . filter ( |s| s. 1 . is_none ( ) ) . map ( |s| XmlAstResult :: SYMBOL ( s. 0 . clone ( ) ) ) ) ;
70
74
results. 1 = Some ( attr. range_value ( ) ) ;
71
75
}
72
76
}
73
77
} else if attr. name ( ) == "id" {
74
78
if attr. range_value ( ) . start <= offset && attr. range_value ( ) . end >= offset {
75
- XmlAstUtils :: add_xml_id_result ( session, attr. value ( ) , & from_module. as_ref ( ) . unwrap ( ) , attr. range_value ( ) , results) ;
79
+ XmlAstUtils :: add_xml_id_result ( session, attr. value ( ) , & from_module. as_ref ( ) . unwrap ( ) , attr. range_value ( ) , results, on_dep_only ) ;
76
80
results. 1 = Some ( attr. range_value ( ) ) ;
77
81
}
78
82
}
79
83
}
80
84
for child in node. children ( ) {
81
- XmlAstUtils :: visit_node ( session, & child, offset, from_module. clone ( ) , ctxt, results) ;
85
+ XmlAstUtils :: visit_node ( session, & child, offset, from_module. clone ( ) , ctxt, results, on_dep_only ) ;
82
86
}
83
87
ctxt. remove ( & S ! ( "record_model" ) ) ;
84
88
}
85
89
86
- fn visit_field ( session : & mut SessionInfo < ' _ > , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) ) {
90
+ fn visit_field ( session : & mut SessionInfo < ' _ > , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) , on_dep_only : bool ) {
87
91
for attr in node. attributes ( ) {
88
92
if attr. name ( ) == "name" {
89
93
ctxt. insert ( S ! ( "field_name" ) , ContextValue :: STRING ( attr. value ( ) . to_string ( ) ) ) ;
@@ -93,7 +97,11 @@ impl XmlAstUtils {
93
97
continue ;
94
98
}
95
99
if let Some ( model) = session. sync_odoo . models . get ( & Sy ! ( model_name) ) . cloned ( ) {
96
- for symbol in model. borrow ( ) . all_symbols ( session, from_module. clone ( ) , true ) {
100
+ let from_module = match on_dep_only {
101
+ true => from_module. clone ( ) ,
102
+ false => None ,
103
+ } ;
104
+ for symbol in model. borrow ( ) . all_symbols ( session, from_module, true ) {
97
105
if symbol. 1 . is_none ( ) {
98
106
let content = symbol. 0 . borrow ( ) . get_content_symbol ( attr. value ( ) , u32:: MAX ) ;
99
107
for symbol in content. symbols . iter ( ) {
@@ -113,19 +121,19 @@ impl XmlAstUtils {
113
121
}
114
122
}
115
123
if field_name == "inherit_id" {
116
- XmlAstUtils :: add_xml_id_result ( session, attr. value ( ) , & from_module. as_ref ( ) . unwrap ( ) , attr. range_value ( ) , results) ;
124
+ XmlAstUtils :: add_xml_id_result ( session, attr. value ( ) , & from_module. as_ref ( ) . unwrap ( ) , attr. range_value ( ) , results, on_dep_only ) ;
117
125
results. 1 = Some ( attr. range_value ( ) ) ;
118
126
}
119
127
}
120
128
}
121
129
}
122
130
for child in node. children ( ) {
123
- XmlAstUtils :: visit_node ( session, & child, offset, from_module. clone ( ) , ctxt, results) ;
131
+ XmlAstUtils :: visit_node ( session, & child, offset, from_module. clone ( ) , ctxt, results, on_dep_only ) ;
124
132
}
125
133
ctxt. remove ( & S ! ( "field_name" ) ) ;
126
134
}
127
135
128
- fn visit_text ( session : & mut SessionInfo , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) ) {
136
+ fn visit_text ( session : & mut SessionInfo , node : & Node , offset : usize , from_module : Option < Rc < RefCell < Symbol > > > , ctxt : & mut HashMap < String , ContextValue > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) , on_dep_only : bool ) {
129
137
if node. range ( ) . start <= offset && node. range ( ) . end >= offset {
130
138
let model = ctxt. get ( & S ! ( "record_model" ) ) . cloned ( ) . unwrap_or ( ContextValue :: STRING ( S ! ( "" ) ) ) . as_string ( ) ;
131
139
let field = ctxt. get ( & S ! ( "field_name" ) ) . cloned ( ) . unwrap_or ( ContextValue :: STRING ( S ! ( "" ) ) ) . as_string ( ) ;
@@ -135,16 +143,34 @@ impl XmlAstUtils {
135
143
if model == "ir.ui.view" {
136
144
if field == "model" {
137
145
if let Some ( model) = session. sync_odoo . models . get ( node. text ( ) . unwrap ( ) ) . cloned ( ) {
138
- results. 0 . extend ( model. borrow ( ) . all_symbols ( session, from_module. clone ( ) , false ) . iter ( ) . filter ( |s| s. 1 . is_none ( ) ) . map ( |s| XmlAstResult :: SYMBOL ( s. 0 . clone ( ) ) ) ) ;
146
+ let from_module = match on_dep_only {
147
+ true => from_module. clone ( ) ,
148
+ false => None ,
149
+ } ;
150
+ results. 0 . extend ( model. borrow ( ) . all_symbols ( session, from_module, false ) . iter ( ) . filter ( |s| s. 1 . is_none ( ) ) . map ( |s| XmlAstResult :: SYMBOL ( s. 0 . clone ( ) ) ) ) ;
139
151
results. 1 = Some ( node. range ( ) ) ;
140
152
}
141
153
}
142
154
}
143
155
}
144
156
}
145
157
146
- fn add_xml_id_result ( session : & mut SessionInfo , xml_id : & str , file_symbol : & Rc < RefCell < Symbol > > , range : Range < usize > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) ) {
147
- let xml_ids = session. sync_odoo . get_xml_ids ( file_symbol, xml_id, & range, & mut vec ! [ ] ) ;
158
+ fn add_xml_id_result ( session : & mut SessionInfo , xml_id : & str , file_symbol : & Rc < RefCell < Symbol > > , range : Range < usize > , results : & mut ( Vec < XmlAstResult > , Option < Range < usize > > ) , on_dep_only : bool ) {
159
+ let mut xml_ids = session. sync_odoo . get_xml_ids ( file_symbol, xml_id, & range, & mut vec ! [ ] ) ;
160
+ if on_dep_only {
161
+ xml_ids = xml_ids. into_iter ( ) . filter ( |x|
162
+ {
163
+ let file = x. get_xml_file_symbol ( ) ;
164
+ if let Some ( file) = file {
165
+ let module = file. borrow ( ) . find_module ( ) ;
166
+ if let Some ( module) = module {
167
+ return ModuleSymbol :: is_in_deps ( session, & file_symbol. borrow ( ) . find_module ( ) . unwrap ( ) , module. borrow ( ) . name ( ) ) ;
168
+ }
169
+ }
170
+ return false ;
171
+ }
172
+ ) . collect :: < Vec < _ > > ( ) ;
173
+ }
148
174
for xml_data in xml_ids. iter ( ) {
149
175
match xml_data {
150
176
XmlData :: RECORD ( r) => {
0 commit comments