aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs31
1 files changed, 10 insertions, 21 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index cff11eeab..b2a53e9aa 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -24,34 +24,22 @@ impl NavigationTarget {
24 24
25 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget 25 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget
26 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> { 26 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> {
27 Ok(match def { 27 let res = match def {
28 Def::Struct(s) => { 28 Def::Struct(s) => {
29 let (file_id, node) = s.source(db)?; 29 let (file_id, node) = s.source(db)?;
30 Some(NavigationTarget::from_named( 30 NavigationTarget::from_named(file_id.original_file(db), &*node)
31 file_id.original_file(db),
32 &*node,
33 ))
34 } 31 }
35 Def::Enum(e) => { 32 Def::Enum(e) => {
36 let (file_id, node) = e.source(db)?; 33 let (file_id, node) = e.source(db)?;
37 Some(NavigationTarget::from_named( 34 NavigationTarget::from_named(file_id.original_file(db), &*node)
38 file_id.original_file(db),
39 &*node,
40 ))
41 } 35 }
42 Def::EnumVariant(ev) => { 36 Def::EnumVariant(ev) => {
43 let (file_id, node) = ev.source(db)?; 37 let (file_id, node) = ev.source(db)?;
44 Some(NavigationTarget::from_named( 38 NavigationTarget::from_named(file_id.original_file(db), &*node)
45 file_id.original_file(db),
46 &*node,
47 ))
48 } 39 }
49 Def::Function(f) => { 40 Def::Function(f) => {
50 let (file_id, node) = f.source(db)?; 41 let (file_id, node) = f.source(db)?;
51 Some(NavigationTarget::from_named( 42 NavigationTarget::from_named(file_id.original_file(db), &*node)
52 file_id.original_file(db),
53 &*node,
54 ))
55 } 43 }
56 Def::Module(m) => { 44 Def::Module(m) => {
57 let (file_id, source) = m.definition_source(db)?; 45 let (file_id, source) = m.definition_source(db)?;
@@ -61,15 +49,16 @@ impl NavigationTarget {
61 .unwrap_or_else(|| SmolStr::new("")); 49 .unwrap_or_else(|| SmolStr::new(""));
62 match source { 50 match source {
63 ModuleSource::SourceFile(node) => { 51 ModuleSource::SourceFile(node) => {
64 Some(NavigationTarget::from_syntax(file_id, name, node.syntax())) 52 NavigationTarget::from_syntax(file_id, name, node.syntax())
65 } 53 }
66 ModuleSource::Module(node) => { 54 ModuleSource::Module(node) => {
67 Some(NavigationTarget::from_syntax(file_id, name, node.syntax())) 55 NavigationTarget::from_syntax(file_id, name, node.syntax())
68 } 56 }
69 } 57 }
70 } 58 }
71 Def::Item => None, 59 Def::Item => return Ok(None),
72 }) 60 };
61 Ok(Some(res))
73 } 62 }
74 63
75 fn from_named(file_id: FileId, node: &impl ast::NameOwner) -> NavigationTarget { 64 fn from_named(file_id: FileId, node: &impl ast::NameOwner) -> NavigationTarget {