Skip to content

Commit 35962b3

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] features: update origin range highlighting in definition
1 parent 4b0a321 commit 35962b3

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

server/src/features/definition.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lsp_types::{GotoDefinitionResponse, Location, LocationLink, Position, Range};
1+
use lsp_types::{GotoDefinitionResponse, LocationLink, Range};
22
use ruff_python_ast::{Expr, ExprCall};
33
use ruff_text_size::TextSize;
44
use std::path::PathBuf;
@@ -9,7 +9,6 @@ use crate::core::evaluation::{Evaluation, EvaluationValue};
99
use crate::core::file_mgr::{FileInfo, FileMgr};
1010
use crate::core::odoo::SyncOdoo;
1111
use crate::core::symbols::symbol::Symbol;
12-
use crate::core::symbols::xml_file_symbol;
1312
use crate::features::ast_utils::AstUtils;
1413
use crate::features::features_utils::FeaturesUtils;
1514
use crate::features::xml_ast_utils::{XmlAstResult, XmlAstUtils};
@@ -35,7 +34,7 @@ impl DefinitionFeature {
3534
let string_domain_fields = FeaturesUtils::find_argument_symbols(
3635
session, Symbol::get_scope_symbol(file_symbol.clone(), offset as u32, false), file_symbol.borrow().find_module(), &field_name, call_expr, offset, field_range
3736
);
38-
string_domain_fields.iter().for_each(|field|{
37+
string_domain_fields.iter().for_each(|(field, field_range)|{
3938
if let Some(file_sym) = field.borrow().get_file().and_then(|file_sym_weak| file_sym_weak.upgrade()){
4039
let path = file_sym.borrow().paths()[0].clone();
4140
let range = session.sync_odoo.get_file_mgr().borrow().text_range_to_range(session, &path, &field.borrow().range());

server/src/features/features_utils.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl FeaturesUtils {
106106
field_range: &TextRange,
107107
field_name: &String,
108108
offset: &usize,
109-
) -> Vec<Rc<RefCell<Symbol>>>{
109+
) -> Vec<(Rc<RefCell<Symbol>>, TextRange)>{
110110
if base_symbol.borrow().as_class_sym()._model.is_none(){
111111
return vec![];
112112
}
@@ -120,7 +120,7 @@ impl FeaturesUtils {
120120
let cursor_section = TextRange::new(range_start, range_end).contains(TextSize::new(*offset as u32));
121121
if cursor_section {
122122
let fields = parent_object.clone().unwrap().borrow().get_member_symbol(session, &name, from_module.clone(), false, true, true, false).0;
123-
return fields;
123+
return fields.into_iter().map(|f| (f, TextRange::new(range_start, range_end - TextSize::new(1)))).collect();
124124
} else {
125125
let (symbols, _diagnostics) = parent_object.clone().unwrap().borrow().get_member_symbol(session,
126126
&name.to_string(),
@@ -157,7 +157,7 @@ impl FeaturesUtils {
157157
field_range: &TextRange,
158158
field_name: &String,
159159
offset: &usize,
160-
) -> Vec<Rc<RefCell<Symbol>>>{
160+
) -> Vec<(Rc<RefCell<Symbol>>, TextRange)>{
161161
let Some(parent_class) = scope.borrow().get_in_parents(&vec![SymType::CLASS], true).and_then(|p| p.upgrade()) else {
162162
return vec![];
163163
};
@@ -171,7 +171,7 @@ impl FeaturesUtils {
171171
field_name: &String,
172172
offset: &usize,
173173
from_module: &Option<Rc<RefCell<Symbol>>>,
174-
) -> Vec<Rc<RefCell<Symbol>>> {
174+
) -> Vec<(Rc<RefCell<Symbol>>, TextRange)> {
175175
let Some(parent_object) = callable.context.get(&S!("base_attr")).and_then(|parent_object| parent_object.as_symbol().upgrade()) else {
176176
return vec![];
177177
};
@@ -187,8 +187,8 @@ impl FeaturesUtils {
187187
offset: usize,
188188
field_range: TextRange,
189189
arg_index: usize,
190-
) -> Vec<Rc<RefCell<Symbol>>>{
191-
let mut arg_symbols: Vec<Rc<RefCell<Symbol>>> = vec![];
190+
) -> Vec<(Rc<RefCell<Symbol>>, TextRange)> {
191+
let mut arg_symbols: Vec<(Rc<RefCell<Symbol>>, TextRange)> = vec![];
192192
let callable_evals = Evaluation::eval_from_ast(session, &call_expr.func, scope.clone(), &call_expr.func.range().start(), false, &mut vec![]).0;
193193
let mut followed_evals = vec![];
194194
for eval in callable_evals {
@@ -215,6 +215,7 @@ impl FeaturesUtils {
215215
if [vec![Sy!("onchange")], vec![Sy!("constrains")]].contains(&func_sym_tree.1) && SyncOdoo::is_in_main_entry(session, &func_sym_tree.0) {
216216
arg_symbols.extend(
217217
FeaturesUtils::find_simple_decorator_field_symbol(session, scope.clone(), from_module.clone(), field_name)
218+
.into_iter().map(|symbol| (symbol, field_range.clone()))
218219
);
219220
continue;
220221
} else if func_sym_tree.1 == vec![Sy!("depends")] && SyncOdoo::is_in_main_entry(session, &func_sym_tree.0){
@@ -255,12 +256,12 @@ impl FeaturesUtils {
255256
offset: usize,
256257
field_range: TextRange,
257258
keyword: &Keyword,
258-
) -> Vec<Rc<RefCell<Symbol>>>{
259+
) -> Vec<(Rc<RefCell<Symbol>>, TextRange)> {
259260
// We only process the `related` keyword argument
260261
if keyword.arg.as_ref().filter(|kw_arg| kw_arg.id == "related").is_none(){
261262
return vec![];
262263
}
263-
let mut arg_symbols: Vec<Rc<RefCell<Symbol>>> = vec![];
264+
let mut arg_symbols = vec![];
264265
let callable_evals = Evaluation::eval_from_ast(session, &call_expr.func, scope.clone(), &call_expr.func.range().start(), false, &mut vec![]).0;
265266
let mut followed_evals = vec![];
266267
for eval in callable_evals {
@@ -291,7 +292,7 @@ impl FeaturesUtils {
291292
call_expr: &ExprCall,
292293
offset: usize,
293294
field_range: TextRange,
294-
) -> Vec<Rc<RefCell<Symbol>>>{
295+
) -> Vec<(Rc<RefCell<Symbol>>, TextRange)>{
295296
if let Some((arg_index, _)) = call_expr.arguments.args.iter().enumerate().find(|(_, arg)|
296297
offset > arg.range().start().to_usize() && offset <= arg.range().end().to_usize()
297298
){
@@ -310,7 +311,7 @@ impl FeaturesUtils {
310311
let scope = Symbol::get_scope_symbol(file_symbol.clone(), offset as u32, false);
311312
let string_domain_fields_syms = FeaturesUtils::find_argument_symbols(session, scope.clone(), from_module.clone(), string_val, call_expr, offset, field_range);
312313
if string_domain_fields_syms.len() >= 1 {
313-
return string_domain_fields_syms;
314+
return string_domain_fields_syms.into_iter().map(|(sym, _)| sym).collect();
314315
}
315316
let compute_kwarg_syms = FeaturesUtils::find_field_symbols(session, scope.clone(), from_module.clone(), string_val, call_expr, &offset);
316317
if compute_kwarg_syms.len() >= 1{

0 commit comments

Comments
 (0)