diff options
author | Florian Diebold <[email protected]> | 2019-10-31 20:21:48 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-11-01 18:57:08 +0000 |
commit | 79cb0a0dab5fd8e3e84cf4a3b927ec29d2b6e65c (patch) | |
tree | 88f2ebdf338d230f6019d56acb96bea0878f7248 /crates/ra_ide_api/src/completion | |
parent | 5da941897d4ed092a219729d7980bd103907850a (diff) |
Complete trait assoc items
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 22 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 38 |
2 files changed, 48 insertions, 12 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 7135f481d..fe32e7366 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -58,15 +58,21 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
58 | 58 | ||
59 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 59 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
60 | let mut seen_methods = FxHashSet::default(); | 60 | let mut seen_methods = FxHashSet::default(); |
61 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, item| { | 61 | ctx.analyzer.iterate_method_candidates( |
62 | if let hir::AssocItem::Function(func) = item { | 62 | ctx.db, |
63 | let data = func.data(ctx.db); | 63 | receiver, |
64 | if data.has_self_param() && seen_methods.insert(data.name().clone()) { | 64 | None, |
65 | acc.add_function(ctx, func); | 65 | hir::LookupMode::MethodCall, |
66 | |_ty, item| { | ||
67 | if let hir::AssocItem::Function(func) = item { | ||
68 | let data = func.data(ctx.db); | ||
69 | if data.has_self_param() && seen_methods.insert(data.name().clone()) { | ||
70 | acc.add_function(ctx, func); | ||
71 | } | ||
66 | } | 72 | } |
67 | } | 73 | None::<()> |
68 | None::<()> | 74 | }, |
69 | }); | 75 | ); |
70 | } | 76 | } |
71 | 77 | ||
72 | #[cfg(test)] | 78 | #[cfg(test)] |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index b471787eb..940858342 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -50,9 +50,12 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
50 | hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), | 50 | hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), |
51 | _ => unreachable!(), | 51 | _ => unreachable!(), |
52 | }; | 52 | }; |
53 | let krate = ctx.module.map(|m| m.krate()); | 53 | ctx.analyzer.iterate_method_candidates( |
54 | if let Some(krate) = krate { | 54 | ctx.db, |
55 | ty.iterate_impl_items(ctx.db, krate, |item| { | 55 | ty.clone(), |
56 | None, | ||
57 | hir::LookupMode::Path, | ||
58 | |_ty, item| { | ||
56 | match item { | 59 | match item { |
57 | hir::AssocItem::Function(func) => { | 60 | hir::AssocItem::Function(func) => { |
58 | let data = func.data(ctx.db); | 61 | let data = func.data(ctx.db); |
@@ -64,6 +67,18 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
64 | hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), | 67 | hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), |
65 | } | 68 | } |
66 | None::<()> | 69 | None::<()> |
70 | }, | ||
71 | ); | ||
72 | // Iterate assoc types separately | ||
73 | // FIXME: complete T::AssocType | ||
74 | let krate = ctx.module.map(|m| m.krate()); | ||
75 | if let Some(krate) = krate { | ||
76 | ty.iterate_impl_items(ctx.db, krate, |item| { | ||
77 | match item { | ||
78 | hir::AssocItem::Function(_) | hir::AssocItem::Const(_) => {} | ||
79 | hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), | ||
80 | } | ||
81 | None::<()> | ||
67 | }); | 82 | }); |
68 | } | 83 | } |
69 | } | 84 | } |
@@ -593,7 +608,22 @@ mod tests { | |||
593 | fn foo() { let _ = S::<|> } | 608 | fn foo() { let _ = S::<|> } |
594 | " | 609 | " |
595 | ), | 610 | ), |
596 | @"[]" | 611 | @r###" |
612 | [ | ||
613 | CompletionItem { | ||
614 | label: "m()", | ||
615 | source_range: [99; 99), | ||
616 | delete: [99; 99), | ||
617 | insert: "m()$0", | ||
618 | kind: Function, | ||
619 | lookup: "m", | ||
620 | detail: "fn m()", | ||
621 | documentation: Documentation( | ||
622 | "A trait method", | ||
623 | ), | ||
624 | }, | ||
625 | ] | ||
626 | "### | ||
597 | ); | 627 | ); |
598 | } | 628 | } |
599 | 629 | ||