Skip to content

Commit d4295f2

Browse files
committed
[IMP] server: remove act_window and _report tags
1 parent 21b81e6 commit d4295f2

File tree

4 files changed

+61
-181
lines changed

4 files changed

+61
-181
lines changed

server/src/core/xml_arch_builder_rng_validation.rs

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use once_cell::sync::Lazy;
55
use regex::Regex;
66
use roxmltree::Node;
77

8-
use crate::{constants::{BuildStatus, BuildSteps, OYarn, EXTENSION_NAME}, core::{diagnostics::{create_diagnostic, DiagnosticCode}, xml_data::{XmlData, XmlDataActWindow, XmlDataDelete, XmlDataField, XmlDataMenuItem, XmlDataRecord, XmlDataReport, XmlDataTemplate}}, oyarn, threads::SessionInfo, Sy, S};
8+
use crate::{constants::{BuildStatus, BuildSteps, OYarn, EXTENSION_NAME}, core::{diagnostics::{create_diagnostic, DiagnosticCode}, xml_data::{XmlData, XmlDataDelete, XmlDataField, XmlDataMenuItem, XmlDataRecord, XmlDataTemplate}}, oyarn, threads::SessionInfo, Sy, S};
99

1010
use super::xml_arch_builder::XmlArchBuilder;
1111

@@ -39,8 +39,6 @@ impl XmlArchBuilder {
3939
|| self.load_record(session, &child, diagnostics)
4040
|| self.load_template(session, &child, diagnostics)
4141
|| self.load_delete(session, &child, diagnostics)
42-
|| self.load_act_window(session, &child, diagnostics)
43-
|| self.load_report(session, &child, diagnostics)
4442
|| self.load_function(session, &child, diagnostics)
4543
|| child.is_text() || child.is_comment()) {
4644
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05005, &[child.tag_name().name(), node.tag_name().name()]) {
@@ -509,121 +507,6 @@ impl XmlArchBuilder {
509507
true
510508
}
511509

512-
fn load_act_window(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> bool {
513-
if node.tag_name().name() != "act_window" { return false; }
514-
let mut found_id = None;
515-
for attr in ["id", "name", "res_model"] {
516-
if node.attribute(attr).is_none() {
517-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05036, &[attr]) {
518-
diagnostics.push(Diagnostic {
519-
range: Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
520-
..diagnostic.clone()
521-
});
522-
}
523-
}
524-
if attr == "id" {
525-
found_id = node.attribute(attr).map(|v| v.to_string());
526-
}
527-
}
528-
for attr in node.attributes() {
529-
match attr.name() {
530-
"id" | "name" | "res_model" => {},
531-
"domain" | "view_mode" | "view_id" | "target" | "context" | "groups" | "limit" | "usage" | "binding_model" => {},
532-
"binding_type" => {
533-
if attr.value() != "action" && attr.value() != "report" {
534-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05039, &[attr.value()]) {
535-
diagnostics.push(Diagnostic {
536-
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
537-
..diagnostic.clone()
538-
});
539-
}
540-
}
541-
},
542-
"binding_views" => {
543-
if !BINDING_VIEWS_RE.is_match(attr.value()) {
544-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05040, &[attr.value()]) {
545-
diagnostics.push(Diagnostic {
546-
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
547-
..diagnostic.clone()
548-
});
549-
}
550-
}
551-
},
552-
_ => {
553-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05037, &[attr.name()]) {
554-
diagnostics.push(Diagnostic {
555-
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
556-
..diagnostic.clone()
557-
});
558-
}
559-
}
560-
}
561-
}
562-
if node.text().is_some() {
563-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05038, &[]) {
564-
diagnostics.push(Diagnostic {
565-
range: Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
566-
..diagnostic.clone()
567-
});
568-
}
569-
}
570-
let data = XmlData::ACT_WINDOW(XmlDataActWindow {
571-
file_symbol: Rc::downgrade(&self.xml_symbol),
572-
xml_id: found_id.clone().map(|id| oyarn!("{}", id)),
573-
res_model: Sy!(node.attribute("res_model").unwrap().to_string()),
574-
name: Sy!(node.attribute("name").unwrap().to_string()),
575-
});
576-
self.on_operation_creation(session, found_id, node, data, diagnostics);
577-
true
578-
}
579-
580-
fn load_report(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> bool {
581-
if node.tag_name().name() != "report" { return false; }
582-
let mut found_id = None;
583-
for attr in ["string", "model", "name"] {
584-
if node.attribute(attr).is_none() {
585-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05041, &[attr]) {
586-
diagnostics.push(Diagnostic {
587-
range: Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
588-
..diagnostic.clone()
589-
});
590-
}
591-
}
592-
}
593-
for attr in node.attributes() {
594-
match attr.name() {
595-
"id" => { found_id = Some(attr.value().to_string()); },
596-
"print_report_name" | "report_type" | "multi"| "menu" | "keyword" | "file" |
597-
"xml" | "parser" | "auto" | "header" | "attachment" | "attachment_use" | "groups" | "paperformat" | "usage" => {},
598-
_ => {
599-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05042, &[attr.name()]) {
600-
diagnostics.push(Diagnostic {
601-
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
602-
..diagnostic.clone()
603-
});
604-
}
605-
}
606-
}
607-
}
608-
if node.text().is_some() {
609-
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05043, &[]) {
610-
diagnostics.push(Diagnostic {
611-
range: Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
612-
..diagnostic.clone()
613-
});
614-
}
615-
}
616-
let data = XmlData::REPORT(XmlDataReport {
617-
file_symbol: Rc::downgrade(&self.xml_symbol),
618-
xml_id: found_id.clone().map(|id| oyarn!("{}", id)),
619-
name: Sy!(node.attribute("name").unwrap().to_string()),
620-
model: Sy!(node.attribute("model").unwrap().to_string()),
621-
string: Sy!(node.attribute("string").unwrap().to_string()),
622-
});
623-
self.on_operation_creation(session, found_id, node, data, diagnostics);
624-
true
625-
}
626-
627510
fn load_function(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> bool {
628511
if node.tag_name().name() != "function" { return false; }
629512
for attr in ["model", "name"] {

server/src/core/xml_data.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ pub enum XmlData {
1111
MENUITEM(XmlDataMenuItem),
1212
TEMPLATE(XmlDataTemplate),
1313
DELETE(XmlDataDelete),
14-
ACT_WINDOW(XmlDataActWindow),
15-
REPORT(XmlDataReport),
1614
}
1715

1816
#[derive(Debug, Clone)]
@@ -51,23 +49,6 @@ pub struct XmlDataDelete {
5149
pub model: OYarn,
5250
}
5351

54-
#[derive(Debug, Clone)]
55-
pub struct XmlDataActWindow {
56-
pub file_symbol: Weak<RefCell<Symbol>>,
57-
pub xml_id: Option<OYarn>,
58-
pub name: OYarn,
59-
pub res_model: OYarn,
60-
}
61-
62-
#[derive(Debug, Clone)]
63-
pub struct XmlDataReport {
64-
pub file_symbol: Weak<RefCell<Symbol>>,
65-
pub xml_id: Option<OYarn>,
66-
pub name: OYarn,
67-
pub model: OYarn,
68-
pub string: OYarn,
69-
}
70-
7152
impl XmlData {
7253

7354
pub fn set_file_symbol(&mut self, xml_symbol: &Rc<RefCell<Symbol>>) {
@@ -84,12 +65,6 @@ impl XmlData {
8465
XmlData::DELETE(ref mut delete) => {
8566
delete.file_symbol = Rc::downgrade(xml_symbol);
8667
},
87-
XmlData::ACT_WINDOW(ref mut act_window) => {
88-
act_window.file_symbol = Rc::downgrade(xml_symbol);
89-
},
90-
XmlData::REPORT(ref mut report) => {
91-
report.file_symbol = Rc::downgrade(xml_symbol);
92-
},
9368
}
9469
}
9570

@@ -117,13 +92,7 @@ impl XmlData {
11792
},
11893
XmlData::DELETE(ref delete) => {
11994
Some(delete.file_symbol.clone())
120-
},
121-
XmlData::ACT_WINDOW(ref act_window) => {
122-
Some(act_window.file_symbol.clone())
123-
},
124-
XmlData::REPORT(ref report) => {
125-
Some(report.file_symbol.clone())
126-
},
95+
}
12796
}
12897
}
12998
}

server/src/core/xml_validation.rs

Lines changed: 1 addition & 11 deletions
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, OYarn, 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, Sy, S};
6+
use crate::{constants::{BuildSteps, OYarn, 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, XmlDataDelete, XmlDataMenuItem, XmlDataRecord, XmlDataTemplate}}, threads::SessionInfo, Sy, S};
77

88

99

@@ -63,8 +63,6 @@ impl XmlValidator {
6363
XmlData::MENUITEM(xml_data_menu_item) => self.validate_menu_item(session, module, xml_data_menu_item, diagnostics, dependencies, model_dependencies),
6464
XmlData::TEMPLATE(xml_data_template) => self.validate_template(session, module, xml_data_template, diagnostics, dependencies, model_dependencies),
6565
XmlData::DELETE(xml_data_delete) => self.validate_delete(session, module, xml_data_delete, diagnostics, dependencies, model_dependencies),
66-
XmlData::ACT_WINDOW(xml_data_act_window) => self.validate_act_window(session, module, xml_data_act_window, diagnostics, dependencies, model_dependencies),
67-
XmlData::REPORT(xml_data_report) => self.validate_report(session, module, xml_data_report, diagnostics, dependencies, model_dependencies),
6866
}
6967
}
7068

@@ -185,12 +183,4 @@ impl XmlValidator {
185183
fn validate_delete(&self, session: &mut SessionInfo, module: &Rc<RefCell<Symbol>>, xml_data_delete: &XmlDataDelete, diagnostics: &mut Vec<Diagnostic>, dependencies: &mut Vec<Rc<RefCell<Symbol>>>, model_dependencies: &mut Vec<Rc<RefCell<Model>>>) {
186184

187185
}
188-
189-
fn validate_act_window(&self, session: &mut SessionInfo, module: &Rc<RefCell<Symbol>>, xml_data_act_window: &XmlDataActWindow, diagnostics: &mut Vec<Diagnostic>, dependencies: &mut Vec<Rc<RefCell<Symbol>>>, model_dependencies: &mut Vec<Rc<RefCell<Model>>>) {
190-
191-
}
192-
193-
fn validate_report(&self, session: &mut SessionInfo, module: &Rc<RefCell<Symbol>>, xml_data_report: &XmlDataReport, diagnostics: &mut Vec<Diagnostic>, dependencies: &mut Vec<Rc<RefCell<Symbol>>>, model_dependencies: &mut Vec<Rc<RefCell<Model>>>) {
194-
195-
}
196186
}

server/src/features/xml_ast_utils.rs

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ impl XmlAstUtils {
4747
}
4848
"field" => {
4949
XmlAstUtils::visit_field(session, &node, offset, from_module.clone(), ctxt, results, on_dep_only);
50+
},
51+
"menuitem" => {
52+
XmlAstUtils::visit_menu_item(session, &node, offset, from_module.clone(), ctxt, results, on_dep_only);
53+
},
54+
"template" => {
55+
XmlAstUtils::visit_template(session, &node, offset, from_module.clone(), ctxt, results, on_dep_only);
5056
}
5157
_ => {
5258
for child in node.children() {
@@ -114,16 +120,8 @@ impl XmlAstUtils {
114120
}
115121
} else if attr.name() == "ref" {
116122
if attr.range_value().start <= offset && attr.range_value().end >= offset {
117-
let mut field_name = "";
118-
for attr in node.attributes() {
119-
if attr.name() == "name" {
120-
field_name = attr.value();
121-
}
122-
}
123-
if field_name == "inherit_id" {
124-
XmlAstUtils::add_xml_id_result(session, attr.value(), &from_module.as_ref().unwrap(), attr.range_value(), results, on_dep_only);
125-
results.1 = Some(attr.range_value());
126-
}
123+
XmlAstUtils::add_xml_id_result(session, attr.value(), &from_module.as_ref().unwrap(), attr.range_value(), results, on_dep_only);
124+
results.1 = Some(attr.range_value());
127125
}
128126
}
129127
}
@@ -140,19 +138,59 @@ impl XmlAstUtils {
140138
if model.is_empty() || field.is_empty() {
141139
return;
142140
}
143-
if model == "ir.ui.view" {
144-
if field == "model" {
145-
if let Some(model) = session.sync_odoo.models.get(node.text().unwrap()).cloned() {
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())));
151-
results.1 = Some(node.range());
152-
}
141+
if field == "model" || field == "res_model" { //do not check model, let's assume it will contains a model name
142+
XmlAstUtils::add_model_result(session, node, from_module, results, on_dep_only);
143+
}
144+
}
145+
}
146+
147+
fn visit_menu_item(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) {
148+
for attr in node.attributes() {
149+
if attr.name() == "action" {
150+
if attr.range_value().start <= offset && attr.range_value().end >= offset {
151+
XmlAstUtils::add_xml_id_result(session, attr.value(), &from_module.as_ref().unwrap(), attr.range_value(), results, on_dep_only);
152+
results.1 = Some(attr.range_value());
153+
}
154+
} else if attr.name() == "groups" {
155+
if attr.range_value().start <= offset && attr.range_value().end >= offset {
156+
XmlAstUtils::add_xml_id_result(session, attr.value(), &from_module.as_ref().unwrap(), attr.range_value(), results, on_dep_only);
157+
results.1 = Some(attr.range_value());
158+
}
159+
}
160+
}
161+
for child in node.children() {
162+
XmlAstUtils::visit_node(session, &child, offset, from_module.clone(), ctxt, results, on_dep_only);
163+
}
164+
}
165+
166+
fn visit_template(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) {
167+
for attr in node.attributes() {
168+
if attr.name() == "inherit_id" {
169+
if attr.range_value().start <= offset && attr.range_value().end >= offset {
170+
XmlAstUtils::add_xml_id_result(session, attr.value(), &from_module.as_ref().unwrap(), attr.range_value(), results, on_dep_only);
171+
results.1 = Some(attr.range_value());
172+
}
173+
} else if attr.name() == "groups" {
174+
if attr.range_value().start <= offset && attr.range_value().end >= offset {
175+
XmlAstUtils::add_xml_id_result(session, attr.value(), &from_module.as_ref().unwrap(), attr.range_value(), results, on_dep_only);
176+
results.1 = Some(attr.range_value());
153177
}
154178
}
155179
}
180+
for child in node.children() {
181+
XmlAstUtils::visit_node(session, &child, offset, from_module.clone(), ctxt, results, on_dep_only);
182+
}
183+
}
184+
185+
fn add_model_result(session: &mut SessionInfo, node: &Node, from_module: Option<Rc<RefCell<Symbol>>>, results: &mut (Vec<XmlAstResult>, Option<Range<usize>>), on_dep_only: bool) {
186+
if let Some(model) = session.sync_odoo.models.get(node.text().unwrap()).cloned() {
187+
let from_module = match on_dep_only {
188+
true => from_module.clone(),
189+
false => None,
190+
};
191+
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())));
192+
results.1 = Some(node.range());
193+
}
156194
}
157195

158196
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) {

0 commit comments

Comments
 (0)