From 077a02271c855841be39d4b6b45b7df14a6fc067 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jan 2019 21:56:20 +0300 Subject: fix go to parent module --- crates/ra_ide_api/src/navigation_target.rs | 19 +++++++++++++++++++ crates/ra_ide_api/src/parent_module.rs | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') 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 { Ok(res) } + pub(crate) fn from_module_to_decl( + db: &RootDatabase, + module: hir::Module, + ) -> Cancelable { + let name = module + .name(db)? + .map(|it| it.to_string().into()) + .unwrap_or_default(); + if let Some((file_id, source)) = module.declaration_source(db)? { + return Ok(NavigationTarget::from_syntax( + file_id, + name, + None, + source.syntax(), + )); + } + NavigationTarget::from_module(db, module) + } + // TODO once Def::Item is gone, this should be able to always return a NavigationTarget pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable> { 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( None => return Ok(Vec::new()), Some(it) => it, }; - let nav = NavigationTarget::from_module(db, module)?; + let nav = NavigationTarget::from_module_to_decl(db, module)?; Ok(vec![nav]) } @@ -31,7 +31,7 @@ mod tests { ", ); let nav = analysis.parent_module(pos).unwrap().pop().unwrap(); - nav.assert_match("foo SOURCE_FILE FileId(2) [0; 10)"); + nav.assert_match("foo MODULE FileId(1) [0; 8)"); } #[test] -- cgit v1.2.3