From b683cbd93db65f5421ef9b7617a2abfe93928af0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Dec 2019 18:42:45 +0100 Subject: Report correct original range in goto_definition --- crates/ra_ide/src/goto_definition.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index b93d6a931..cfe62037f 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -19,25 +19,23 @@ pub(crate) fn goto_definition( position: FilePosition, ) -> Option>> { let file = db.parse_or_expand(position.file_id.into())?; - let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; - let token = descend_into_macros(db, position.file_id, token); + let original_token = + file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; + let token = descend_into_macros(db, position.file_id, original_token.clone()); - let res = match_ast! { + let nav_targets = match_ast! { match (token.value.parent()) { ast::NameRef(name_ref) => { - let navs = reference_definition(db, token.with_value(&name_ref)).to_vec(); - RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()) + reference_definition(db, token.with_value(&name_ref)).to_vec() }, ast::Name(name) => { - let navs = name_definition(db, token.with_value(&name))?; - RangeInfo::new(name.syntax().text_range(), navs) - + name_definition(db, token.with_value(&name))? }, _ => return None, } }; - Some(res) + Some(RangeInfo::new(original_token.text_range(), nav_targets)) } #[derive(Debug)] -- cgit v1.2.3