aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-16 15:24:51 +0100
committerGitHub <[email protected]>2019-08-16 15:24:51 +0100
commitcd2434999768d3767814bc8b437bd5fb91263ef6 (patch)
treefd75a42035182e3fd4aade2c9df5d610ea2dbacd /crates/ra_ide_api
parentaf1052bb4c8e5dc3584670e2859324776c228b6a (diff)
parent35a04ec066b1a4ece2a6aa5e74dd8beae52e68f1 (diff)
Merge #1691
1691: Show inherent and trait impls of structs and enums r=viorina a=viorina Co-authored-by: Ekaterina Babshukova <[email protected]>
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/impls.rs37
1 files changed, 35 insertions, 2 deletions
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 @@
1use hir::{db::HirDatabase, source_binder}; 1use hir::{db::HirDatabase, source_binder, ApplicationTy, Ty, TypeCtor};
2use ra_db::SourceDatabase; 2use ra_db::SourceDatabase;
3use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; 3use 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
75fn 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)]
75mod tests { 89mod 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}