mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 22:13:39 +00:00
Don't bother with focus range for navigation to locals
This commit is contained in:
parent
46a299bcee
commit
7c25224f05
2 changed files with 49 additions and 7 deletions
|
@ -328,22 +328,23 @@ impl ToNav for hir::AssocItem {
|
||||||
impl ToNav for hir::Local {
|
impl ToNav for hir::Local {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||||
let src = self.source(db);
|
let src = self.source(db);
|
||||||
let (full_range, focus_range) = match src.value {
|
let node = match &src.value {
|
||||||
Either::Left(it) => {
|
Either::Left(bind_pat) => {
|
||||||
(it.syntax().text_range(), it.name().map(|it| it.syntax().text_range()))
|
bind_pat.name().map_or_else(|| bind_pat.syntax().clone(), |it| it.syntax().clone())
|
||||||
}
|
}
|
||||||
Either::Right(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())),
|
Either::Right(it) => it.syntax().clone(),
|
||||||
};
|
};
|
||||||
|
let full_range = original_range(db, src.with_value(&node));
|
||||||
let name = match self.name(db) {
|
let name = match self.name(db) {
|
||||||
Some(it) => it.to_string().into(),
|
Some(it) => it.to_string().into(),
|
||||||
None => "".into(),
|
None => "".into(),
|
||||||
};
|
};
|
||||||
NavigationTarget {
|
NavigationTarget {
|
||||||
file_id: src.file_id.original_file(db),
|
file_id: full_range.file_id,
|
||||||
name,
|
name,
|
||||||
kind: BIND_PAT,
|
kind: BIND_PAT,
|
||||||
full_range,
|
full_range: full_range.range,
|
||||||
focus_range,
|
focus_range: None,
|
||||||
container_name: None,
|
container_name: None,
|
||||||
description: None,
|
description: None,
|
||||||
docs: None,
|
docs: None,
|
||||||
|
|
|
@ -817,4 +817,45 @@ mod tests {
|
||||||
"T",
|
"T",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_within_macro() {
|
||||||
|
check_goto(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
macro_rules! id {
|
||||||
|
($($tt:tt)*) => ($($tt)*)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
let x = 1;
|
||||||
|
id!({
|
||||||
|
let y = <|>x;
|
||||||
|
let z = y;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"x BIND_PAT FileId(1) [69; 70)",
|
||||||
|
"x",
|
||||||
|
);
|
||||||
|
|
||||||
|
check_goto(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
macro_rules! id {
|
||||||
|
($($tt:tt)*) => ($($tt)*)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
let x = 1;
|
||||||
|
id!({
|
||||||
|
let y = x;
|
||||||
|
let z = <|>y;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"y BIND_PAT FileId(1) [98; 99)",
|
||||||
|
"y",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue