From d912444cacb0f9079680c505b3bb075fbeb208be Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 26 Jan 2021 00:44:27 +0100 Subject: Shorten hir::TypeParam full_range in NavigationTarget --- crates/ide/src/display/navigation_target.rs | 11 +++++++---- crates/ide/src/references.rs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'crates') 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 { fn try_to_nav(&self, db: &RootDatabase) -> Option { 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(), 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() -> 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 + "#]], + ); + } } -- cgit v1.2.3