From 710e430dbb9048c473d0e19e714cef9e279fac11 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 May 2020 12:20:38 +0200 Subject: Fix focus range for TypeParam closes #4274 --- crates/ra_ide/src/display/navigation_target.rs | 10 +++++++--- crates/ra_ide/src/goto_definition.rs | 10 +++++----- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 914a8b471..de35c6711 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -376,16 +376,20 @@ impl ToNav for hir::Local { impl ToNav for hir::TypeParam { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.source(db); - let range = match src.value { + let full_range = match &src.value { Either::Left(it) => it.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()), + }; NavigationTarget { file_id: src.file_id.original_file(db), name: self.name(db).to_string().into(), kind: TYPE_PARAM, - full_range: range, - focus_range: None, + full_range, + focus_range, container_name: None, description: None, docs: None, diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 1dfca819d..dbb4f38c7 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -754,14 +754,14 @@ mod tests { #[test] fn goto_for_type_param() { check_goto( - " + r#" //- /lib.rs - struct Foo { + struct Foo { t: <|>T, } - ", - "T TYPE_PARAM FileId(1) 11..12", - "T", + "#, + "T TYPE_PARAM FileId(1) 11..19 11..12", + "T: Clone|T", ); } -- cgit v1.2.3