Skip to content

Commit 9a8e314

Browse files
committed
[IMP] server: remove act_window and _report tags
1 parent a024551 commit 9a8e314

File tree

4 files changed

+61
-197
lines changed

4 files changed

+61
-197
lines changed

server/src/core/xml_arch_builder_rng_validation.rs

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use regex::Regex;
66
use roxmltree::Node;
77
use tracing::{error, warn};
88

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

1111
use super::{file_mgr::FileInfo, odoo::SyncOdoo, symbols::{symbol::Symbol, xml_file_symbol::XmlFileSymbol}, xml_arch_builder::XmlArchBuilder};
1212

@@ -40,8 +40,6 @@ impl XmlArchBuilder {
4040
|| self.load_record(session, &child, diagnostics)
4141
|| self.load_template(session, &child, diagnostics)
4242
|| self.load_delete(session, &child, diagnostics)
43-
|| self.load_act_window(session, &child, diagnostics)
44-
|| self.load_report(session, &child, diagnostics)
4543
|| self.load_function(session, &child, diagnostics)
4644
|| child.is_text() || child.is_comment()) {
4745
diagnostics.push(Diagnostic::new(
@@ -578,137 +576,6 @@ impl XmlArchBuilder {
578576
true
579577
}
580578

581-
fn load_act_window(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> bool {
582-
if node.tag_name().name() != "act_window" { return false; }
583-
let mut found_id = None;
584-
for attr in ["id", "name", "res_model"] {
585-
if node.attribute(attr).is_none() {
586-
diagnostics.push(Diagnostic::new(
587-
Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
588-
Some(DiagnosticSeverity::ERROR),
589-
Some(lsp_types::NumberOrString::String(S!("OLS304032"))),
590-
Some(EXTENSION_NAME.to_string()),
591-
format!("act_window node must contain a {} attribute", attr),
592-
None,
593-
None));
594-
}
595-
if attr == "id" {
596-
found_id = Some(node.attribute(attr).unwrap().to_string());
597-
}
598-
}
599-
for attr in node.attributes() {
600-
match attr.name() {
601-
"id" | "name" | "res_model" => {},
602-
"domain" | "view_mode" | "view_id" | "target" | "context" | "groups" | "limit" | "usage" | "binding_model" => {},
603-
"binding_type" => {
604-
if attr.value() != "action" && attr.value() != "report" {
605-
diagnostics.push(Diagnostic::new(
606-
Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
607-
Some(DiagnosticSeverity::ERROR),
608-
Some(lsp_types::NumberOrString::String(S!("OLS304034"))),
609-
Some(EXTENSION_NAME.to_string()),
610-
format!("binding_type attribute must be either 'action' or 'report', found {}", attr.value()),
611-
None,
612-
None));
613-
}
614-
},
615-
"binding_views" => {
616-
if !BINDING_VIEWS_RE.is_match(attr.value()) {
617-
diagnostics.push(Diagnostic::new(
618-
Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
619-
Some(DiagnosticSeverity::ERROR),
620-
Some(lsp_types::NumberOrString::String(S!("OLS304035"))),
621-
Some(EXTENSION_NAME.to_string()),
622-
format!("binding_views attribute must be a comma-separated list of view types matching ^([a-z]+(,[a-z]+)*)?$, found {}", attr.value()),
623-
None,
624-
None));
625-
}
626-
},
627-
_ => {
628-
diagnostics.push(Diagnostic::new(
629-
Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
630-
Some(DiagnosticSeverity::ERROR),
631-
Some(lsp_types::NumberOrString::String(S!("OLS304033"))),
632-
Some(EXTENSION_NAME.to_string()),
633-
format!("Invalid attribute {} in act_window node", attr.name()),
634-
None,
635-
None));
636-
}
637-
}
638-
}
639-
if node.text().is_some() {
640-
diagnostics.push(Diagnostic::new(
641-
Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
642-
Some(DiagnosticSeverity::ERROR),
643-
Some(lsp_types::NumberOrString::String(S!("OLS304033"))),
644-
Some(EXTENSION_NAME.to_string()),
645-
format!("act_window node cannot have text content"),
646-
None,
647-
None));
648-
}
649-
let data = XmlData::ACT_WINDOW(XmlDataActWindow {
650-
file_symbol: Rc::downgrade(&self.xml_symbol),
651-
xml_id: found_id.clone().map(|id| oyarn!("{}", id)),
652-
res_model: Sy!(node.attribute("res_model").unwrap().to_string()),
653-
name: Sy!(node.attribute("name").unwrap().to_string()),
654-
});
655-
self.on_operation_creation(session, found_id, node, data, diagnostics);
656-
true
657-
}
658-
659-
fn load_report(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> bool {
660-
if node.tag_name().name() != "report" { return false; }
661-
let mut found_id = None;
662-
for attr in ["string", "model", "name"] {
663-
if node.attribute(attr).is_none() {
664-
diagnostics.push(Diagnostic::new(
665-
Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
666-
Some(DiagnosticSeverity::ERROR),
667-
Some(lsp_types::NumberOrString::String(S!("OLS304036"))),
668-
Some(EXTENSION_NAME.to_string()),
669-
format!("report node must contain a {} attribute", attr),
670-
None,
671-
None));
672-
}
673-
}
674-
for attr in node.attributes() {
675-
match attr.name() {
676-
"id" => { found_id = Some(attr.value().to_string()); },
677-
"print_report_name" | "report_type" | "multi"| "menu" | "keyword" | "file" |
678-
"xml" | "parser" | "auto" | "header" | "attachment" | "attachment_use" | "groups" | "paperformat" | "usage" => {},
679-
_ => {
680-
diagnostics.push(Diagnostic::new(
681-
Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
682-
Some(DiagnosticSeverity::ERROR),
683-
Some(lsp_types::NumberOrString::String(S!("OLS304037"))),
684-
Some(EXTENSION_NAME.to_string()),
685-
format!("Invalid attribute {} in report node", attr.name()),
686-
None,
687-
None));
688-
}
689-
}
690-
}
691-
if node.text().is_some() {
692-
diagnostics.push(Diagnostic::new(
693-
Range { start: Position::new(node.range().start as u32, 0), end: Position::new(node.range().end as u32, 0) },
694-
Some(DiagnosticSeverity::ERROR),
695-
Some(lsp_types::NumberOrString::String(S!("OLS304038"))),
696-
Some(EXTENSION_NAME.to_string()),
697-
format!("report node cannot have text content"),
698-
None,
699-
None));
700-
}
701-
let data = XmlData::REPORT(XmlDataReport {
702-
file_symbol: Rc::downgrade(&self.xml_symbol),
703-
xml_id: found_id.clone().map(|id| oyarn!("{}", id)),
704-
name: Sy!(node.attribute("name").unwrap().to_string()),
705-
model: Sy!(node.attribute("model").unwrap().to_string()),
706-
string: Sy!(node.attribute("string").unwrap().to_string()),
707-
});
708-
self.on_operation_creation(session, found_id, node, data, diagnostics);
709-
true
710-
}
711-
712579
fn load_function(&mut self, session: &mut SessionInfo, node: &Node, diagnostics: &mut Vec<Diagnostic>) -> bool {
713580
if node.tag_name().name() != "function" { return false; }
714581
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)