4292: Fix focus range for TypeParam r=matklad a=matklad

closes #4274



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-05-04 10:26:18 +00:00 committed by GitHub
commit 0ef4665d42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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",
);
}