Fix focus range for TypeParam

closes #4274
This commit is contained in:
Aleksey Kladov 2020-05-04 12:20:38 +02:00
parent 13bce1a164
commit 710e430dbb
2 changed files with 12 additions and 8 deletions

View file

@ -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,

View file

@ -754,14 +754,14 @@ mod tests {
#[test]
fn goto_for_type_param() {
check_goto(
"
r#"
//- /lib.rs
struct Foo<T> {
struct Foo<T: Clone> {
t: <|>T,
}
",
"T TYPE_PARAM FileId(1) 11..12",
"T",
"#,
"T TYPE_PARAM FileId(1) 11..19 11..12",
"T: Clone|T",
);
}