mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
10639: fix: make `goto_declaration` multi-token mapping aware r=Veykril a=spookyvision 10640: assume valid identifier r=Veykril a=spookyvision improve https://github.com/rust-analyzer/rust-analyzer/pull/10637/ by always returning `Some(potentially_empty_vec)` instead of `None` in the empty case Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
This commit is contained in:
commit
c48730cb72
2 changed files with 30 additions and 27 deletions
|
@ -19,28 +19,35 @@ pub(crate) fn goto_declaration(
|
||||||
let original_token = file
|
let original_token = file
|
||||||
.token_at_offset(position.offset)
|
.token_at_offset(position.offset)
|
||||||
.find(|it| matches!(it.kind(), IDENT | T![self] | T![super] | T![crate]))?;
|
.find(|it| matches!(it.kind(), IDENT | T![self] | T![super] | T![crate]))?;
|
||||||
let token = sema.descend_into_macros_single(original_token.clone());
|
let range = original_token.text_range();
|
||||||
let parent = token.parent()?;
|
let info: Vec<NavigationTarget> = sema
|
||||||
let def = match_ast! {
|
.descend_into_macros(original_token)
|
||||||
match parent {
|
.iter()
|
||||||
ast::NameRef(name_ref) => match NameRefClass::classify(&sema, &name_ref)? {
|
.filter_map(|token| {
|
||||||
NameRefClass::Definition(it) => Some(it),
|
let parent = token.parent()?;
|
||||||
_ => None
|
let def = match_ast! {
|
||||||
},
|
match parent {
|
||||||
ast::Name(name) => match NameClass::classify(&sema, &name)? {
|
ast::NameRef(name_ref) => match NameRefClass::classify(&sema, &name_ref)? {
|
||||||
NameClass::Definition(it) => Some(it),
|
NameRefClass::Definition(it) => Some(it),
|
||||||
_ => None
|
_ => None
|
||||||
},
|
},
|
||||||
_ => None,
|
ast::Name(name) => match NameClass::classify(&sema, &name)? {
|
||||||
}
|
NameClass::Definition(it) => Some(it),
|
||||||
};
|
_ => None
|
||||||
match def? {
|
},
|
||||||
Definition::ModuleDef(hir::ModuleDef::Module(module)) => Some(RangeInfo::new(
|
_ => None
|
||||||
original_token.text_range(),
|
}
|
||||||
vec![NavigationTarget::from_module_to_decl(db, module)],
|
};
|
||||||
)),
|
match def? {
|
||||||
_ => None,
|
Definition::ModuleDef(hir::ModuleDef::Module(module)) => {
|
||||||
}
|
Some(NavigationTarget::from_module_to_decl(db, module))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Some(RangeInfo::new(range, info))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -81,11 +81,7 @@ pub(crate) fn goto_type_definition(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if res.is_empty() {
|
Some(RangeInfo::new(range, res))
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(RangeInfo::new(range, res))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue