mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Show implementations when hovering over SelfType
This commit is contained in:
parent
dcb5387b42
commit
cd6426afe5
1 changed files with 29 additions and 8 deletions
|
@ -182,16 +182,18 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
match def {
|
let adt = match def {
|
||||||
Definition::ModuleDef(it) => match it {
|
Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
|
||||||
ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.try_to_nav(db)?)),
|
Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
|
||||||
ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.try_to_nav(db)?)),
|
Definition::SelfType(it) => it.target_ty(db).as_adt(),
|
||||||
ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.try_to_nav(db)?)),
|
|
||||||
ModuleDef::Trait(it) => Some(to_action(it.try_to_nav(db)?)),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
_ => None,
|
_ => None,
|
||||||
|
}?;
|
||||||
|
match adt {
|
||||||
|
Adt::Struct(it) => it.try_to_nav(db),
|
||||||
|
Adt::Union(it) => it.try_to_nav(db),
|
||||||
|
Adt::Enum(it) => it.try_to_nav(db),
|
||||||
}
|
}
|
||||||
|
.map(to_action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runnable_action(
|
fn runnable_action(
|
||||||
|
@ -2174,6 +2176,25 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hover_self_has_impl_action() {
|
||||||
|
check_actions(
|
||||||
|
r#"struct foo where Self<|>:;"#,
|
||||||
|
expect![[r#"
|
||||||
|
[
|
||||||
|
Implementation(
|
||||||
|
FilePosition {
|
||||||
|
file_id: FileId(
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
offset: 7,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_test_has_action() {
|
fn test_hover_test_has_action() {
|
||||||
check_actions(
|
check_actions(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue