aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-26 06:35:20 +0000
committerGitHub <[email protected]>2021-01-26 06:35:20 +0000
commit2f223d8c157c940b4e78918f65ac033f8291f7b1 (patch)
tree45f709cbd6e97f2c44e45927e1224b7a01364584
parentaa91a0268bae6deda964a9fdfcbdbd2d8ca5802f (diff)
parentd912444cacb0f9079680c505b3bb075fbeb208be (diff)
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, ![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 <[email protected]>
-rw-r--r--crates/ide/src/display/navigation_target.rs11
-rw-r--r--crates/ide/src/references.rs16
2 files changed, 23 insertions, 4 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index f178dd744..23d885218 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -435,13 +435,16 @@ impl TryToNav for hir::TypeParam {
435 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { 435 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
436 let src = self.source(db)?; 436 let src = self.source(db)?;
437 let full_range = match &src.value { 437 let full_range = match &src.value {
438 Either::Left(it) => it.syntax().text_range(), 438 Either::Left(it) => it
439 .name()
440 .map_or_else(|| it.syntax().text_range(), |name| name.syntax().text_range()),
439 Either::Right(it) => it.syntax().text_range(), 441 Either::Right(it) => it.syntax().text_range(),
440 }; 442 };
441 let focus_range = match &src.value { 443 let focus_range = match &src.value {
442 Either::Left(_) => None, 444 Either::Left(it) => it.name(),
443 Either::Right(it) => it.name().map(|it| it.syntax().text_range()), 445 Either::Right(it) => it.name(),
444 }; 446 }
447 .map(|it| it.syntax().text_range());
445 Some(NavigationTarget { 448 Some(NavigationTarget {
446 file_id: src.file_id.original_file(db), 449 file_id: src.file_id.original_file(db),
447 name: self.name(db).to_string().into(), 450 name: self.name(db).to_string().into(),
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 3a4f4d80b..40d9487eb 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -1098,4 +1098,20 @@ fn foo<const FOO$0: usize>() -> usize {
1098 "#]], 1098 "#]],
1099 ); 1099 );
1100 } 1100 }
1101
1102 #[test]
1103 fn test_find_self_ty_in_trait_def() {
1104 check(
1105 r#"
1106trait Foo {
1107 fn f() -> Self$0;
1108}
1109"#,
1110 expect![[r#"
1111 Self TypeParam FileId(0) 6..9 6..9 Other
1112
1113 FileId(0) 26..30 Other
1114 "#]],
1115 );
1116 }
1101} 1117}