mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge #7438
7438: Shorten hir::TypeParam ranges for traits in NavigationTarget r=matklad a=Veykril I noticed that selecting `Self` here highlights the entire trait,  this should cut it down to just the trait name and the `Self` which imo seems better.  Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
2f223d8c15
@ -435,13 +435,16 @@ impl TryToNav for hir::TypeParam {
|
|||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
||||||
let src = self.source(db)?;
|
let src = self.source(db)?;
|
||||||
let full_range = match &src.value {
|
let full_range = match &src.value {
|
||||||
Either::Left(it) => it.syntax().text_range(),
|
Either::Left(it) => it
|
||||||
|
.name()
|
||||||
|
.map_or_else(|| it.syntax().text_range(), |name| name.syntax().text_range()),
|
||||||
Either::Right(it) => it.syntax().text_range(),
|
Either::Right(it) => it.syntax().text_range(),
|
||||||
};
|
};
|
||||||
let focus_range = match &src.value {
|
let focus_range = match &src.value {
|
||||||
Either::Left(_) => None,
|
Either::Left(it) => it.name(),
|
||||||
Either::Right(it) => it.name().map(|it| it.syntax().text_range()),
|
Either::Right(it) => it.name(),
|
||||||
};
|
}
|
||||||
|
.map(|it| it.syntax().text_range());
|
||||||
Some(NavigationTarget {
|
Some(NavigationTarget {
|
||||||
file_id: src.file_id.original_file(db),
|
file_id: src.file_id.original_file(db),
|
||||||
name: self.name(db).to_string().into(),
|
name: self.name(db).to_string().into(),
|
||||||
|
@ -1098,4 +1098,20 @@ fn foo<const FOO$0: usize>() -> usize {
|
|||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_self_ty_in_trait_def() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
trait Foo {
|
||||||
|
fn f() -> Self$0;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
Self TypeParam FileId(0) 6..9 6..9 Other
|
||||||
|
|
||||||
|
FileId(0) 26..30 Other
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user