From 3aaf20bd6ec75a572b13d020520d4df563a2891c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 14:14:09 +0300 Subject: return ref ranges from gotodef --- crates/ra_ide_api/src/goto_definition.rs | 10 ++++++---- crates/ra_ide_api/src/lib.rs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 4706dc733..3fb29950b 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -4,19 +4,21 @@ use ra_syntax::{ algo::find_node_at_offset, }; -use crate::{FilePosition, NavigationTarget, db::RootDatabase}; +use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; pub(crate) fn goto_definition( db: &RootDatabase, position: FilePosition, -) -> Cancelable>> { +) -> Cancelable>>> { let file = db.source_file(position.file_id); let syntax = file.syntax(); if let Some(name_ref) = find_node_at_offset::(syntax, position.offset) { - return Ok(Some(reference_definition(db, position.file_id, name_ref)?)); + let navs = reference_definition(db, position.file_id, name_ref)?; + return Ok(Some(RangeInfo::new(name_ref.syntax().range(), navs))); } if let Some(name) = find_node_at_offset::(syntax, position.offset) { - return name_definition(db, position.file_id, name); + let navs = ctry!(name_definition(db, position.file_id, name)?); + return Ok(Some(RangeInfo::new(name.syntax().range(), navs))); } Ok(None) } diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 2873bab36..2b02dab2a 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -251,7 +251,7 @@ pub struct RangeInfo { } impl RangeInfo { - fn new(range: TextRange, info: T) -> RangeInfo { + pub fn new(range: TextRange, info: T) -> RangeInfo { RangeInfo { range, info } } } @@ -391,7 +391,7 @@ impl Analysis { pub fn goto_definition( &self, position: FilePosition, - ) -> Cancelable>> { + ) -> Cancelable>>> { self.db .catch_canceled(|db| goto_definition::goto_definition(db, position))? } -- cgit v1.2.3