Skip to content

Commit f72aaae

Browse files
committed
[FIX] server: adapt some diagnostics to new structure
1 parent e533a76 commit f72aaae

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
@@ -412,4 +412,16 @@ OLS05053, DiagnosticSetting::Error, "Action with id '{0}' does not exist",
412412
* A menuitem is specifying a group that has not been declared before the menuitem
413413
*/
414414
OLS05054, DiagnosticSetting::Error, "Group with id '{0}' does not exist",
415+
/**
416+
* Model not found
417+
*/
418+
OLS05055, DiagnosticSetting::Error, "Model '{0}' not found in module '{1}'",
419+
/**
420+
* Model not found
421+
*/
422+
OLS05056, DiagnosticSetting::Error, "Model '{0}' not found",
423+
/**
424+
* Field not found in model
425+
*/
426+
OLS05057, DiagnosticSetting::Error, "Field '{0}' not found in model '{1}'",
415427
}

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;
@@ -937,7 +938,7 @@ impl SyncOdoo {
937938
/**
938939
* search for an xml_id in the already registered xml files.
939940
* */
940-
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> {
941+
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> {
941942
if !from_file.borrow().get_entry().unwrap().borrow().is_main() {
942943
return vec![];
943944
}
@@ -948,22 +949,19 @@ impl SyncOdoo {
948949
module = from_file.borrow().find_module();
949950
} else if id_split.len() == 2 {
950951
// Try to find the module by name
951-
if let Some(m) = self.modules.get(&Sy!(id_split.first().unwrap().to_string())) {
952+
if let Some(m) = session.sync_odoo.modules.get(&Sy!(id_split.first().unwrap().to_string())) {
952953
module = m.upgrade();
953954
}
954955
} else if id_split.len() > 2 {
955-
diagnostics.push(Diagnostic::new(
956-
Range {
957-
start: Position::new(range.start as u32, 0),
958-
end: Position::new(range.end as u32, 0),
959-
},
960-
Some(DiagnosticSeverity::ERROR),
961-
Some(lsp_types::NumberOrString::String(S!("OLS30446"))),
962-
Some(EXTENSION_NAME.to_string()),
963-
format!("Invalid XML ID '{}'. It should not contain more than one dot", xml_id),
964-
None,
965-
None
966-
));
956+
if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS05051, &[xml_id]) {
957+
diagnostics.push(lsp_types::Diagnostic {
958+
range: lsp_types::Range {
959+
start: lsp_types::Position::new(range.start as u32, 0),
960+
end: lsp_types::Position::new(range.end as u32, 0),
961+
},
962+
..diagnostic.clone()
963+
});
964+
}
967965
return vec![];
968966
}
969967
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)