Skip to content

Commit 359e0ff

Browse files
committed
[FIX] server: adapt some diagnostics to new structure
1 parent 19a8344 commit 359e0ff

File tree

6 files changed

+50
-49
lines changed

6 files changed

+50
-49
lines changed

server/src/core/diagnostic_codes_list.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,16 @@ OLS05053, DiagnosticSetting::Error, "Action with id '{0}' does not exist",
407407
* A menuitem is specifying a group that has not been declared before the menuitem
408408
*/
409409
OLS05054, DiagnosticSetting::Error, "Group with id '{0}' does not exist",
410+
/**
411+
* Model not found
412+
*/
413+
OLS05055, DiagnosticSetting::Error, "Model '{0}' not found in module '{1}'",
414+
/**
415+
* Model not found
416+
*/
417+
OLS05056, DiagnosticSetting::Error, "Model '{0}' not found",
418+
/**
419+
* Field not found in model
420+
*/
421+
OLS05057, DiagnosticSetting::Error, "Field '{0}' not found in model '{1}'",
410422
}

server/src/core/odoo.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::core::diagnostics::{create_diagnostic, DiagnosticCode};
12
use crate::core::entry_point::EntryPointType;
23
use crate::core::file_mgr::AstType;
34
use crate::core::symbols::file_symbol;
@@ -935,7 +936,7 @@ impl SyncOdoo {
935936
/**
936937
* search for an xml_id in the already registered xml files.
937938
* */
938-
pub fn get_xml_ids(&mut self, from_file: &Rc<RefCell<Symbol>>, xml_id: &str, range: &std::ops::Range<usize>, diagnostics: &mut Vec<Diagnostic>) -> Vec<XmlData> {
939+
pub fn get_xml_ids(session: &mut SessionInfo, from_file: &Rc<RefCell<Symbol>>, xml_id: &str, range: &std::ops::Range<usize>, diagnostics: &mut Vec<Diagnostic>) -> Vec<XmlData> {
939940
if !from_file.borrow().get_entry().unwrap().borrow().is_main() {
940941
return vec![];
941942
}
@@ -946,22 +947,19 @@ impl SyncOdoo {
946947
module = from_file.borrow().find_module();
947948
} else if id_split.len() == 2 {
948949
// Try to find the module by name
949-
if let Some(m) = self.modules.get(&Sy!(id_split.first().unwrap().to_string())) {
950+
if let Some(m) = session.sync_odoo.modules.get(&Sy!(id_split.first().unwrap().to_string())) {
950951
module = m.upgrade();
951952
}
952953
} else if id_split.len() > 2 {
953-
diagnostics.push(Diagnostic::new(
954-
Range {
955-
start: Position::new(range.start as u32, 0),
956-
end: Position::new(range.end as u32, 0),
957-
},
958-
Some(DiagnosticSeverity::ERROR),
959-
Some(lsp_types::NumberOrString::String(S!("OLS30446"))),
960-
Some(EXTENSION_NAME.to_string()),
961-
format!("Invalid XML ID '{}'. It should not contain more than one dot", xml_id),
962-
None,
963-
None
964-
));
954+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05051, &[xml_id]) {
955+
diagnostics.push(lsp_types::Diagnostic {
956+
range: lsp_types::Range {
957+
start: lsp_types::Position::new(range.start as u32, 0),
958+
end: lsp_types::Position::new(range.end as u32, 0),
959+
},
960+
..diagnostic.clone()
961+
});
962+
}
965963
return vec![];
966964
}
967965
if module.is_none() {

server/src/core/xml_arch_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use roxmltree::{Attribute, Node};
66
use tracing::{error, warn};
77
use weak_table::PtrWeakHashSet;
88

9-
use crate::{core::{diagnostics::{create_diagnostic, DiagnosticCode}}};
9+
use crate::core::{diagnostics::{create_diagnostic, DiagnosticCode}, odoo::SyncOdoo};
1010
use crate::{constants::{BuildStatus, BuildSteps, OYarn, EXTENSION_NAME}, core::{entry_point::EntryPointType, xml_data::XmlData}, oyarn, threads::SessionInfo, Sy, S};
1111

1212
use super::{file_mgr::FileInfo, symbols::{symbol::Symbol}};
@@ -87,7 +87,7 @@ impl XmlArchBuilder {
8787
}
8888

8989
pub fn get_group_ids(&self, session: &mut SessionInfo, xml_id: &str, attr: &Attribute, diagnostics: &mut Vec<Diagnostic>) -> Vec<XmlData> {
90-
let xml_ids = session.sync_odoo.get_xml_ids(&self.xml_symbol, xml_id, &attr.range(), diagnostics);
90+
let xml_ids = SyncOdoo::get_xml_ids(session, &self.xml_symbol, xml_id, &attr.range(), diagnostics);
9191
let mut res = vec![];
9292
for data in xml_ids.iter() {
9393
match data {

server/src/core/xml_arch_builder_rng_validation.rs

Lines changed: 3 additions & 3 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, XmlDataDelete, XmlDataField, XmlDataMenuItem, XmlDataRecord, XmlDataTemplate}}, oyarn, threads::SessionInfo, Sy, S};
8+
use crate::{constants::{BuildStatus, BuildSteps, OYarn, EXTENSION_NAME}, core::{diagnostics::{create_diagnostic, DiagnosticCode}, odoo::SyncOdoo, xml_data::{XmlData, XmlDataDelete, XmlDataField, XmlDataMenuItem, XmlDataRecord, XmlDataTemplate}}, oyarn, threads::SessionInfo, Sy, S};
99

1010
use super::xml_arch_builder::XmlArchBuilder;
1111

@@ -103,7 +103,7 @@ impl XmlArchBuilder {
103103
}
104104
}
105105
//check that action exists
106-
if session.sync_odoo.get_xml_ids(&self.xml_symbol, attr.value(), &attr.range(), diagnostics).is_empty() {
106+
if SyncOdoo::get_xml_ids(session, &self.xml_symbol, attr.value(), &attr.range(), diagnostics).is_empty() {
107107
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05053, &[attr.value()]) {
108108
diagnostics.push(Diagnostic {
109109
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },
@@ -122,7 +122,7 @@ impl XmlArchBuilder {
122122
}
123123
} else {
124124
//check that parent exists
125-
if session.sync_odoo.get_xml_ids(&self.xml_symbol, attr.value(), &attr.range(), diagnostics).is_empty() {
125+
if SyncOdoo::get_xml_ids(session, &self.xml_symbol, attr.value(), &attr.range(), diagnostics).is_empty() {
126126
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05052, &[attr.value()]) {
127127
diagnostics.push(Diagnostic {
128128
range: Range { start: Position::new(attr.range().start as u32, 0), end: Position::new(attr.range().end as u32, 0) },

server/src/core/xml_validation.rs

Lines changed: 19 additions & 28 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, XmlDataDelete, XmlDataMenuItem, XmlDataRecord, XmlDataTemplate}}, threads::SessionInfo, Sy, S};
6+
use crate::{constants::{BuildSteps, OYarn, SymType, DEBUG_STEPS, EXTENSION_NAME}, core::{diagnostics::{create_diagnostic, DiagnosticCode}, 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

@@ -69,15 +69,12 @@ impl XmlValidator {
6969
fn validate_record(&self, session: &mut SessionInfo, module: &Rc<RefCell<Symbol>>, xml_data_record: &XmlDataRecord, diagnostics: &mut Vec<Diagnostic>, dependencies: &mut Vec<Rc<RefCell<Symbol>>>, model_dependencies: &mut Vec<Rc<RefCell<Model>>>) {
7070
let Some(model) = session.sync_odoo.models.get(&xml_data_record.model.0).cloned() else {
7171
//TODO register to not_found_models
72-
diagnostics.push(Diagnostic::new(
73-
Range::new(Position::new(xml_data_record.model.1.start.try_into().unwrap(), 0), Position::new(xml_data_record.model.1.end.try_into().unwrap(), 0)),
74-
Some(lsp_types::DiagnosticSeverity::ERROR),
75-
Some(lsp_types::NumberOrString::String(S!("OLS30450"))),
76-
Some(EXTENSION_NAME.to_string()),
77-
format!("Model '{}' not found in module '{}'", xml_data_record.model.0, module.borrow().name()),
78-
None,
79-
None
80-
));
72+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05055, &[&xml_data_record.model.0, module.borrow().name()]) {
73+
diagnostics.push(Diagnostic {
74+
range: Range { start: Position::new(xml_data_record.model.1.start.try_into().unwrap(), 0), end: Position::new(xml_data_record.model.1.end.try_into().unwrap(), 0) },
75+
..diagnostic.clone()
76+
});
77+
}
8178
info!("Model '{}' not found in module '{}'", xml_data_record.model.0, module.borrow().name());
8279
return;
8380
};
@@ -130,31 +127,25 @@ impl XmlValidator {
130127
main_sym = model.borrow().get_main_symbols(session, from_module);
131128
}
132129
if main_sym.is_empty() {
133-
diagnostics.push(Diagnostic::new(
134-
Range::new(Position::new(field.text_range.as_ref().unwrap().start.try_into().unwrap(), 0), Position::new(field.text_range.as_ref().unwrap().end.try_into().unwrap(), 0)),
135-
Some(lsp_types::DiagnosticSeverity::ERROR),
136-
Some(lsp_types::NumberOrString::String(S!("OLS30453"))),
137-
Some(EXTENSION_NAME.to_string()),
138-
format!("Model '{}' not found", field.text.as_ref().unwrap()),
139-
None,
140-
None
141-
))
130+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05056, &[&field.text.as_ref().unwrap()]) {
131+
diagnostics.push(Diagnostic {
132+
range: Range { start: Position::new(field.text_range.as_ref().unwrap().start.try_into().unwrap(), 0), end: Position::new(field.text_range.as_ref().unwrap().end.try_into().unwrap(), 0) },
133+
..diagnostic.clone()
134+
});
135+
}
142136
}
143137
}
144138
},
145139
_ => {}
146140
}
147141
//TODO check type
148142
} else {
149-
diagnostics.push(Diagnostic::new(
150-
Range::new(Position::new(field.range.start.try_into().unwrap(), 0), Position::new(field.range.end.try_into().unwrap(), 0)),
151-
Some(lsp_types::DiagnosticSeverity::ERROR),
152-
Some(lsp_types::NumberOrString::String(S!("OLS30451"))),
153-
Some(EXTENSION_NAME.to_string()),
154-
format!("Field '{}' not found in model '{}'", field.name, xml_data_record.model.0),
155-
None,
156-
None
157-
));
143+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05057, &[&field.name, &xml_data_record.model.0]) {
144+
diagnostics.push(Diagnostic {
145+
range: Range { start: Position::new(field.range.start.try_into().unwrap(), 0), end: Position::new(field.range.end.try_into().unwrap(), 0) },
146+
..diagnostic.clone()
147+
});
148+
}
158149
}
159150
}
160151
//Diagnostic if some mandatory fields are not detected

server/src/features/xml_ast_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{cell::RefCell, collections::HashMap, ops::Range, rc::Rc};
22

33
use roxmltree::Node;
44

5-
use crate::{constants::OYarn, core::{evaluation::ContextValue, symbols::{module_symbol::ModuleSymbol, symbol::Symbol}, xml_data::XmlData}, threads::SessionInfo, Sy, S};
5+
use crate::{constants::OYarn, core::{evaluation::ContextValue, odoo::SyncOdoo, symbols::{module_symbol::ModuleSymbol, symbol::Symbol}, xml_data::XmlData}, threads::SessionInfo, Sy, S};
66

77
pub enum XmlAstResult {
88
SYMBOL(Rc<RefCell<Symbol>>),
@@ -194,7 +194,7 @@ impl XmlAstUtils {
194194
}
195195

196196
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) {
197-
let mut xml_ids = session.sync_odoo.get_xml_ids(file_symbol, xml_id, &range, &mut vec![]);
197+
let mut xml_ids = SyncOdoo::get_xml_ids(session, file_symbol, xml_id, &range, &mut vec![]);
198198
if on_dep_only {
199199
xml_ids = xml_ids.into_iter().filter(|x|
200200
{

0 commit comments

Comments
 (0)