7438: Shorten hir::TypeParam ranges for traits in NavigationTarget r=matklad a=Veykril

I noticed that selecting `Self` here highlights the entire trait,
![Code_a8DMOEUuWY](https://user-images.githubusercontent.com/3757771/105779993-d2592c00-5f6f-11eb-81d1-bd99f9369cf7.png)
this should cut it down to just the trait name and the `Self` which imo seems better.
![image](https://user-images.githubusercontent.com/3757771/105780410-ac805700-5f70-11eb-882b-10ed63b951f2.png)


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-01-26 06:35:20 +00:00 committed by GitHub
commit 2f223d8c15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View file

@ -435,13 +435,16 @@ impl TryToNav for hir::TypeParam {
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
let src = self.source(db)?;
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(),
};
let focus_range = match &src.value {
Either::Left(_) => None,
Either::Right(it) => it.name().map(|it| it.syntax().text_range()),
};
Either::Left(it) => it.name(),
Either::Right(it) => it.name(),
}
.map(|it| it.syntax().text_range());
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
name: self.name(db).to_string().into(),

View file

@ -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
"#]],
);
}
}