aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-11 11:14:09 +0000
committerAleksey Kladov <[email protected]>2019-01-11 13:06:08 +0000
commit3aaf20bd6ec75a572b13d020520d4df563a2891c (patch)
treeaa2a0b8e64896423b9324a44ef1f36141ff757bb /crates/ra_ide_api
parentf9ed8d4d23cd210f24ca303c72b436bfbe84741f (diff)
return ref ranges from gotodef
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs10
-rw-r--r--crates/ra_ide_api/src/lib.rs4
2 files changed, 8 insertions, 6 deletions
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::{
4 algo::find_node_at_offset, 4 algo::find_node_at_offset,
5}; 5};
6 6
7use crate::{FilePosition, NavigationTarget, db::RootDatabase}; 7use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo};
8 8
9pub(crate) fn goto_definition( 9pub(crate) fn goto_definition(
10 db: &RootDatabase, 10 db: &RootDatabase,
11 position: FilePosition, 11 position: FilePosition,
12) -> Cancelable<Option<Vec<NavigationTarget>>> { 12) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> {
13 let file = db.source_file(position.file_id); 13 let file = db.source_file(position.file_id);
14 let syntax = file.syntax(); 14 let syntax = file.syntax();
15 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { 15 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
16 return Ok(Some(reference_definition(db, position.file_id, name_ref)?)); 16 let navs = reference_definition(db, position.file_id, name_ref)?;
17 return Ok(Some(RangeInfo::new(name_ref.syntax().range(), navs)));
17 } 18 }
18 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { 19 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) {
19 return name_definition(db, position.file_id, name); 20 let navs = ctry!(name_definition(db, position.file_id, name)?);
21 return Ok(Some(RangeInfo::new(name.syntax().range(), navs)));
20 } 22 }
21 Ok(None) 23 Ok(None)
22} 24}
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<T> {
251} 251}
252 252
253impl<T> RangeInfo<T> { 253impl<T> RangeInfo<T> {
254 fn new(range: TextRange, info: T) -> RangeInfo<T> { 254 pub fn new(range: TextRange, info: T) -> RangeInfo<T> {
255 RangeInfo { range, info } 255 RangeInfo { range, info }
256 } 256 }
257} 257}
@@ -391,7 +391,7 @@ impl Analysis {
391 pub fn goto_definition( 391 pub fn goto_definition(
392 &self, 392 &self,
393 position: FilePosition, 393 position: FilePosition,
394 ) -> Cancelable<Option<Vec<NavigationTarget>>> { 394 ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> {
395 self.db 395 self.db
396 .catch_canceled(|db| goto_definition::goto_definition(db, position))? 396 .catch_canceled(|db| goto_definition::goto_definition(db, position))?
397 } 397 }