Skip to content

Commit 47d484d

Browse files
committed
[FIX] GoToDefinition on import statement
1 parent 65c655e commit 47d484d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

server/src/features/definition.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ impl DefinitionFeature {
232232
if analyse_ast_result.evaluations.is_empty() {
233233
return None;
234234
}
235-
let Some(expr) = expr else {
236-
return None; // Unreachable anyway
237-
};
238235
let mut links = vec![];
239236
let mut evaluations = analyse_ast_result.evaluations.clone();
240237
// Filter out magic fields
@@ -255,10 +252,9 @@ impl DefinitionFeature {
255252
}
256253
eval_sym.borrow().range() != parent_sym.borrow().range()
257254
});
258-
if dislay_name_found {
255+
if let Some(expr) = expr && dislay_name_found {
259256
DefinitionFeature::add_display_name_compute_methods(session, &mut links, &expr, file_symbol, offset);
260257
}
261-
drop(expr);
262258
drop(file_info_ast_ref);
263259
let mut index = 0;
264260
while index < evaluations.len() {
@@ -276,6 +272,16 @@ impl DefinitionFeature {
276272
continue;
277273
};
278274
if let Some(file) = symbol.borrow().get_file() {
275+
//For import variable, we should take the next evaluation if we are at the same location than the offset, as the get_symbol will return the current import variable (special case as the definition is from outside the file)
276+
if symbol.borrow().typ() == SymType::VARIABLE && symbol.borrow().as_variable().is_import_variable && Rc::ptr_eq(&file.upgrade().unwrap(), file_symbol) && symbol.borrow().has_range() && symbol.borrow().range().contains(TextSize::new(offset as u32)) {
277+
evaluations.remove(index);
278+
let symbol = symbol.borrow();
279+
let sym_eval = symbol.evaluations();
280+
if let Some(sym_eval) = sym_eval {
281+
evaluations = [evaluations.clone(), sym_eval.clone()].concat();
282+
}
283+
continue;
284+
}
279285
for path in file.upgrade().unwrap().borrow().paths().iter() {
280286
let full_path = match file.upgrade().unwrap().borrow().typ() {
281287
SymType::PACKAGE(_) => PathBuf::from(path).join(format!("__init__.py{}", file.upgrade().unwrap().borrow().as_package().i_ext())).sanitize(),

0 commit comments

Comments
 (0)