diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_dot.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index cb86ba9a3..473edc50e 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -1,29 +1,27 @@ | |||
1 | use hir::{Ty, Def}; | 1 | use hir::{Ty, Def}; |
2 | 2 | ||
3 | use crate::Cancelable; | ||
4 | use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem, CompletionItemKind}; | 3 | use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem, CompletionItemKind}; |
5 | 4 | ||
6 | /// Complete dot accesses, i.e. fields or methods (currently only fields). | 5 | /// Complete dot accesses, i.e. fields or methods (currently only fields). |
7 | pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { | 6 | pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { |
8 | let (function, receiver) = match (&ctx.function, ctx.dot_receiver) { | 7 | let (function, receiver) = match (&ctx.function, ctx.dot_receiver) { |
9 | (Some(function), Some(receiver)) => (function, receiver), | 8 | (Some(function), Some(receiver)) => (function, receiver), |
10 | _ => return Ok(()), | 9 | _ => return, |
11 | }; | 10 | }; |
12 | let infer_result = function.infer(ctx.db)?; | 11 | let infer_result = function.infer(ctx.db); |
13 | let syntax_mapping = function.body_syntax_mapping(ctx.db); | 12 | let syntax_mapping = function.body_syntax_mapping(ctx.db); |
14 | let expr = match syntax_mapping.node_expr(receiver) { | 13 | let expr = match syntax_mapping.node_expr(receiver) { |
15 | Some(expr) => expr, | 14 | Some(expr) => expr, |
16 | None => return Ok(()), | 15 | None => return, |
17 | }; | 16 | }; |
18 | let receiver_ty = infer_result[expr].clone(); | 17 | let receiver_ty = infer_result[expr].clone(); |
19 | if !ctx.is_call { | 18 | if !ctx.is_call { |
20 | complete_fields(acc, ctx, receiver_ty.clone())?; | 19 | complete_fields(acc, ctx, receiver_ty.clone()); |
21 | } | 20 | } |
22 | complete_methods(acc, ctx, receiver_ty)?; | 21 | complete_methods(acc, ctx, receiver_ty); |
23 | Ok(()) | ||
24 | } | 22 | } |
25 | 23 | ||
26 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) -> Cancelable<()> { | 24 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
27 | for receiver in receiver.autoderef(ctx.db) { | 25 | for receiver in receiver.autoderef(ctx.db) { |
28 | match receiver { | 26 | match receiver { |
29 | Ty::Adt { def_id, .. } => { | 27 | Ty::Adt { def_id, .. } => { |
@@ -35,7 +33,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
35 | field.name().to_string(), | 33 | field.name().to_string(), |
36 | ) | 34 | ) |
37 | .kind(CompletionItemKind::Field) | 35 | .kind(CompletionItemKind::Field) |
38 | .set_detail(field.ty(ctx.db)?.map(|ty| ty.to_string())) | 36 | .set_detail(field.ty(ctx.db).map(|ty| ty.to_string())) |
39 | .add_to(acc); | 37 | .add_to(acc); |
40 | } | 38 | } |
41 | } | 39 | } |
@@ -53,14 +51,9 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
53 | _ => {} | 51 | _ => {} |
54 | }; | 52 | }; |
55 | } | 53 | } |
56 | Ok(()) | ||
57 | } | 54 | } |
58 | 55 | ||
59 | fn complete_methods( | 56 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
60 | acc: &mut Completions, | ||
61 | ctx: &CompletionContext, | ||
62 | receiver: Ty, | ||
63 | ) -> Cancelable<()> { | ||
64 | receiver.iterate_methods(ctx.db, |func| { | 57 | receiver.iterate_methods(ctx.db, |func| { |
65 | let sig = func.signature(ctx.db); | 58 | let sig = func.signature(ctx.db); |
66 | if sig.has_self_param() { | 59 | if sig.has_self_param() { |
@@ -69,9 +62,8 @@ fn complete_methods( | |||
69 | .kind(CompletionItemKind::Method) | 62 | .kind(CompletionItemKind::Method) |
70 | .add_to(acc); | 63 | .add_to(acc); |
71 | } | 64 | } |
72 | Ok(None::<()>) | 65 | None::<()> |
73 | })?; | 66 | }); |
74 | Ok(()) | ||
75 | } | 67 | } |
76 | 68 | ||
77 | #[cfg(test)] | 69 | #[cfg(test)] |