aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorvsrs <[email protected]>2020-06-11 18:17:32 +0100
committervsrs <[email protected]>2020-06-18 08:15:43 +0100
commit4b07c1e77515ae9198aae6275700aacd43181b50 (patch)
tree30fe7b19cfd23d384ba5de42b96c9eda2d389614 /crates/ra_ide
parent7ec0064409f90334f6b0dd61e572a65702702985 (diff)
Add Type::walk method
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/hover.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 045713519..c2909e200 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -236,9 +236,26 @@ fn runnable_action(
236fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> { 236fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
237 match def { 237 match def {
238 Definition::Local(it) => { 238 Definition::Local(it) => {
239 let targets = it 239 let mut targets: Vec<ModuleDef> = Vec::new();
240 .ty(db) 240 let mut push_new_def = |item: ModuleDef| {
241 .flattened_type_items(db) 241 if !targets.contains(&item) {
242 targets.push(item);
243 }
244 };
245
246 it.ty(db).walk(db, |t| {
247 if let Some(adt) = t.as_adt() {
248 push_new_def(adt.into());
249 } else if let Some(trait_) = t.as_dyn_trait() {
250 push_new_def(trait_.into());
251 } else if let Some(trait_) = t.as_impl_trait(db) {
252 push_new_def(trait_.into());
253 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
254 push_new_def(trait_.into());
255 }
256 });
257
258 let targets = targets
242 .into_iter() 259 .into_iter()
243 .filter_map(|it| { 260 .filter_map(|it| {
244 Some(HoverGotoTypeData { 261 Some(HoverGotoTypeData {
@@ -246,7 +263,7 @@ fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
246 nav: it.try_to_nav(db)?, 263 nav: it.try_to_nav(db)?,
247 }) 264 })
248 }) 265 })
249 .collect_vec(); 266 .collect();
250 267
251 Some(HoverAction::GoToType(targets)) 268 Some(HoverAction::GoToType(targets))
252 } 269 }