Skip to content

Commit 6afc2ac

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] Filter out magic fields from go to definition
1 parent 5341d1c commit 6afc2ac

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

server/src/core/python_odoo_builder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ use crate::{oyarn, Sy, S};
1717

1818
use super::evaluation::{ContextValue, Evaluation, EvaluationSymbolPtr, EvaluationValue};
1919

20+
pub const MAGIC_FIELDS: [&str; 6] = [
21+
"id",
22+
"display_name",
23+
"create_uid",
24+
"create_date",
25+
"write_uid",
26+
"write_date"
27+
];
28+
2029
pub struct PythonOdooBuilder {
2130
symbol: Rc<RefCell<Symbol>>,
2231
}

server/src/features/definition.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::constants::SymType;
88
use crate::core::evaluation::{Evaluation, EvaluationValue};
99
use crate::core::file_mgr::{FileInfo, FileMgr};
1010
use crate::core::odoo::SyncOdoo;
11+
use crate::core::python_odoo_builder::MAGIC_FIELDS;
1112
use crate::core::symbols::symbol::Symbol;
1213
use crate::features::ast_utils::AstUtils;
1314
use crate::features::features_utils::FeaturesUtils;
@@ -161,6 +162,20 @@ impl DefinitionFeature {
161162
}
162163
let mut links = vec![];
163164
let mut evaluations = analyse_ast_result.evaluations.clone();
165+
// Filter out magic fields
166+
evaluations.retain(|eval| {
167+
// Filter out, variables, whose parents are a class, whose name is one of the magic fields, and have the same range as their parent
168+
let eval_sym = eval.symbol.get_symbol(session, &mut None, &mut vec![], None);
169+
let Some(eval_sym) = eval_sym.upgrade_weak() else { return true; };
170+
if !MAGIC_FIELDS.contains(&eval_sym.borrow().name().as_str()) || eval_sym.borrow().typ() != SymType::VARIABLE || !eval_sym.borrow().is_field(session) {
171+
return true;
172+
}
173+
let Some(parent_sym) = eval_sym.borrow().parent().and_then(|parent| parent.upgrade()) else { return true; };
174+
if parent_sym.borrow().typ() != SymType::CLASS {
175+
return true;
176+
}
177+
eval_sym.borrow().range() != parent_sym.borrow().range()
178+
});
164179
let mut index = 0;
165180
while index < evaluations.len() {
166181
let eval = evaluations[index].clone();

0 commit comments

Comments
 (0)