mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
More precise navigation to parent
This commit is contained in:
parent
2ac20b05f1
commit
ef8f38efc6
3 changed files with 13 additions and 10 deletions
|
@ -85,12 +85,16 @@ impl NavigationTarget {
|
||||||
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
||||||
if let Some(src) = module.declaration_source(db) {
|
if let Some(src) = module.declaration_source(db) {
|
||||||
let node = src.as_ref().map(|it| it.syntax());
|
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(
|
let mut res = NavigationTarget::from_syntax(
|
||||||
frange.file_id,
|
full_range.file_id,
|
||||||
name,
|
name,
|
||||||
None,
|
focus_range,
|
||||||
frange.range,
|
full_range.range,
|
||||||
SymbolKind::Module,
|
SymbolKind::Module,
|
||||||
);
|
);
|
||||||
res.docs = module.attrs(db).docs();
|
res.docs = module.attrs(db).docs();
|
||||||
|
|
|
@ -131,7 +131,6 @@ pub(crate) fn reference_definition(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ide_db::base_db::FileRange;
|
use ide_db::base_db::FileRange;
|
||||||
use syntax::{TextRange, TextSize};
|
|
||||||
|
|
||||||
use crate::fixture;
|
use crate::fixture;
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ mod tests {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
//^^^^^^^^
|
//^^^
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
$0// empty
|
$0// empty
|
||||||
|
@ -96,8 +96,8 @@ $0// empty
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
//^^^^^^^^
|
//^^^
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
mod $0bar;
|
mod $0bar;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ mod $0bar;
|
||||||
mod foo {
|
mod foo {
|
||||||
mod bar {
|
mod bar {
|
||||||
mod baz { $0 }
|
mod baz { $0 }
|
||||||
} //^^^^^^^^^^^^
|
} //^^^
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue