diff options
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide_api/src/impls.rs | 37 |
2 files changed, 44 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 88d012a74..3f4c43aee 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -68,6 +68,15 @@ impl CrateImplBlocks { | |||
68 | ) | 68 | ) |
69 | } | 69 | } |
70 | 70 | ||
71 | pub fn all_impls<'a>(&'a self) -> impl Iterator<Item = ImplBlock> + 'a { | ||
72 | self.impls.values().chain(self.impls_by_trait.values()).flat_map(|i| i.iter()).map( | ||
73 | move |(module_id, impl_id)| { | ||
74 | let module = Module { krate: self.krate, module_id: *module_id }; | ||
75 | ImplBlock::from_id(module, *impl_id) | ||
76 | }, | ||
77 | ) | ||
78 | } | ||
79 | |||
71 | fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) { | 80 | fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) { |
72 | let module_impl_blocks = db.impls_in_module(module); | 81 | let module_impl_blocks = db.impls_in_module(module); |
73 | 82 | ||
diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index f5b6ffd61..638f4cbde 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::{db::HirDatabase, source_binder}; | 1 | use hir::{db::HirDatabase, source_binder, ApplicationTy, Ty, TypeCtor}; |
2 | use ra_db::SourceDatabase; | 2 | use ra_db::SourceDatabase; |
3 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; | 3 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; |
4 | 4 | ||
@@ -47,7 +47,8 @@ fn impls_for_def( | |||
47 | 47 | ||
48 | Some( | 48 | Some( |
49 | impls | 49 | impls |
50 | .lookup_impl_blocks(&ty) | 50 | .all_impls() |
51 | .filter(|impl_block| is_equal_for_find_impls(&ty, &impl_block.target_ty(db))) | ||
51 | .map(|imp| NavigationTarget::from_impl_block(db, imp)) | 52 | .map(|imp| NavigationTarget::from_impl_block(db, imp)) |
52 | .collect(), | 53 | .collect(), |
53 | ) | 54 | ) |
@@ -71,6 +72,19 @@ fn impls_for_trait( | |||
71 | ) | 72 | ) |
72 | } | 73 | } |
73 | 74 | ||
75 | fn is_equal_for_find_impls(original_ty: &Ty, impl_ty: &Ty) -> bool { | ||
76 | match (original_ty, impl_ty) { | ||
77 | (Ty::Apply(a_original_ty), Ty::Apply(ApplicationTy { ctor, parameters })) => match ctor { | ||
78 | TypeCtor::Ref(..) => match parameters.as_single() { | ||
79 | Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, | ||
80 | _ => false, | ||
81 | }, | ||
82 | _ => a_original_ty.ctor == *ctor, | ||
83 | }, | ||
84 | _ => false, | ||
85 | } | ||
86 | } | ||
87 | |||
74 | #[cfg(test)] | 88 | #[cfg(test)] |
75 | mod tests { | 89 | mod tests { |
76 | use crate::mock_analysis::analysis_and_position; | 90 | use crate::mock_analysis::analysis_and_position; |
@@ -173,4 +187,23 @@ mod tests { | |||
173 | &["impl IMPL_BLOCK FileId(2) [0; 31)", "impl IMPL_BLOCK FileId(3) [0; 31)"], | 187 | &["impl IMPL_BLOCK FileId(2) [0; 31)", "impl IMPL_BLOCK FileId(3) [0; 31)"], |
174 | ); | 188 | ); |
175 | } | 189 | } |
190 | |||
191 | #[test] | ||
192 | fn goto_implementation_all_impls() { | ||
193 | check_goto( | ||
194 | " | ||
195 | //- /lib.rs | ||
196 | trait T {} | ||
197 | struct Foo<|>; | ||
198 | impl Foo {} | ||
199 | impl T for Foo {} | ||
200 | impl T for &Foo {} | ||
201 | ", | ||
202 | &[ | ||
203 | "impl IMPL_BLOCK FileId(1) [23; 34)", | ||
204 | "impl IMPL_BLOCK FileId(1) [35; 52)", | ||
205 | "impl IMPL_BLOCK FileId(1) [53; 71)", | ||
206 | ], | ||
207 | ); | ||
208 | } | ||
176 | } | 209 | } |