mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
fix: make goto_declaration
multi-token mapping aware
This commit is contained in:
parent
ee1d6cffbf
commit
d8ed15b6a6
1 changed files with 29 additions and 22 deletions
|
@ -19,7 +19,11 @@ pub(crate) fn goto_declaration(
|
|||
let original_token = file
|
||||
.token_at_offset(position.offset)
|
||||
.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 info: Vec<NavigationTarget> = sema
|
||||
.descend_into_macros(original_token)
|
||||
.iter()
|
||||
.filter_map(|token| {
|
||||
let parent = token.parent()?;
|
||||
let def = match_ast! {
|
||||
match parent {
|
||||
|
@ -31,16 +35,19 @@ pub(crate) fn goto_declaration(
|
|||
NameClass::Definition(it) => Some(it),
|
||||
_ => None
|
||||
},
|
||||
_ => None,
|
||||
_ => None
|
||||
}
|
||||
};
|
||||
match def? {
|
||||
Definition::ModuleDef(hir::ModuleDef::Module(module)) => Some(RangeInfo::new(
|
||||
original_token.text_range(),
|
||||
vec![NavigationTarget::from_module_to_decl(db, module)],
|
||||
)),
|
||||
Definition::ModuleDef(hir::ModuleDef::Module(module)) => {
|
||||
Some(NavigationTarget::from_module_to_decl(db, module))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
Some(RangeInfo::new(range, info))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in a new issue