From ef8f38efc658270d55f438fc1a23c355ee0f4481 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Feb 2021 18:21:09 +0300 Subject: More precise navigation to parent --- crates/ide/src/display/navigation_target.rs | 12 ++++++++---- crates/ide/src/goto_definition.rs | 1 - crates/ide/src/parent_module.rs | 10 +++++----- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 23d885218..198243466 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -85,12 +85,16 @@ impl NavigationTarget { let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); if let Some(src) = module.declaration_source(db) { let node = src.as_ref().map(|it| it.syntax()); - let frange = node.original_file_range(db); + let full_range = node.original_file_range(db); + let focus_range = src + .value + .name() + .map(|name| src.with_value(name.syntax()).original_file_range(db).range); let mut res = NavigationTarget::from_syntax( - frange.file_id, + full_range.file_id, name, - None, - frange.range, + focus_range, + full_range.range, SymbolKind::Module, ); res.docs = module.attrs(db).docs(); diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index c91eb1283..e86ae2a18 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -131,7 +131,6 @@ pub(crate) fn reference_definition( #[cfg(test)] mod tests { use ide_db::base_db::FileRange; - use syntax::{TextRange, TextSize}; use crate::fixture; diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index e5515ef2c..7b08bc27b 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -81,8 +81,8 @@ mod tests { check( r#" //- /lib.rs - mod foo; -//^^^^^^^^ +mod foo; + //^^^ //- /foo.rs $0// empty @@ -96,8 +96,8 @@ $0// empty check( r#" //- /lib.rs - mod foo; -//^^^^^^^^ +mod foo; + //^^^ //- /foo.rs mod $0bar; @@ -115,7 +115,7 @@ mod $0bar; mod foo { mod bar { mod baz { $0 } - } //^^^^^^^^^^^^ + } //^^^ } "#, ); -- cgit v1.2.3