aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs19
-rw-r--r--crates/ra_ide_api/src/parent_module.rs4
2 files changed, 21 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index b0d0a3e8b..230d0f67a 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -89,6 +89,25 @@ impl NavigationTarget {
89 Ok(res) 89 Ok(res)
90 } 90 }
91 91
92 pub(crate) fn from_module_to_decl(
93 db: &RootDatabase,
94 module: hir::Module,
95 ) -> Cancelable<NavigationTarget> {
96 let name = module
97 .name(db)?
98 .map(|it| it.to_string().into())
99 .unwrap_or_default();
100 if let Some((file_id, source)) = module.declaration_source(db)? {
101 return Ok(NavigationTarget::from_syntax(
102 file_id,
103 name,
104 None,
105 source.syntax(),
106 ));
107 }
108 NavigationTarget::from_module(db, module)
109 }
110
92 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget 111 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget
93 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> { 112 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> {
94 let res = match def { 113 let res = match def {
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs
index d345839a3..675042a6c 100644
--- a/crates/ra_ide_api/src/parent_module.rs
+++ b/crates/ra_ide_api/src/parent_module.rs
@@ -12,7 +12,7 @@ pub(crate) fn parent_module(
12 None => return Ok(Vec::new()), 12 None => return Ok(Vec::new()),
13 Some(it) => it, 13 Some(it) => it,
14 }; 14 };
15 let nav = NavigationTarget::from_module(db, module)?; 15 let nav = NavigationTarget::from_module_to_decl(db, module)?;
16 Ok(vec![nav]) 16 Ok(vec![nav])
17} 17}
18 18
@@ -31,7 +31,7 @@ mod tests {
31 ", 31 ",
32 ); 32 );
33 let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); 33 let nav = analysis.parent_module(pos).unwrap().pop().unwrap();
34 nav.assert_match("foo SOURCE_FILE FileId(2) [0; 10)"); 34 nav.assert_match("foo MODULE FileId(1) [0; 8)");
35 } 35 }
36 36
37 #[test] 37 #[test]